[R-sig-Geo] proj4string-issue - leading spaces

Jon Olav Skoien jon.skoien at jrc.ec.europa.eu
Fri Jan 11 14:29:06 CET 2013


On 11-Jan-13 12:42, Roger Bivand wrote:
> On Fri, 11 Jan 2013, Edzer Pebesma wrote:
>
>>
>>
>> On 01/11/2013 12:10 PM, Jon Olav Skoien wrote:
>>>
>>> Is there a simple way to solve this, not having check and modify the
>>> proj4string of all objects? Or could the call to identical in functions
>>> like over be replaced by an identicalCRS()-function?
>>>
>>> identicalCRS = function(x,y) {
>>>   identical(CRS(proj4string(x)), CRS(proj4string(y)))
>>> }
>>
>> Great suggestion, Jon; I added this to sp on r-forge.
>
> Not so great, it doesn't address the problem that users with different 
> versions of rgdal (and/or with stored objects from older versions of 
> rgdal) may have extraneous prepended spaces. The function nees to test 
> for NA or not, then length, if lengths equal, OK, test, if differ by 
> one check whether space and if so trim, ...
>
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


-- 
Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Land Resource Management Unit

Via Fermi 2749, TP 440,  I-21027 Ispra (VA), ITALY

jon.skoien at jrc.ec.europa.eu
Tel:  +39 0332 789206

Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission.



More information about the R-sig-Geo mailing list