[R-sig-Geo] Combining polygons from a SpatialPolygonsDataFrame object
Rafael Wüest
rafael.wueest at wsl.ch
Thu Jun 14 11:16:44 CEST 2012
Hi Jesus
gUnaryUnion (or gUnionCascaded) from the rgeos package can do this.
Have a look at the examples in the function documentation ?gUnaryUnion
> library(maptools)
> nc1 <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], proj4string=CRS("+proj=longlat +datum=NAD27"))
> ID <- cut(lps[,1], quantile(lps[,1]), include.lowest=TRUE)
> reg4 <- gUnaryUnion(nc1, ID) # requires GEOS version 3.3.0
and look at
plot(reg4,lwd=2)
plot(nc1,add=T,lty=3)
If you set id to your province ID, you should get what you are looking for.
HTH,
Rafael
On 14.06.2012, at 09:45, Alonso Nanclares, Jesús Alberto wrote:
> Dear list,
>
> I have a Shapefile representing the censal sections of Spain, and my interest is creating a KML file with only 52 polygons representing the different provinces of Spain. I shall use readOGR, and my problem comes when I have a SpatialPolygonsDataFrame object in R and I want to merge in only one polygon all the censal sections of every province. I have an attribute with the province ID defined in the same object, so it would only be aggregating the censal sections with the same province ID, but still I don’t know how to do it.
>
> I shall be grateful for any help. My kind regards,
>
> Jesús Alberto Alonso Nanclares
> Consultor Junior
> Centro de Competencias Business Analytics
>
> Avda de Bruselas, 35
> 28108 Alcobendas (Madrid)
> España
>
> T +34 914 805 863
> jaalonson at indra.es
> www.indracompany.com
>
> <image001.jpg>
>
>
> Este correo electrónico y, en su caso, cualquier fichero anexo al mismo, contiene información de carácter confidencial exclusivamente dirigida a su destinatario o destinatarios. Si no es vd. el destinatario indicado, queda notificado que la lectura, utilización, divulgación y/o copia sin autorización está prohibida en virtud de la legislación vigente. En el caso de haber recibido este correo electrónico por error, se ruega notificar inmediatamente esta circunstancia mediante reenvío a la dirección electrónica del remitente.
> Evite imprimir este mensaje si no es estrictamente necesario.
>
> This email and any file attached to it (when applicable) contain(s) confidential information that is exclusively addressed to its recipient(s). If you are not the indicated recipient, you are informed that reading, using, disseminating and/or copying it without authorisation is forbidden in accordance with the legislation in effect. If you have received this email by mistake, please immediately notify the sender of the situation by resending it to their email address.
> Avoid printing this message if it is not absolutely necessary.
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Rafael Wüest
Swiss Federal Research Institute WSL
Zürcherstrasse 111
8903 Birmensdorf
Switzerland
+41 44 7392126
rafael.wueest at wsl.ch
http://www.wsl.ch/info/mitarbeitende/wueest
More information about the R-sig-Geo
mailing list