I have a number of shapefiles in different CRSs (mostly WGS84 lat/lon) that I'd like to transform into a common projection (likely Albers Equal Area Conic, but I may ask for help on choosing in another question once my problem gets better-defined).
I spent a few months doing spatial stats stuff in R, but it was 5 years ago. For the life of me, I cannot remember how to transform an sp
object (e.g. SpatialPolygonsDataFrame
) from one projection to another.
Example code:
P4S.latlon <- CRS("+proj=longlat +datum=WGS84")
hrr.shp <- readShapePoly("HRR_Bdry"), verbose=TRUE, proj4string=P4S.latlon)
# Shapefile available at
# http://www.dartmouthatlas.org/downloads/geography/hrr_bdry.zip
# but you must rename all the filenames to have the same
# capitalization for it to work in R
Now I have a SpatialPolygonsDataFrame
with appropriate projection information, but I'd like to transform it to the desired projection. I recall there being a somewhat unintuitively-named function for this, but I can't remember what it is.
Note that I do not want just to change the CRS but to change the coordinates to match ("reproject", "transform", etc.).
Edit
Excluding AK/HI which are annoyingly placed in Mexico for this shapefile:
library(taRifx.geo)
hrr.shp <-
subset(hrr.shp, !(grepl( "AK-" , hrr.shp@data$HRRCITY ) |
grepl( "HI-" , hrr.shp@data$HRRCITY )) )
proj4string(hrr.shp) <- P4S.latlon