[R-sig-Geo] Problem aggregating municipalities

Roger Bivand Roger.Bivand at nhh.no
Mon Oct 1 14:16:01 CEST 2012


On Mon, 1 Oct 2012, Mathieu Rajerison wrote:

> 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.
>

I'm afraid that this is a case in which the individual geometries may be 
valid, but that they overlap - see the recent thread:

https://stat.ethz.ch/pipermail/r-sig-geo/2012-September/016134.html

In that case Mao-Gui Hu attached a small data excerpt which helped in 
analysis of the problem, perhaps you could do the same? If the excerpt is 
larger than 20Kb, please put it on a website, to avoid distributing it to 
all of the list's subscribers needlessly. Downloading the full 40Mb you 
reference is too large anyway. You could try to identify offending 
geometries using gOverlaps().

Roger

>
> 2012/9/30 Brigitte Hogan <brigittehogan at 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 at data[which(vM.spdf at data$CVE_ENT=="09"),]
>> v.id <- vM.spdf at 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 at polygons, vM.spdf at plotOrder,
>> proj4string=vM.spdf at 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 at 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 at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> 	[[alternative HTML version deleted]]
>
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list