Skip to content
Prev 16658 / 29559 Next

Lines crossing Mercator projection map

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: