Geographic Information Systems Asked by hendra on December 20, 2020
[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:
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?
If you have a correctly projected file, Raster library has a simple function to compare CRS.
Library(raster)
compareCRS(shpA, shpB)
[1] TRUE
Using it would save you the time of writing your own function to compare the strings. If nothing else this would let you create a vector of which shapes are correctly projected. Reprojecting the shapes however might be faster to do in python (both probably pulling on gdal however. Just a matter of which environment).
Answered by SeldomSeenSlim on December 20, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP