Commit 2f02c938 authored by Hopf, Konstantin's avatar Hopf, Konstantin
Browse files

Scripts and data for L05

parent 83aaed97
---
title: "Practical tasks working with geographic and time-related data (EESYS-BIA-M, L05)"
output: html_notebook
editor_options:
chunk_output_type: inline
---
# Practicals for geographic data
Germany publishes geographic data as ESRI shapefiles on the Website of the [Bundesamt für Kartographie](http://www.geodatenzentrum.de/geodaten/gdz_rahmen.gdz_div?gdz_spr=deu&gdz_akt_zeile=5&gdz_anz_zeile=1&gdz_user_id=0)
For illusrration, the political borders (Verwaltungsgrenzen) are used on a scale of 1:250 000 (VG250)
There are two datasets available:
* VG250 Kompakt: contains the lines and general data (>120 MB)
* VG250 Ebenen: contains the detailed data (>70MB)
Selected layers are available in the `/data/` folder of this repository.
```{r load German political borders}
library(sp)
library(rgdal)
#read the shapefile
ger.shp <- readOGR("../data/DE_Admin_Geodata/VG250_Kompakt/", "VG250_L") #lines
#the attribute AGZ contains the type of the boundary (AGZ = 'Art der Grenze')
table(ger.shp$AGZ)
#Plot lines
plot(ger.shp[ger.shp$AGZ==1, ]) #German main border
lines(ger.shp[ger.shp$AGZ==2, ], col=2) #German state borders
lines(ger.shp[ger.shp$AGZ==3, ], col=3) #German Regierungsbezirk
lines(ger.shp[ger.shp$AGZ==4, ], col=4) #Kreise
```
```{r load German states as polygons}
#read teh shapefile
ger.shp <- readOGR("../data/DE_Admin_Geodata/VG250_Ebenen/", "VG250_LAN")
#basic plot of the data - looks similar to previous plot
plot(ger.shp)
#Here, we have polygons that we can colorate
plot(ger.shp, col=1:23)
ger.shp@data
?plot.sp
proj4string(ger.shp)
head(ger.shp@)
plot(ger.shp, axit="t")
```
As an example, the housing statistics from the German Federal Ministry of Statistics is used
Wohngebäude, Wohnungen, Wohnfläche: Bundesländer, Stichtag, Anzahl der Wohnungen
By this example, the `readr` package is illustrated
```{r visualize some data}
library(readr)
housing_statistic_DE <- read_csv2("../data/housing_statistic_germany_31231-0003.csv",
col_types = cols(
date = col_number(),
state = col_character(),
`1_app_buildings` = col_integer(),
`1_app_dwellings` = col_integer(),
`1_app_livingareas` = col_integer(),
`2_app_buildings` = col_integer(),
`2_app_dwellings` = col_integer(),
`2_app_livingareas` = col_integer(),
`3_more_app_buildings` = col_integer(),
`3_more_app_dwellings` = col_integer(),
`3_more_app_livingarea` = col_integer(),
dormitory_buildings = col_integer(),
dormitory_dwellings = col_integer(),
dormitory_livingarea = col_integer(),
total_buildings = col_integer(),
total_dwellings = col_integer(),
total_livingarea = col_integer()
),
col_names = c("date", "state",
"1_app_buildings", "1_app_dwellings", "1_app_livingareas",
"2_app_buildings", "2_app_dwellings", "2_app_livingareas",
"3_more_app_buildings", "3_more_app_dwellings", "3_more_app_livingarea",
"dormitory_buildings", "dormitory_dwellings", "dormitory_livingarea",
"total_buildings", "total_dwellings", "total_livingarea"),
skip = 8, n_max = 16, locale = locale(date_names = "de",
encoding = "latin1",
decimal_mark = ",",
grouping_mark = "."))
#calculate the relative distribution of total living area
housing_statistic_DE$total_livingarea_rel <- housing_statistic_DE$total_livingarea / max(housing_statistic_DE$total_livingarea)
#the HSV function definex colors by means of hue, saturation and darkness value
color_grades <- hsv(h=0.6, s=housing_statistic_DE$total_livingarea_rel, v = 1)
pos_states_map_statistics <- match(ger.shp$GEN, housing_statistic_DE$state)
plot(ger.shp, col=color_grades[pos_states_map_statistics],
main="Total living space area in the German states")
axis(1)
axis(2)
```
```{r plot coordinaes on the map}
# the WGS84 coordinates of Bamberg are
bamberg <- SpatialPoints(list(x=10.891667, y=49.891667))
# transform the german UTM coordinates to WGS84 coordinates
ger.shp.wgs84 <- spTransform(ger.shp, CRS("+proj=longlat +datum=WGS84"))
plot(ger.shp.wgs84)
axis(1)
axis(2)
points(bamberg, col=2)
```
PROJCS["ETRS_1989_UTM_Zone_32N",GEOGCS["GCS_ETRS_1989",DATUM["D_ETRS_1989",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
\ No newline at end of file
PROJCS["ETRS_1989_UTM_Zone_32N",GEOGCS["GCS_ETRS_1989",DATUM["D_ETRS_1989",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
\ No newline at end of file
UTF-8
\ No newline at end of file
PROJCS["ETRS_1989_UTM_Zone_32N",GEOGCS["GCS_ETRS_1989",DATUM["D_ETRS_1989",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment