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, 14062419214, 1406241... POLYGON ((-95.23831 38.93552, -95.23817 38.935...

1 rows × 22 columns

In [3]:
haskell_gdf.plot()
Out[3]:
<Axes: >
No description has been provided for this image

We have a map of the Haskell Campus!

Create an interactive map¶

There are lots of different ways to create maps and plots in Python. Here, we’re going to use a tool called 'hvplot' and 'geoviews' to create an interactive map, including the online 'EsriImagery' tile source basemap.

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]:
# 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 [9]:
colorado_gdf = osm.features_from_address(
    'University of Colorado Boulder, United States',
        {'amenity': ['university']})
colorado_gdf
Out[9]:
geometry nodes amenity boundary internet_access name operator short_name website wikidata wikipedia ele gnis:feature_id
element_type osmid
way 46226108 POLYGON ((-105.27589 40.01047, -105.27597 40.0... [589514700, 2188984094, 2188984095, 326889012,... university administrative wlan University of Colorado Boulder (Main Campus) University of Colorado Boulder CU Boulder https://www.colorado.edu/ Q736674 en:University of Colorado Boulder NaN NaN
391232001 POLYGON ((-105.26632 40.01452, -105.26631 40.0... [3944423259, 3944423260, 3944423261, 394442326... university NaN NaN Naropa University Naropa University NaN https://www.naropa.edu Q2975783 en:Naropa University 1620 178660
In [11]:
colorado_gdf.plot()
Out[11]:
<Axes: >
No description has been provided for this image
In [14]:
# Plot Colorado boundary
colorado_map = colorado_gdf.reset_index().hvplot(
    # Givethe map a descriptive title
    title="Colorado Universty, Boulder, United States",
    # 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(colorado_map, 'colorado.html')

# Display the map
colorado_map
WARNING:bokeh.core.validation.check:W-1005 (FIXED_SIZING_MODE): 'fixed' sizing mode requires width and height to be set: figure(id='p1397', ...)
Out[14]:
In [49]:
cimfr_gdf = osm.features_from_address(
    'Central Institute of Mining And Fuel Research - CIMFR,Dhanbad,India',
        {'amenity': ['college']})
cimfr_gdf
Out[49]:
nodes amenity fixme isced:level name wikidata wikimedia_commons wikipedia geometry
element_type osmid
way 825700044 [7709452515, 7709452514, 7709452513, 770945251... college isced:level (approximated from name) 4;5 Central Institute of Mining And Fuel Research ... Q18345017 Category:Central Institute of Mining and Fuel ... en:Central Institute of Mining and Fuel Research POLYGON ((86.41668 23.69268, 86.41800 23.69145...
In [50]:
cimfr_gdf.plot()
Out[50]:
<Axes: >
No description has been provided for this image
In [52]:
# Plot Central Institute of Mining and Fuel Research
cimfr_map = cimfr_gdf.reset_index().hvplot(
    # Givethe map a descriptive title
    title="Central Institute of Mining and Fuel Research,Dhanbad",
    # 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(cimfr_map, 'cimfr.html')

# Display the map
cimfr_map
WARNING:bokeh.core.validation.check:W-1005 (FIXED_SIZING_MODE): 'fixed' sizing mode requires width and height to be set: figure(id='p1926', ...)
Out[52]:
In [ ]:
%%capture
%%bash
#Coverting to HTML
jupyter nbconvert first-map.ipynb --to html