{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Street Trees\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import geopandas as gpd\n", "\n", "import colorcet as cc\n", "import hvplot.pandas" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = 'http://data.phl.opendata.arcgis.com/datasets/957f032f9c874327a1ad800abd887d17_0.geojson'\n", "trees_gdf = gpd.read_file(url)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "trees_gdf[:10000].hvplot.points('Longitude', 'Latitude', title='Street Tree Density',\n", " geo=True, datashade=True, dynspread=True, framewise=False,\n", " height=500, width=500, legend=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Speeding up trees\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "trees_gdf.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "trees_df = pd.DataFrame({'Longitude': trees_gdf.geometry.x, 'Latitude': trees_gdf.geometry.y})\n", "trees_df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we'll plot again, using a the new dataframe and a colormap that is more fitting for trees. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "trees_df.hvplot.points('Longitude', 'Latitude', title='Street Tree Density',\n", " geo=True, datashade=True, dynspread=True, framewise=False,\n", " height=500, width=500, legend=False, cmap=cc.kgy[::-1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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](03_heat_and_trees.ipynb)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "trees_df.to_parquet('./data/trees.parq')" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }