Researchers


IT Services Blog

IT services blog

Using tree data in a Python 3 Jupyter Notebook

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

Google Colab provides a free Jupyter environment for testing ideas

https://colab.research.google.com/drive/1MrwVZ5nx7TuulYOinr2M9a6Y-HVlAedF

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

loading libspatial index

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
 

Once the libraries are loaded

trees = "https://opendata.arcgis.com/datasets/e7c856379492408e9543a25d684b8311_79.geojson"
treedf = gd.read_file(trees)       
structures = "https://opendata.arcgis.com/datasets/431d3b5cde454e9f9c65725cc2f44c97_45.geojson"
structuresdf = gd.read_file(structures)  
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


 Add a Comment

0 Comments.

  Return to Blog
This post is closed for further discussion.

Skip to main content

Claude Moore Health Sciences Library
1350 Jefferson Park Avenue P.O. Box 800722
Charlottesville, VA 22908 (Directions)

facebook twitter instagram
© 2020 by the Rector and Visitors of the University of Virginia
Copyright & Privacy