Add Filter Geo Map
Import libraries¶
In [1]:
import geopandas as gpd
import ipywidgets as widgets
from IPython.display import display
import hagerstrand as hs
import pandas as pd
import ipyleaflet
Load data as (Geo)DataFrame¶
In [2]:
lines = gpd.read_file("../../examples/data/cbg_poi_lines.json")
In [3]:
len(lines)
Out[3]:
4085
Deduplicate rows¶
In [4]:
lines = hs.ExtendedDataFrame(lines)
lines = lines.deduplicate(["PlusCode", "GEOID"])
In [5]:
len(lines)
Out[5]:
3232
Set variables¶
In [6]:
df = lines.copy()
field = "GEOID"
Filter a (Geo)DataFrame based on a single value in a column¶
In [7]:
hs.filter_df_widget(df=df, field=field)
Center map and initialize Google Earth Engine¶
In [8]:
Map_hs = hs.Map(center=[35.9606,-83.9207], zoom=10) # Create map instance
hs.ee_initialize() # Initialize Google Earth Engine
Add a GeoDataFrame to the map¶
In [9]:
linez = gpd.GeoDataFrame(df)
In [10]:
Map_hs.add_gdf(linez)
Load interactive map¶
In [11]:
Map_hs
Longer way of converting geopandas GeoDataFrame to the map based on ipyleaflet functions¶
Convert a pandas DataFrame to a GeoJSON¶
In [12]:
hs.df_to_geojson(df, properties, vector_geom='LineString', coords=["geometry"], out_geojson="../../data/sample.geojson")
Convert a pandas GeoDataFrame into an ipyleaflet.GeoData object that can be added to a map¶
In [13]:
linez_geoData = ipyleaflet.GeoData(geo_dataframe=linez, name="CBG to Store Connections")
Map_hs.add_layer(linez_geoData)
In [ ]:
Map_hs
Last update: 2021-05-03