Skip to content

Projected SpatialLinesDataFrame has a segment spanning the globe

4 messages · Edzer Pebesma, rr2box42, Andy South

#
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?
#
On 11/01/2013 02:15 PM, Andy South wrote:
Please let me know where you learned that you could use coordinates() to
assign coordinates to a Spatial* object.
a wild guess, but this might work:

coastsMerc at lines[[94]]@Lines[[1]]@coords <-
 coastsMerc[94,]@lines[[1]]@Lines[[1]]@coords[-numToRemove,,drop=FALSE]

  
    
#
Thanks much to you both--Edzer's suggestion does work to remove the offending
vertex. Based on the input I managed an alternative, which is to correct the
original vertex to not pass 180 degrees longitude (it's currently at
180.0000004, which is apparently the problem):

ind = which(coastsCoarse at lines[[94]]@Lines[[1]]@coords[,1] > 180)
coastsCoarse at lines[[94]]@Lines[[1]]@coords[ind,1] = 180

Cheers,
Ryan



Edzer Pebesma-2 wrote

            

        
            

            

        
        
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Projected-SpatialLinesDataFrame-has-a-segment-spanning-the-globe-tp7585010p7585018.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
rr2box42 <rr2box42 <at> gmail.com> writes:
offending
180)
Thanks both, I'll fix in the next update to rworldmap.
I was just trying what seemed sensible, in sp help for coordinates() it says :
Description: retrieve (or set) spatial coordinates from (for) spatial data