Skip to content

Commit

Permalink
grass.jupyter: Add direct integration with folium (OSGeo#2208)
Browse files Browse the repository at this point in the history
Restructures InteractiveMap so that folium-like objects can be created and used directly with folium.

New Raster and Vector classes allow direct interaction with folium and have add_to method for adding into folium.  InteractiveMap is restructured to use new Raster and Vector classes. A new ReprojectionRenderer class takes most of the complex reprojection, rendering, and format conversion functionality from InteractiveMap and provides that to functions to  folium-like objects and InteractiveMap.

Adds tiles parameter to InteractiveMap. The main notebook now includes an example with direct use of folium. 

Adds pytest tests for ReprojectionRenderer. Removes interact_display.py from pylint ignore.
  • Loading branch information
chaedri authored Apr 13, 2022
1 parent 389ce3a commit 9045c62
Show file tree
Hide file tree
Showing 9 changed files with 451 additions and 165 deletions.
41 changes: 41 additions & 0 deletions doc/notebooks/grass_jupyter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,47 @@
"fig.save(filename=\"test_map.html\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## GRASS-folium Integration\n",
"\n",
"We can also pass GRASS rasters and vectors directly to folium with the Raster and Vector classes. This provides much more flexibility when creating maps since we can access all of folium's capabilities."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import folium \n",
"\n",
"# Create figure\n",
"fig = folium.Figure(width=600, height=400)\n",
"\n",
"# Create a map to add to the figure later\n",
"m = folium.Map(tiles=\"Stamen Terrain\", location=[35.761168,-78.668271], zoom_start=13)\n",
"\n",
"# Create and add elevation layer to map\n",
"gj.Raster(\"elevation\", opacity=0.5).add_to(m)\n",
"\n",
"# Do some cool folium stuff!\n",
"# Like make a tooltip\n",
"tooltip = \"Click me!\"\n",
"# and add a marker\n",
"folium.Marker(\n",
" [35.781608,-78.675800], popup=\"<i>Point of Interest</i>\", tooltip=tooltip\n",
").add_to(m)\n",
"\n",
"# Add the map to the figure\n",
"fig.add_child(m)\n",
"\n",
"# Display figure\n",
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion python/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ignore-paths=grass/temporal/.*,
grass/utils/.*,
grass/exceptions/.*,
grass/app/.*,
grass/jupyter/interact_display.py,


# Files or directories matching the regex patterns are skipped. The regex
# matches against base names, not paths.
Expand Down
2 changes: 2 additions & 0 deletions python/grass/jupyter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ MODULES = \
interact_display \
region \
render3d \
reprojection_renderer \
utils


PYFILES := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)

Expand Down
1 change: 1 addition & 0 deletions python/grass/jupyter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
from .render3d import *
from .setup import *
from .utils import *
from .reprojection_renderer import *
Loading

0 comments on commit 9045c62

Please sign in to comment.