Dear Mike,

Thank you for your answer.

I get an error with the polygons intersection:

> wrld.clip <- gIntersection(clipPoly, wrld_simpl)

Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, "rgeos_intersection")
:

  TopologyException: side location conflict at -91.437497778887078
17.241108073444931

The problem seems to be a bad polygon in the wrld_simpl database

> gIsValid(wrld_simpl)

[1] FALSE

Warning message:

In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") :

  Ring Self-intersection at or near point -95.902496339999999
66.946641920000005


Any way to fix it?

BTW, I am sorry for the packages call. Here it comes:
library(maps)
library(maptools)
library(rgdal)

/Gis



On 12 November 2012 12:08, Michael Sumner <mdsumner@gmail.com> wrote:

> 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@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@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
> --
> Michael Sumner
> Hobart, Australia
> e-mail: mdsumner@gmail.com
>

	[[alternative HTML version deleted]]

