Introduction to Shapefiles and Vector Data in Open Source Python - Spatial Data


Welcome to Week 3!

Welcome to week 3 of Earth Analytics! This week, you will dive deeper into working with spatial data in Python. You will learn how to handle data in different coordinate reference systems, how to create custom maps and legends and how to extract data from a raster file. You are on your way towards integrating many different types of data into your analysis which involves knowing how to deal with things like coordinate reference systems and varying data structures.

What You Need

You will need a computer with internet access to complete this lesson and the spatial-vector-lidar data subset created for the course. Note that the data download below is large (172MB) however it contains data that you will use for the next 2 weeks! The best way to get the data is to use earthpy:

et.data.get_data("spatial-vector-lidar")

You can also download the data using the link below.

Download Spatial Lidar Teaching Data Subset data

or using the earthpy package: et.data.get_data("spatial-vector-lidar")

1. Complete the Assignment Below

Homework

The Homework Assignment for This Week Can Be Found on Github

Click here to view the GitHub Repo with the assignment template.

The lessons for this week have been moved to our Intermediate Earth Analytics Textbook.

Please read the following chapters to support completing this week’s assignment:

Downloading from https://ndownloader.figshare.com/files/12459464
Extracted output to /root/earth-analytics/data/spatial-vector-lidar/.

Plot 1 - Roads Map and Legend

/opt/conda/lib/python3.7/site-packages/geopandas/geoseries.py:358: UserWarning: GeoSeries.notna() previously returned False for both missing (None) and empty geometries. Now, it only returns False for missing values. Since the calling GeoSeries contains empty geometries, the result has changed compared to previous versions of GeoPandas.
Given a GeoSeries 's', you can use '~s.is_empty & s.notna()' to get back the old behaviour.

To further ignore this warning, you can do: 
import warnings; warnings.filterwarnings('ignore', 'GeoSeries.notna', UserWarning)
  return self.notna()
Map showing the SJER field site roads and plot locations clipped to the site boundary.
Map showing the SJER field site roads and plot locations clipped to the site boundary.

Plot 2 - Roads in Del Norte, Modoc & Siskiyou Counties in California

/opt/conda/lib/python3.7/site-packages/geopandas/geoseries.py:358: UserWarning: GeoSeries.notna() previously returned False for both missing (None) and empty geometries. Now, it only returns False for missing values. Since the calling GeoSeries contains empty geometries, the result has changed compared to previous versions of GeoPandas.
Given a GeoSeries 's', you can use '~s.is_empty & s.notna()' to get back the old behaviour.

To further ignore this warning, you can do: 
import warnings; warnings.filterwarnings('ignore', 'GeoSeries.notna', UserWarning)
  return self.notna()
/opt/conda/lib/python3.7/site-packages/geopandas/geoseries.py:358: UserWarning: GeoSeries.notna() previously returned False for both missing (None) and empty geometries. Now, it only returns False for missing values. Since the calling GeoSeries contains empty geometries, the result has changed compared to previous versions of GeoPandas.
Given a GeoSeries 's', you can use '~s.is_empty & s.notna()' to get back the old behaviour.

To further ignore this warning, you can do: 
import warnings; warnings.filterwarnings('ignore', 'GeoSeries.notna', UserWarning)
  return self.notna()
Map showing the roads layer clipped to the three counties and colored according to which county the road is in.
Map showing the roads layer clipped to the three counties and colored according to which county the road is in.

Plot 3 - Census Data

You can use the code below to download and unzip the data from the Natural Earth website. Please note that the download function was written to take

  1. a download path - this is the directory where you want to store your data
  2. a url - this is the URL where the data are located. The URL below might look odd as it has two “http” strings in it but it is how the url’s are organized on natural earth and should work.

The download() function will unzip your data for you and place it in the directory that you specify.

Downloading from https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries.zip
Extracted output to /root/earth-analytics/data/earthpy-downloads/ne_10m_admin_0_countries
/opt/conda/lib/python3.7/site-packages/pandas/core/reshape/merge.py:618: UserWarning: merging between different levels can give an unintended result (1 levels on the left, 2 on the right)
  warnings.warn(msg, UserWarning)
Natural Earth Global Mean population rank and total estimated population
Natural Earth Global Mean population rank and total estimated population