OpenDataPhilly released an inventory of all the street trees in the city. Street trees are trees that are planted along streets, not those in parks and private property. Using datashader
we can easily plot these 100,000 points.
import pandas as pd
import geopandas as gpd
import colorcet as cc
import hvplot.pandas
url = 'http://data.phl.opendata.arcgis.com/datasets/957f032f9c874327a1ad800abd887d17_0.geojson'
trees_gdf = gpd.read_file(url)
trees_gdf[:10000].hvplot.points('Longitude', 'Latitude', title='Street Tree Density',
geo=True, datashade=True, dynspread=True, framewise=False,
height=500, width=500, legend=False)
The trees plot can be generated straight from the geopandas dataframe, but that is rather slow. By inspecting the dataframe, we can see that each tree is represented as a point. We can create a simpler pandas dataframe with lat as one column and lon as the other.
trees_gdf.head()
trees_df = pd.DataFrame({'Longitude': trees_gdf.geometry.x, 'Latitude': trees_gdf.geometry.y})
trees_df.head()
Now we'll plot again, using a the new dataframe and a colormap that is more fitting for trees.
trees_df.hvplot.points('Longitude', 'Latitude', title='Street Tree Density',
geo=True, datashade=True, dynspread=True, framewise=False,
height=500, width=500, legend=False, cmap=cc.kgy[::-1])
Notice how much faster it is to rerender on zoom using this new version of the data. We'll save that off for use in the next notebook.
trees_df.to_parquet('./data/trees.parq')