Skip to content

a minor bug in rgdal?

3 messages · Roger Bivand, Martin Ivanov

#
Dear Prof. Bivand,

I am running R-2.15.2 with rgdal version 0.7-22.
I noticed the following bug: when transforming a SpatialPoints object,
a white space is prepended to the proj4string of the target CRS. For 
example:

crds <- matrix(data=c(9.05, 48.52), ncol=2)
spPoint <- SpatialPoints(coords=crds,
  proj4string=CRS("+proj=longlat +ellps=sphere +no_defs"))
a <- spTransform(spPoint, CRS(paste("+proj=ob_tran +o_proj=longlat",
  "+o_lon_p=-162 +o_lat_p=39.25 +lon_0=180 +ellps=sphere +no_defs")),
  use_ob_tran=TRUE)

proj4string(a)
# " +proj=ob_tran +o_proj=longlat +o_lon_p=-162 +o_lat_p=39.25 
+lon_0=180 +ellps=sphere +no_defs"

As You can see, a white space is prepended to the proj4string, from 
"+proj=ob_tran ..."
it becomes " +proj=ob_tran ...". This leads to errors when one 
interpolates using krige from gstat for example.

Best regards,
#
On Sat, 8 Dec 2012, epaiv01 wrote:

            
Thanks for a helpful example. The problem has been around for a long time, 
and is basically caused by pj_get_def() in PROJ.4, which prepends a space. 
This function is called in various places in rgdal, and in addition, when 
the sp constructor method for CRS objects is called when rgdal is loaded, 
it is called then too; it checks the string for formal errors. Probably a 
forthcoming release of sp would have permitted this to be resolved at the 
R level, but in order to sort things out for earlier sp versions, I've 
added a trap in the C code in rgdal. I've committed the fix to R-forge SVN 
revision 402.

Please let me know if this helps,

Roger

  
    
#
Dear Prof. Bivand,

Thank You very much for Your fast response. Now the proj4string after 
spTransform is ok.
Many thanks again.

Best regards,

Martin Ivanov
On 12/08/2012 08:39 PM, Roger Bivand wrote: