Skip to content
Prev 17156 / 29559 Next

proj4string-issue - leading spaces

On 11-Jan-13 12:42, Roger Bivand wrote:
You mean that the suggestion does not solve the problem when using CRS 
from sp instead of rgdal as the sp-version does not trim leading spaces? 
Then I think an alternative sp version could use gsub without being too 
complicated. Leading spaces can be removed from the proj4string if they 
exists, NAs are not touched:

ch = "+init=epsg:4326"
gsub("^ .", "", ch)
ch = " +init=epsg:4326"
gsub("^ .", "", ch)
ch = NA
gsub("^ .", "", ch)

and the function could be something like:

identicalCRS = function(x,y) {
   if (inherits(x, "Spatial")) x = proj4string(x)
   if (inherits(y, "Spatial")) y = proj4string(y)
   x = gsub("^ .", "", y)
   y = gsub("^ .", "", y)
   identical(x,y)
}

Two NA-proj4strings will be treated as identical, same as they are now. 
However, it will not catch the similarity between "+init=epsg:4326" and 
"+init=epsg:4326 +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs 
+towgs84=0,0,0" such as a possible rgdal-version (first suggestion 
above) can do.

Cheers,
Jon