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 | 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

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 = ""
treedf = gd.read_file(trees)       
structures = ""
structuresdf = gd.read_file(structures)  
ashprob = gd.sjoin(ashtreedf, structuresdf, how="inner", op='intersects')

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


  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
© 2023 by the Rector and Visitors of the University of Virginia
Copyright & Privacy