Skip to content

Lines crossing Mercator projection map

5 messages · Michael Sumner, Roger Bivand, Giuseppe Bianco

#
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:

  
    
#
On Mon, 12 Nov 2012, Giuseppe Bianco wrote:

            
You need to provide the version of rgeos you are using - from 
sessionInfo(), and the messages printed when rgeos is loaded. For me with
rgeos: (SVN revision 360)
  GEOS runtime version: 3.3.5-CAPI-1.7.5
  Polygon checking: TRUE

and:
R version 2.15.2 (2012-10-26)
Platform: x86_64-unknown-linux-gnu (64-bit)
...
other attached packages:
[1] rgeos_0.2-9     rgdal_0.7-22    maptools_0.8-20 lattice_0.20-10
[5] sp_1.0-2        foreign_0.8-51

there is no problem.
On the same system, I also see this, but it isn't the cause of your 
problem. Please also stop posting HTML, it is being stripped anyway, so 
post plain text only, as the list instructions require.

Roger

PS: If you need the countries, use:

wrld.clip <- gIntersection(clipPoly, wrld_simpl, byid=TRUE)
row.names(wrld.clip)

shows the IDs.

  
    
#
Thank you Roger.

Below what I get (didn't change after update.packages("rgeos"))
rgeos: (SVN revision 357)
 GEOS runtime version: 3.3.3-CAPI-1.7.4
 Polygon checking: TRUE
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets
methods   base

other attached packages:
[1] rgeos_0.2-8     rgdal_0.7-22    maptools_0.8-18 lattice_0.20-10
sp_1.0-2
[6] foreign_0.8-51

Hope this helps.

/Gis
On 12 November 2012 19:19, Roger Bivand <Roger.Bivand at nhh.no> wrote: