[A couple of other questions deal with this sort of problem (see Comparing projections of two datasets when SRID not available and How to test if two GDAL datasets are in the same projection?) but not from an R perspective.]
I'm trying to figure out the best way to compare projections in R because I have a list of shapefiles and I want to reproject them to WGS84 if they are not currently in WGS84.
I thought of several ways to do this, but none seem to be bulletproof:
- The simplest way I can think of to do this is to use the equality operator to directly compare two proj4 strings but this will fail, for example, if there are spurious spaces in the strings or differences in decimal places.
- I had also thought about trying to determine the EPSG code of a proj4 string and comparing it to 4326 but (I think) not all proj4 strings have corresponding EPSG codes.
- Finally, I thought about just using
spTransform()
on all my layers (~10,000 of them) regardless of whether they're in WGS84 already or not but I figure this will eat a lot of unnecessary compute-time.
I've probably missed something, but I don't seem to be able to find any functions in packages like sp
or rgdal
that would do a comparison for me.
So, what have I missed? Are there best practices for performing projection comparisons in R?