# IT Services Blog

## Using tree data in a Python 3 Jupyter Notebook

by Anson Parker on 2019-12-06T15:55:00-05:00 | 0 Comments

Google Colab provides a free Jupyter environment for testing ideas

is the same example as the project done in Chapter 1 with QGIS

Because we need to do some special calculations in Python in this example we start out loading libspatialindex in to the notebook Note 1: Using the ! lets us work on the command line of the virtual machine - the exclamation point puts us straight in to a bash environment, and we can run commands as if we were logged in to a terminal

so after downloading, configuring, making, and installing the software we are ready to load up the Python Geopandas library for running queries and doing manipulations on spatial data.  we will also have the Shapely library available to buffer the tree points to search for intersections

!pip install geopandas
!pip install rtree
!pip install geopy
!pip install osmnx
import pandas as pd
import geopandas as gd
import matplotlib.pyplot as plt
import zipfile

trees = "https://opendata.arcgis.com/datasets/e7c856379492408e9543a25d684b8311_79.geojson"
structures = "https://opendata.arcgis.com/datasets/431d3b5cde454e9f9c65725cc2f44c97_45.geojson"
ashtreedf=treedf[treedf['Common_Name'].str.contains('Ash')]
ashtreedf['geometry']=ashtreedf.geometry.buffer(.0001,resolution=5)
ashprob = gd.sjoin(ashtreedf, structuresdf, how="inner", op='intersects')
cost=len(ashprob.index)
print(cost*5000)
print(len(ashprob.index))
ashprob.plot()

That's all there is to test the same process as done in QGIS. We also added a \$5000 per tree cost in there, so that we can estimate budgetary costs in this query