Hi,

Maybe you could ckeck, first, which geometries are not valid, using
gIsValid and using par. byid=TRUE
v <- gIsValid(vM.spdf, byid=TRUE)

Then, you could fix the topology problems.


2012/9/30 Brigitte Hogan <brigittehogan@gmail.com>

> I am having a problem with unionSpatialPolygons() in
> library(maptools). I am working with a shapefile of Mexico
> municipalities found here:
> http://mapserver.inegi.org.mx/data/mgm/
> under Marco Geoestadístico Municipal 2009 Versión 4.1,  Áreas
> Geoestadísticas Municipales (38.8 Mb).
>
> I need to combine the "Federal District" municipalities into one
> polygon. I am a new user of the sp and rgeos packages, running R
> version 2.13 under Windows 7. When I try to combine the districts, I
> get an error similar to one in the archive:
> https://stat.ethz.ch/pipermail/r-sig-geo/2011-August/012445.html
>
> I tried to run checkPolygonsHoles() as suggested, but I cannot figure
> out how to convert the SpatialPolygonsDataFrame or SpatialPolygons
> object into a Polygons object.  The solution to the error in the
> archive was to reset the significant digits. However, when I tried, I
> still ended up with the same error message. An excerpt from my code is
> below.
>
>
> ## Original Code
> library(maptools)
> library(rgdal)
> library(rgeos)
> file3 <- "C:/Desktop/MUNICIPIOS"
> vM.spdf <- readShapePoly(file3, IDvar=NULL)
> class(vM.spdf)
>                # SpatialPolygonsDataFrame
> vM.spdf@data[which(vM.spdf@data$CVE_ENT=="09"),]
> v.id <- vM.spdf@data$CVE_ENT=="09"                               # IDs
> which rows to merge
> newM <- unionSpatialPolygons(vM.sp, IDs=v.id)                  # merge
>
> # Returns the error:
> # Error in TopologyFunc(groupID(spgeom[ids[[i]]], id[ids[[i]]]),
> names(ids)[i],  :
> # TopologyException: found non-noded intersection between LINESTRING
> (3.47895e+006 551354,
> # 3.479e+006 551323) and LINESTRING (3.479e+006 551323, 3.479e+006
> 551364) at 3.479e+006 551323
>
> ## Trying checkPolygonsHoles()
> checkPolygonsHoles(vM.spdf)                                        #
> Error ... not a Polygons object
> vM.sp <- SpatialPolygons(vM.spdf@polygons, vM.spdf@plotOrder,
> proj4string=vM.spdf@proj4string)
> vM.p   <- Polygons(vM.sp)
> # Error in as.list.default(X) : no method for coercing this S4 class
> to a vector
> vM.p  <- Polygons(list(vM.sp))
> vM.p <- Polygons(vM.sp@polygons)                             # Error
> in Polygons(list(vM.sp)) : srl not a list of Polygon objects
>
> ## Trying to reset sig difs
> getScale()
>                   # returns '1e+08'
> setScale(1e+09)
> newM <- unionSpatialPolygons(vM.sp, IDs=v.id)                  # same
> error
>
>
>
> Thanks for any help you can give me.
>
> Brigitte
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

