[R-sig-Geo] UnionSpatialPolygons in the German DEU_adm3.RData file
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Mon Jan 31 09:17:25 CET 2011
On Sun, Jan 30, 2011 at 11:26 PM, DPajak <pajak at europa-uni.de> wrote:
>
> Hello,
>
> actually I started to learn how to produce a choropleth map today. So
> hopefully somebody can help me?
>
> I want to use the GADM data file for Germany (DEU_adm3.RData) along with
> some data from my dissertation in business studies. So far so good. Since
> there are some good examples out there it was easy to merge those two files.
>
> The problem I have is due to some local government reorganizations (e.g. the
> Kreisgebietsreform 2008 in Saxony).
>
> So I have to merge some district in the DEU_adm3.RData file.
>
> I learnt today, that the "UnionSpatialPolygons" of the GPC library can do
> that.
>
> So I tried to figured out, how to use this function. Here is what I have so
> far:
>
> ---
> library(sp)
> library(maptools)
> library(gpclib) #
> http://en.wikipedia.org/wiki/GPC_General_Polygon_Clipper_Library
> gpclibPermit()
> Germany <-load("./Dropbox/Projekte/Spatial Map/DEU_adm3.RData")
>
> write.csv(gadm, "gadm-data.csv")
>
> # ID_3 for the three former districts Döbeln (23204), Freiberg (23185) &
> Mittweida (23187)
>
> Merge_Mittelsachsen <- gadm[gadm$ID_3 %in% c("23185","23187","23204"),]
> ID <- rep("Mittelsachsen", length(slot(Merge_Mittelsachsen, "polygons")))
> Mittelsachsen <- unionSpatialPolygons(Merge_Mittelsachsen, ID)
> plot(Mittelsachsen)
> ---
>
> This works perfectly to plot the new district of Mittelsachsen
> (Middle-Saxony).
>
> But how can I combine this new merged district with the rest of the German
> map? Or in others words, how can I overwrite the former three separated
> districts with my new "Mittelsachsen" polygon.
>
> Thank you very much for any hints you can give me.
Sometimes things are easier to do in something other than R (although
this is the point where Roger sends in a two-line R snippet to do
this).
I'd fire up my favourite Free Open Source GIS package, Quantum GIS,
load the shapefile vector, enable editing, select the polygons, hit
the merge button, choose which of the original polygons attributes to
include (or construct new ones, such as summing the population of the
original three), save, and job done. Load it into R for your stats.
www.qgis.org
Barry
More information about the R-sig-Geo
mailing list