[Rspatial-devel] proj4string<-
Roger Bivand
Roger.Bivand at nhh.no
Wed Mar 28 12:41:49 CEST 2012
On Tue, 27 Mar 2012, Edzer Pebesma wrote:
>
>
> On 03/27/2012 02:41 PM, Roger Bivand wrote:
>> On Tue, 27 Mar 2012, Edzer Pebesma wrote:
>>
>>> I discovered today than a student assumed that in the following sequence:
>>>
>>> xx = readOGR('whatever shapefile')
>>> proj4string(xx) = "new proj4 string"
>>>
>>> would project to the new projection. The logic is that of
>>>
>>> coordinates(meuse) = c("x", "y")
>>>
>>> It doesn't, but also doesn't say it doesn't.
>>>
>>> https://stat.ethz.ch/pipermail/r-sig-geo/2012-March/014666.html
>>>
>>> is another case of the same assumption.
>>>
>>> I suggest to modify proj4string<- such that when it is called with a
>>> CRS, and the object already has a (non-NA) CRS, a message is printed
>>> that sais sth like:
>>>
>>> "A new CRS was assigned to an object with an existing CRS, without
>>> reprojecting. For reprojection, use function spTransform in package
>>> rgdal".
>>
>> Yes, that would make sense, but should it be a warning, or a message
>> controlled by an option? I do it often with GRASS because rasters and
>> vectors get different renderings of the same PROJ.4 string. So some
>> users could turn off the warning; maybe a flag could be set to show the
>> message once only too?
>
> Sounds good, but I don't know how to realize that.
>
As of revision 1234, I've tried to do this:
library(sp)
data(meuse)
coordinates(meuse) <- c("x", "y")
is.projected(meuse)
proj4string(meuse) <- CRS("+proj=utm +zone=30")
proj4string(meuse) <- CRS("+proj=utm +zone=30")
proj4string(meuse) <- CRS("+proj=utm +zone=31")
#Warning message:
#In `proj4string<-`(`*tmp*`, value = <S4 object of class "CRS">) :
# A new CRS was assigned to an object with an existing CRS:
#+proj=utm +zone=30
#without reprojecting.
#For reprojection, use function spTransform in package rgdal
set_ReplCRS_warn(FALSE)
proj4string(meuse) <- CRS("+proj=utm +zone=31")
proj4string(meuse)
The options are in AAA.R and spOptions.R, documented in is.projected.Rd,
and the revision in projected.R. I decided not to warn if the strings of
the old and new CRS are identical. Is this something like your intentions?
Roger
>>
>> Roger
>>
>>>
>>
>
>
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the Rspatial-devel
mailing list