Exocom
Exocom

Reputation: 791

Merging (two and a half) countries from maps-package to one map object in R

I am looking for a map that combines Germany, Austria and parts of Switzerland together to one spatial object. This area should represent the German speaking areas in those three countries. I have some parts in place, but can not find a way to combine them. If there is a completely different solution to solve this problem, I am still interested.

I get the German and the Austrian map by:

require(maps)
germany <- map("world",regions="Germany",fill=TRUE,col="white") #get the map
austria <- map("world",regions="Austria",fill=TRUE,col="white") #get the map

Switzerland is more complicated, as I only need the 60-70% percent which mainly speak German. The cantones that do so (taken from the census report) are

cantonesGerman = c("Uri", "Appenzell Innerrhoden", "Nidwalden", "Obwalden", "Appenzell Ausserrhoden", "Schwyz", "Lucerne", "Thurgau", "Solothurn", "Sankt Gallen", "Schaffhausen", "Basel-Landschaft", "Aargau", "Glarus", "Zug", "Zürich", "Basel-Stadt")

The cantone names can used together with data from gadm.org/country (selecting Switzerland & SpatialPolygonsDataFrame -> Level 1 or via the direct link) to get the German-speaking areas from the gadm-object:

gadmCH = readRDS("~/tmp/CHE_adm1.rds")

dataGermanSwiss <- gadmCH[gadmCH$NAME_1 %in% cantonesGerman,]

I am now missing the merging step to get this information together. The result should look like this:

Result It represents a combined map consisting of the contours of the merged area (Germany + Austria + ~70% of Switzerland), without borders between the countries. If adding and leaving out the inter-country borders would be parametrizable, that would be great but not a must have.

Upvotes: 0

Views: 1535

Answers (1)

Robert Hijmans
Robert Hijmans

Reputation: 47016

You can that like this:

Get the polygons you need

library(raster)
deu <- getData('GADM', country='DEU', level=0)
aut <- getData('GADM', country='AUT', level=0)
swi <- getData('GADM', country='CHE', level=1)

Subset the Swiss cantons (here an example list, not the correct one); there is no need for a loop for such things in R.

cantone <- c('Aargau', 'Appenzell Ausserrhoden', 'Appenzell Innerrhoden', 'Basel-Landschaft', 'Basel-Stadt', 'Sankt Gallen', 'Schaffhausen', 'Solothurn', 'Thurgau', 'Zürich')
GermanSwiss <- swi[swi$NAME_1 %in% cantone,]

Aggregate (dissolve) Swiss internal boundaries

GermanSwiss <- aggregate(GermanSwiss)

Combine the three countries and aggregate

german <- bind(deu, aut, GermanSwiss)
german <- aggregate(german)

Upvotes: 2

Related Questions