[Rspatial-devel] proj4string<-

Edzer Pebesma edzer.pebesma at uni-muenster.de
Wed Mar 28 12:50:28 CEST 2012



On 03/28/2012 12:41 PM, Roger Bivand wrote:
> 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?

It is exactly what I intended ;-)

Thanks,

> 
> Roger
> 
> 
>>>
>>> Roger
>>>
>>>>
>>>
>>
>>
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de


More information about the Rspatial-devel mailing list