[R-sig-Geo] Projected SpatialLinesDataFrame has a segment spanning the globe

rr2box42 rr2box42 at gmail.com
Fri Nov 1 16:21:12 CET 2013


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
> On 11/01/2013 02:15 PM, Andy South wrote:
>> Ry Guy 
> <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 
>> the data and base map,
>>> 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.
> 
>> Best wishes,
>> Andy
>> 
>>>
>>> # ---------------------------------------
>>> 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?
>>>
>>> Thanks much,
>>> Ryan
>>>
>> 
>> _______________________________________________
>> R-sig-Geo mailing list
>> 

> R-sig-Geo@

>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> 
> 
> -- 
> Edzer Pebesma
> Institute for Geoinformatics (ifgi), University of Münster
> Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
> 83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795
> 
> 
> _______________________________________________
> R-sig-Geo mailing list

> R-sig-Geo@

> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> 
> signature.asc (567 bytes)
> <http://r-sig-geo.2731867.n2.nabble.com/attachment/7585016/0/signature.asc>





--
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.



More information about the R-sig-Geo mailing list