Introduction to Spatial Analysis

Day 2 - Spatial Operations

Jonathan Phillips

January, 2019

Transforming Spatial Data

Transforming Spatial Data

From Polygons to Points - Centroids

  • How far is it between São Paulo and the other municipalities in São Paulo?
    • We only have the polygon shapefile…

Transforming Spatial Data

From Polygons to Points - Centroids

  • How far is it between São Paulo and the other municipalities in São Paulo?
    • We only have the polygon shapefile…

Transforming Spatial Data

From Polygons to Points - Centroids

  • How far is it between São Paulo and the other municipalities in São Paulo?
    • A distance vector

      V1
      140 365011.59 m
      586 82332.68 m
      461 50681.76 m
      568 261071.83 m
      185 451628.42 m
      335 519815.11 m
      97 589514.12 m
      456 156418.58 m

Transforming Spatial Data

From Polygons to Points - Centroids

  • How far is it between each municipality in São Paulo?
    • A distance matrix

      V1 V2 V3 V4 V5
      0.00 m 18 956.267 m 19 251.624 m 128 686.49 m 134 478.11 m
      18956.27 m 0.000 m 7280.954 m 145456.29 m 149857.24 m
      19251.62 m 7280.954 m 0.000 m 147785.28 m 153066.04 m
      128686.49 m 145456.295 m 147785.277 m 0.00 m 20069.45 m
      134478.11 m 149857.243 m 153066.041 m 20069.45 m 0.00 m

Transforming Spatial Data

From Points to Polygons - Buffers

  • We want to find the area within 10km of each point

Transforming Spatial Data

From Points to Polygons - Buffers

  • We want to find the area within 10km of each point

Transforming Spatial Data

From Points to Polygons - Voronoi Polygons

  • When we want no gaps between the polygons
    • Each point in space assigned to the nearest centroid

Transforming Spatial Data

From Points to Polygons - Voronoi Polygons

  • When we want no gaps between the polygons
    • Each point in space assigned to the nearest centroid

Transforming Spatial Data

From Points to Polygons - Voronoi Polygons

  • When we want no gaps between the polygons
    • Each point in space assigned to the nearest centroid

Transforming Spatial Data

From Points to Lines - Creating a Graph

  • How would we drive between the top 1% richest municipalities?

Transforming Spatial Data

From Points to Lines - Creating a Graph

  • How would we drive between the top 1% richest municipalities?

Transforming Spatial Data

From Points to Lines - Creating a Graph

  • How would we drive between the top 1% richest municipalities?

Transforming Spatial Data

From Polygons to Lines - Boundaries

Transforming Spatial Data

From Polygons to Lines - Boundaries

Transforming Spatial Data

From Polygons to (bigger) Polygons - Dissolve

  • Aggregating municipal polygons to state polygons by dissolving internal boundaries

Transforming Spatial Data

From Polygons to (bigger) Polygons - Dissolve

  • Aggregating municipal polygons to state polygons by dissolving internal boundaries

Transforming Spatial Data

From Points to (fewer) Points - Clip/Subset

  • Selecting only the points within a polygon
    • Only the centroids in the polygons of São Paulo city or Campinas

Transforming Spatial Data

Summary of Transformations:

Layers

  • The power of spatial analysis comes from combining data sources
    • Spatial + Non-Spatial
    • Spatial + Spatial
  • This helps us answer new questions:
    • Where are left-wing votes geographically clustered?
    • Are school results better north or south of the river?
    • Do places with less rainfall suffer more violence?

Layers

  • Spatial layers ‘overlap’ based on their common location attributes
    • CRUCIAL to have the same projection
    • Less important which projection
  • Handling multiple layers:
    • Hard in Stata
    • Easy in GIS
    • Easy in R

Layers

Non-Spatial Joins

  • Governments publish school performance data
    • But what is the spatial pattern of school performance?
  • We need a source for the location of the schools

  • How do we combine the school performance and location datasets?
    • Join on a unique identifier

Non-Spatial Joins

Spatial Joins

  • Do schools located in the cerrado (‘savannah’) perform better than those in other regions?
    • Two spatial data sources: school point locations, and cerrado area
    • Calculation: Average school performance by ecological region
    • But which schools are in which region?
  • We need to overlay the schools on the map of the cerrado and ‘add’ the ecological region details to the school dataset

Spatial Joins

Points in Polygons

  • How many earthquakes have occurred in each country?
    • Easy with a spatial join!

Points in Polygons

  • How many earthquakes have occurred in each country?
    • Easy with a spatial join!
Country Number of Earthquakes
China 157
Indonesia 113
Iran 106
Turkey 77
Japan 61

Spatial Relations

  • With multiple layers, we can combine them to make new spatial objects
    • Not just to share attributes

Intersection
What portion of Minas Gerais is in the cerrado?

Union
- What land is either in Minas Gerais or in the cerrado?

Example of Spatial Operations

We want to find all the villages within 3km of the Bihar-Jharkhand Border in Bihar

  1. Convert village polygons to centroid points
  2. Filter border to Bihar-Jharkhand section
  3. Create 3km buffer around border
  4. Clip villages to border buffer
  5. Calculate distance to the border for every village

Example of Spatial Operations

Example of Spatial Operations

Example of Spatial Operations

Example of Spatial Operations

Example of Spatial Operations

Example of Spatial Operations

Example of Spatial Operations