Skip to content
Prev 8374 / 29559 Next

projection() and proj4string()

On Sat, 29 May 2010, Agustin Lobo wrote:

            
You are getting mixed up between packages. projection() is a function in 
the raster package, while proj4string() is a function in sp. Use 
projection() for classes defined or extended in raster, proj4string() for 
classes defined in sp. Critically, projection<-() tries to assign to a 
slot called "crs", which is not present in Spatial* objects.

My feeling is that the sp nomenclature is clearer but clunkier, because it 
specifies the representation of the projection as a PROJ.4 string, while 
the name of the function "projection" could admit arbitrary 
representations, but in fact uses the same representation and mechanisms 
as sp (with verification through the PROJ.4 library if rgdal is loaded).

Probably projection<-() needs the same if() statement as that used in 
projection(), to distinguish extensions of "BasicRaster" from those of 
"Spatial", in which case projection<-() and proj4string<-() will both work 
on objects extending "Spatial" too.

Roger