[R-sig-Geo] Lines crossing Mercator projection map
Michael Sumner
mdsumner at gmail.com
Mon Nov 12 12:08:26 CET 2012
This is happening because the maps data has data that is out of the
range of [-180, 180], either from the source data itself or from the
clipping somehow:
range(world.map$x, na.rm = TRUE)
[1] -179.9572 190.2908
You would have to carefully clean this up to make it useable, but I
would just avoid it and use the clean data set in maptools (or import
your own from some other source.
Here you can intersect a polygon with wrld_simpl to clip it from the
infinities at the poles before reprojecting:
library(maptools)
library(rgdal)
library(rgeos)
data(wrld_simpl)
poly <- Polygon(cbind(c(-180, 180, 180, -180, -180), c(-80, -80, 80, 80, -80)))
clipPoly <- SpatialPolygons(list(Polygons(list(poly), ID = "1")),
proj4string = CRS(proj4string(wrld_simpl)))
wrld.clip <- gIntersection(clipPoly, wrld_simpl)
wrld.merc <- spTransform(wrld.clip, CRS("+proj=merc"))
plot(wrld.merc)
Also, please declare the packages you have in use with library() or
require() so that code is reproducible.
Cheers, Mike.
On Mon, Nov 12, 2012 at 11:06 AM, Giuseppe Bianco <giubi78 at gmail.com> wrote:
> Dear List,
>
> I have been struggling all the day long with this issue but I didn't find
> any workaround.
>
> I would like to have exactly the map that come out from the code below but
> without the ugly line crossing one side to the other.
>
> world.map <- map(fill=T, plot=F)
> IDs <- sapply(strsplit(world.map$names, ":"), function(x) x[1])
> poly.map <- map2SpatialPolygons(world.map, IDs=IDs,
> proj4string=CRS("+proj=longlat"))
> merc.map <- spTransform(poly.map, CRS("+proj=merc"))
>
> # Set the map to -80 to 80
> bb <- cbind(c(-180, 180), c(-80, 80))
> bb.poly <- SpatialPoints(bb, proj4string = CRS("+proj=longlat"))
> bb.merc <- spTransform(bb.poly, CRS("+proj=merc"))
> bb.merc <- as.data.frame(bb.merc)
>
> # Here the ugly plot
> plot(merc.map, col="gray", border="gray", xlim=bb.merc[,1],
> ylim=bb.merc[,2])
>
> Any help is very appreciated,
> /Gis
>
> [[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
--
Michael Sumner
Hobart, Australia
e-mail: mdsumner at gmail.com
More information about the R-sig-Geo
mailing list