Skip to content

Shifting x coordinates by 180

3 messages · Leigh Kroeger, Roland Harhoff, Michael Sumner

#
Hello,

I have the following shapefile imported into R:
Object of class SpatialPolygonsDataFrame
Coordinates:
         min        max
x -165.73220 -123.23912
y   29.55567   46.44211
Is projected: FALSE
proj4string : [+proj=longlat +ellps=WGS84]

I need to shift 'x' by adding 180 to the data column. I think the 'elide'
function in maptools can accomplish this but the following error comes up
when I start the code:
Error in `coordinates<-`(`*tmp*`, value = c("x", "y")) :   setting
coordinates cannot be done on Spatial objects, where they have already been
set

My intended outcome is to be able to plot occurrence data from GBIF onto
the polygon shapefile.

Regards,
#
Hello Leigh,

the error message clearly states the problem. A workaround would maybe to
extract the coordinates (Try to use function lapply due to the polygons slot
is a list.). Then change the coordinates as desired and create a new
SpatialPolygons object. In the end create a new SpatialPolygonsDataFrame out
of the new SpatialPolygons and the original data.

It is just an idea and not tested ; ) .

See also
?SpatialPolygonsDataFrame
?SpatialPolygons
etc.

With best regards

Roland


Leigh Kroeger schrieb am 2014-10-15:

        
#
Why not just use elide as you stated?

Why are you using coordinates()<-?

??
On Wed, Oct 15, 2014 at 7:33 PM, Leigh Kroeger <leigh.kroeger at gmail.com> wrote: