Aan de slagGa gratis aan de slag

Merging data from different CRS/projections

Every spatial object has a coordinate reference system (CRS) associated with it. Generally, this is set when the data are imported and will be read directly from the spatial files. This is how the neighborhoods and nyc_tracts obtained their coordinate system information.

Both the sp and raster packages have a proj4string() function that returns the CRS of the object it's called on.

Trying to work with spatial data using different CRSs is a bit like trying to work with a dataset in miles and another in kilometers. They are measuring the same thing, but the numbers aren't directly comparable.

Let's take a look at our two polygon objects.

Deze oefening maakt deel uit van de cursus

Visualizing Geospatial Data in R

Cursus bekijken

Oefeninstructies

  • Call proj4string() on neighborhoods, then again on nyc_tracts. Verify the two strings are different.
  • Take a look at the head() of the coordinates() of neighborhoods and repeat for nyc_tracts. Can you see the problem? nyc_tracts has x coordinates around -70, but neighborhoods is around 1,000,000!
  • Plot neighborhoods, then plot nyc_tracts with col = "red" and add = TRUE to add them on top.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

library(sp)

# proj4string() on nyc_tracts and neighborhoods



# coordinates() on nyc_tracts and neighborhoods



# plot() neighborhoods and nyc_tracts

Code bewerken en uitvoeren