[R-sig-Geo] map2SpatialLines and map('world2')

Roger Bivand Roger.Bivand at nhh.no
Sun Jul 3 15:59:20 CEST 2011


On Sat, 2 Jul 2011, Rob Hodges wrote:

> Greetings R-sig-geo'ders;
>
> I want to use the Pacific-centric world map 'world2' from the maps package
> for use with hurricane observations. I am also making use of the sp spatial
> data classes. The following (Atlantic-centric) example works:
>
> x = map('world', plot=F)
> x_sl = map2SpatialLines(x, proj4string=CRS("+proj=longlat +datum=WGS84"))
>
> However, the map2SpatialLines function when using 'world2' - the
> Pacific-centric world map - fails.
>
> x_pac = map('world2', plot=F)
> x_pac_sl = map2SpatialLines(x, proj4string=CRS("+proj=longlat
> +datum=WGS84"))
> *Error in validityMethod(object) :
>  Geographical CRS given to non-conformant data*
>
> Interestingly: The range on longitude for x is roughly 0 to 180, while the
> range on longitude for x_pac is 0 to 360. Didn't know if that had something
> to do with it.

> x_pac$range
[1]  -5.072266 369.988892 -85.443077  83.573914
> x$range
[1] -179.95721  190.29080  -85.44308   83.57391

where the world2 data falls foul of:

> sp:::.ll_sanity
function (bb)
{
     tol <- .Machine$double.eps^0.25
     W <- bb[1, 1] < -180 && !isTRUE(all.equal((bb[1, 1] - -180),
         0, tolerance = tol))
     E <- bb[1, 2] > 360 && !isTRUE(all.equal((bb[1, 2] - 360),
         0, tolerance = tol))
     S <- bb[2, 1] < -90 && !isTRUE(all.equal((bb[2, 1] - -90),
         0, tolerance = tol))
     N <- bb[2, 2] > 90 && !isTRUE(all.equal((bb[2, 2] - 90),
         0, tolerance = tol))
     return(!(any(W || E || S || N)))
}
<environment: namespace:sp>

and its limit at just over 360 degrees. If what you need are lines as a 
background, then pruneMap() may help:

x_pac_sl = map2SpatialLines(pruneMap(x_pac, xlim=c(0, 360)),
   proj4string=CRS("+proj=longlat +datum=WGS84"))

by trimming lines. Alternatives through recenter methods often lead to 
horizonal stripes.

Hope this helps,

Roger

>
> Thanks in advance,
>
> - Rob Hodges
> FSU, Geography
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list