On 11/01/2013 02:15 PM, Andy South wrote:
<rr2box42 <at>
gmail.com> writes:
Hi All,
I'm trying to use the 'coastsCoarse' dataset from library 'rworldmap' as
a
base map for plotting a global
dataset. It works fine when I use unprojected data. However, if I
project
coastsCoarse ends up with one horizontal line segment that spans the
whole
map. You can see what I mean like this:
Hi Ryan,
I think I've identified the offending segment (see below), but haven't
yet
been able to remove it. I'm sure someone else on the list better at
manipulating sp objects will be able to help with getting around the
error
below :
'setting coordinates cannot be done on Spatial objects, where they have
already been set'
Once we've fixed this I'll try fixing in rworldmap by removoing the
corresponding point in the unprojected file.
Please let me know where you learned that you could use coordinates() to
assign coordinates to a Spatial* object.
# ---------------------------------------
library(rgdal)
library(rworldmap)
data(coastsCoarse)
plot(coastsCoarse) # Looks good
mercator.proj4 = "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84
+datum=WGS84 +units=m +no_defs"
coastsMerc = spTransform(coastsCoarse, CRS(mercator.proj4))
spplot(coastsMerc) # horizontal line across plot connects east and west
Beringia...
#the problem is with line 94
plot(coastsMerc[94,])
#look at the last and the first point see which is the problem
coordinates(coastsMerc[94,])
#looks like the last point is the problem try removing it
numToRemove <- nrow(coastsMerc[94,]@lines[[1]]@Lines[[1]]@coords)
coordinates(coastsMerc[94,]) <-
coastsMerc[94,]@lines[[1]]@Lines[[1]]@coords[-numToRemove,]
#Error in `coordinates<-`(`*tmp*`, value = c(-1809707.97165956,
-1823151.78413843, :
#setting coordinates cannot be done on Spatial objects, where they have
already been set
a wild guess, but this might work:
coastsMerc at lines[[94]]@Lines[[1]]@coords <-
coastsMerc[94,]@lines[[1]]@Lines[[1]]@coords[-numToRemove,,drop=FALSE]
It seems like the boundary of northern Russia didn't get cut off
correctly. I imagine the fix is
straightforward, but I've been banging away at it to no avail. Does
anyone
have a simple solution that
either (a) locates and removes the offending pan-global segment or (b)
doesn't produce it to begin with?