Skip to content
Prev 19674 / 29559 Next

Projected SpatialLinesDataFrame has a segment spanning the globe

Ry Guy <rr2box42 <at> gmail.com> writes:
base map for plotting a global
the data and base map,
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.
Best wishes,
Andy
+datum=WGS84 +units=m +no_defs"
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
correctly. I imagine the fix is
have a simple solution that
doesn't produce it to begin with?