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.
Este ejercicio forma parte del curso
Visualizing Geospatial Data in R
Instrucciones del ejercicio
- Call
proj4string()onneighborhoods, then again onnyc_tracts. Verify the two strings are different. - Take a look at the
head()of thecoordinates()ofneighborhoodsand repeat fornyc_tracts. Can you see the problem?nyc_tractshas x coordinates around -70, butneighborhoodsis around 1,000,000! - Plot
neighborhoods, then plotnyc_tractswithcol = "red"andadd = TRUEto add them on top.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
library(sp)
# proj4string() on nyc_tracts and neighborhoods
# coordinates() on nyc_tracts and neighborhoods
# plot() neighborhoods and nyc_tracts