Making Interactive Maps¶
In [1]:
# Work with vector data
import geopandas as gpd
# Save maps and plots to files
import holoviews as hv
# Create interactive maps and plots
import hvplot.pandas
# Search for locations by name - this might take a moment
from osmnx import features as osm
In [2]:
# Search for United Tribes Technical College
haskell_gdf = osm.features_from_address(
'Haskell Indian Nations University, Lawrence, KS, United States',
{'amenity': ['university']})
haskell_gdf
Out[2]:
ways | addr:city | addr:housenumber | addr:postcode | addr:street | amenity | boundary | ele | gnis:feature_id | heritage | ... | nrhp:criteria | nrhp:inscription_date | nrhp:nhl | protection_title | ref:nrhp | type | wikidata | wikipedia | nodes | geometry | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
element_type | osmid | |||||||||||||||||||||
relation | 2330930 | [172603550, 174576051, 174576058, 171002778, 1... | Lawrence | 2300 | 66046 | Barker Avenue | university | protected_area | 268 | 479134 | 2 | ... | (A) | July 4, 1961 | yes | protected_site | 66000342 | multipolygon | Q845332 | en:Haskell Indian Nations University | [[[391518501, 1834666320, 1834666332, 12070968... | POLYGON ((-95.23831 38.93552, -95.23817 38.935... |
1 rows × 22 columns
In [3]:
haskell_gdf.plot()
Out[3]:
<Axes: >
In [4]:
# Plot haskell boundary
haskell_map = haskell_gdf.reset_index().hvplot(
# Givethe map a descriptive title
title="Haskell Indian Nations Universty, Lawrence, KS",
# Add a basemap
geo=True, tiles='EsriImagery',
# Change the colors
fill_color='white', fill_alpha=0.2,
line_color='skyblue', line_width=5,
# Change the image size
frame_width=400, frame_height=400)
# Save the map as a file to put on the web
hv.save(haskell_map, 'haskell.html')
# Display the map
haskell_map
/opt/conda/lib/python3.11/site-packages/dask/dataframe/__init__.py:31: FutureWarning: Dask dataframe query planning is disabled because dask-expr is not installed. You can install it with `pip install dask[dataframe]` or `conda install dask`. This will raise in a future version. warnings.warn(msg, FutureWarning) WARNING:bokeh.core.validation.check:W-1005 (FIXED_SIZING_MODE): 'fixed' sizing mode requires width and height to be set: figure(id='p1043', ...)
Out[4]:
In [5]:
# Search Vinoba Bhave University, Hazaribagh,Jharkhand, India.
VBU_gdf = osm.features_from_address(
'Vinoba Bhave University, Hazaribagh, Jharkhand, India',
{'amenity': ['university']},dist=500)
VBU_gdf
Out[5]:
nodes | addr:city | amenity | name | name:etymology:wikidata | wikidata | wikipedia | geometry | ||
---|---|---|---|---|---|---|---|---|---|
element_type | osmid | ||||||||
way | 524846511 | [5106871912, 5106871913, 5106871914, 510687191... | Hazaribagh | university | Vinoba Bhave University | Q13021 | Q7932713 | en:Vinoba Bhave University | POLYGON ((85.37735 24.02239, 85.37665 24.02274... |
In [6]:
VBU_gdf.plot()
Out[6]:
<Axes: >
In [ ]:
VBU_gdf.explore()
In [ ]:
# Plot VBU boundary
VBU_map = VBU_gdf.reset_index().hvplot(
# Givethe map a descriptive title
title="Vinoba Bhave Universty, Hazaribagh, India",
# Add a basemap
geo=True, tiles='EsriImagery',
# Change the colors
fill_color='white', fill_alpha=0.2,
line_color='skyblue', line_width=5,
# Change the image size
frame_width=400, frame_height=400)
# Save the map as a file to put on the web
hv.save(VBU_map, 'VBU.html')
# Display the map
VBU_map
WARNING:bokeh.core.validation.check:W-1005 (FIXED_SIZING_MODE): 'fixed' sizing mode requires width and height to be set: figure(id='p1218', ...)
Out[ ]:
In [ ]:
# Search Vinoba Bhave University, Hazaribagh,Jharkhand, India.
JU_gdf = osm.features_from_address(
'Jadavpur University, Kolkata, West Bengal, India',
{'amenity': ['university']},dist=500)
JU_gdf
Out[ ]:
nodes | amenity | name | wikidata | wikipedia | geometry | wikimedia_commons | ||
---|---|---|---|---|---|---|---|---|
element_type | osmid | |||||||
way | 192929961 | [2034631179, 2034631184, 2034631172, 203463116... | university | Jadavpur University | Q2579702 | en:Jadavpur University | POLYGON ((88.41345 22.56002, 88.41299 22.55919... | NaN |
192929964 | [2034631185, 2034631171, 2034619112, 203463117... | university | West Bengal National University of Juridical S... | Q3348916 | en:West Bengal National University of Juridica... | POLYGON ((88.40999 22.56013, 88.41146 22.56108... | Category:West Bengal National University of Ju... |
In [ ]:
JU_gdf1=JU_gdf[JU_gdf['wikidata']=='Q2579702']
JU_gdf1
Out[ ]:
nodes | amenity | name | wikidata | wikipedia | geometry | wikimedia_commons | ||
---|---|---|---|---|---|---|---|---|
element_type | osmid | |||||||
way | 192929961 | [2034631179, 2034631184, 2034631172, 203463116... | university | Jadavpur University | Q2579702 | en:Jadavpur University | POLYGON ((88.41345 22.56002, 88.41299 22.55919... | NaN |
In [ ]:
JU_gdf1.hvplot( geo=True, tiles='EsriImagery'
)
Out[ ]:
In [ ]:
JU_gdf.plot()
Out[ ]:
<Axes: >
In [ ]:
JU_gdf.hvplot( geo=True, tiles='EsriImagery'
)
Out[ ]:
In [ ]:
%%capture
%%bash
#Coverting to HTML
jupyter nbconvert first-map.ipynb --to html