Geopatra¶
[1]:
import random
import geopatra
import geopandas
[2]:
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))
cities['value'] = [int(random.randint(10, 1000)) for i in range(len(cities))]
[3]:
world.head()
[3]:
pop_est | continent | name | iso_a3 | gdp_md_est | geometry | |
---|---|---|---|---|---|---|
0 | 920938 | Oceania | Fiji | FJI | 8374.0 | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... |
1 | 53950935 | Africa | Tanzania | TZA | 150600.0 | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... |
2 | 603253 | Africa | W. Sahara | ESH | 906.5 | POLYGON ((-8.66559 27.65643, -8.66512 27.58948... |
3 | 35623680 | North America | Canada | CAN | 1674000.0 | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... |
4 | 326625791 | North America | United States of America | USA | 18560000.0 | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... |
[4]:
cities.head()
[4]:
name | geometry | value | |
---|---|---|---|
0 | Vatican City | POINT (12.45339 41.90328) | 934 |
1 | San Marino | POINT (12.44177 43.93610) | 202 |
2 | Vaduz | POINT (9.51667 47.13372) | 33 |
3 | Luxembourg | POINT (6.13000 49.61166) | 466 |
4 | Palikir | POINT (158.14997 6.91664) | 649 |
Interactive maps with folium¶
Map geodataframes with Folium
Supported Maps¶
- Geojson plots (Plot the geometries in geodataframes)
- Choropleth maps (Colors and Jazz)
- Markercluster (Count, Sum, Average)
- Heatmaps (Oooh 🔥)
Geojson maps¶
[5]:
cities.folium.plot()
[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
[6]:
# Directly interact with the function
m = geopatra.folium.geojson(cities, zoom=5)
Circle Maps¶
[7]:
cities.folium.circle(
tooltip=["name"],
radius=10,
fill=True,
fill_color='red',
zoom=100
)
[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
[8]:
# Directly interact with the function
m = geopatra.folium.circle(cities, zoom=5)
Choropleth maps¶
[9]:
world.folium.choropleth(color_by= 'pop_est',
tooltip=['name'],
color= 'green',
zoom= 1,
style = {'color': 'black',
'weight': 1,
'dashArray': '10, 5',
'fillOpacity': 0.5,
})
[9]:
Make this Notebook Trusted to load map: File -> Trust Notebook
[10]:
# Directly interact with the function
m = geopatra.folium.choropleth(world, color_by= 'pop_est',)
Markercluster maps¶
[11]:
cities.folium.markercluster(zoom=1)
[11]:
Make this Notebook Trusted to load map: File -> Trust Notebook
[12]:
# Directly interact with the function
m = geopatra.folium.markercluster(cities, zoom=5)
Weighted Markercluster maps¶
TODO: add color change and tooltip
[13]:
cities.folium.markercluster(zoom=1, metric='sum', weight='value')
[13]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Heat maps¶
[14]:
cities.folium.heatmap(style={'min_opacity': 0.3}, zoom=5)
[14]:
Make this Notebook Trusted to load map: File -> Trust Notebook
[15]:
# Directly interact with the function
m = geopatra.folium.heatmap(cities, zoom=5)
Interactive maps with kepler.gl¶
Build an interface for geodataframes to work natively with Kepler.gl https://docs.kepler.gl/docs/keplergl-jupyter
Supported Maps¶
- Geojson plots & Choropleth
Geojson maps¶
[16]:
import warnings
from IPython.display import IFrame
warnings.filterwarnings('ignore')
[17]:
kmap1 = cities.kepler.plot()
kmap1.save_to_html(file_name='./_static/_maps/kepler_map1.html')
User Guide: https://github.com/keplergl/kepler.gl/blob/master/docs/keplergl-jupyter/user-guide.md
Map saved to ./_static/_maps/kepler_map1.html!
[18]:
IFrame('./_static/_maps/kepler_map1.html', width=900, height=500)
[18]:
Simple Polygons¶
[19]:
kmap2 = world.kepler.plot(name="world",
tooltip=['continent'],
color=[255,0,0],
opacity=0.2,
stroke_color=[0,0,0],
stroke_thickness=1
)
kmap2.save_to_html(file_name='./_static/_maps/kepler_map2.html')
User Guide: https://github.com/keplergl/kepler.gl/blob/master/docs/keplergl-jupyter/user-guide.md
Map saved to ./_static/_maps/kepler_map2.html!
[20]:
IFrame('./_static/_maps/kepler_map2.html', width=900, height=500)
[20]:
Choropleth maps¶
[21]:
kmap_3 = world.kepler.plot(name = 'world',
tooltip=['continent', 'pop_est'],
stroke_color=[0,0,0],
stroke_thickness=1,
color_field = 'pop_est',
color_scheme = 'Blues',
color_scheme_steps = 5
)
kmap_3.save_to_html(file_name='./_static/_maps/kepler_map3.html')
User Guide: https://github.com/keplergl/kepler.gl/blob/master/docs/keplergl-jupyter/user-guide.md
Map saved to ./_static/_maps/kepler_map3.html!
[22]:
IFrame('./_static/_maps/kepler_map3.html', width=900, height=500)
[22]: