-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcatenateBuildingFunctions.Rmd
102 lines (79 loc) · 4.29 KB
/
concatenateBuildingFunctions.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
title: "Concatenate Building Functions"
author: "David Swinkels"
date: "October 6, 2017"
github: "David Swinkels"
purpose: "Part of MSc thesis Geo-Information Science at Wageningen University"
status: "Production"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
options(scipen=999)
```
```{r read}
## Read buildings data
buildings <- read.csv2(file = "D:/Workspace/ExtraData/AddressBuildingAmsterdam.csv", sep = ",")
## Check buildings data
# str(Buildings)
# dim(Buildings)
# head(Buildings)
# as.numeric(levels(Buildings$BuildingID))[Buildings$BuildingID]
# head(Buildings)
# tail(Buildings)
```
```{r concatenateFunctions1}
## Aggregate building data excluding cell function
## Aggregrate building data
buildings_aggr_clean <- aggregate(Gebruiksdo ~ BuildingID, data = Buildings, paste, collapse = ",")
## Check aggregated buildings
str(buildings_aggr_clean)
names <- c("Residential", "Meeting", "Healthcare", "Industry", "Office", "Accommodation", "Education", "Sport", "Shop", "Other")
## For every column in names set all values in rows to zero
for (name in names){
buildings_aggr_clean[,name] <- 0
}
## Make index in column where specific function is found and set value in that column at that index to 1
buildings_aggr_clean$Residential[(grepl("woonfunctie", buildings_aggr_clean$Gebruiksdo))] <- 1
buildings_aggr_clean$Meeting[(grepl("bijeenkomstfunctie", buildings_aggr_clean$Gebruiksdo))] <- 1
buildings_aggr_clean$Healthcare[(grepl("gezondheidszorgfunctie", buildings_aggr_clean$Gebruiksdo))] <- 1
buildings_aggr_clean$Industry[(grepl("industriefunctie", buildings_aggr_clean$Gebruiksdo))] <- 1
buildings_aggr_clean$Office[(grepl("kantoorfunctie", buildings_aggr_clean$Gebruiksdo))] <- 1
buildings_aggr_clean$Accommodation[(grepl("logiesfunctie", buildings_aggr_clean$Gebruiksdo))] <- 1
buildings_aggr_clean$Education[(grepl("onderwijsfunctie", buildings_aggr_clean$Gebruiksdo))] <- 1
buildings_aggr_clean$Sport[(grepl("sportfunctie", buildings_aggr_clean$Gebruiksdo))] <- 1
buildings_aggr_clean$Shop[(grepl("winkelfunctie", buildings_aggr_clean$Gebruiksdo))] <- 1
buildings_aggr_clean$Other[(grepl("overige gebruiksfunctie", buildings_aggr_clean$Gebruiksdo))] <- 1
## Save BuildingID as text, because number is not correctly stored in excel if stored as a number
buildings_aggr_clean$BuildingID <- as.character(buildings_aggr_clean$BuildingID)
## Write data to .csv
write.csv(buildings_aggr_clean, file = "D:/Workspace/ExtraData/AddressBuildingAmsterdamConcatenatedAdjLandUse.csv")
```
```{r concatenateFunctions2}
## Aggregate building data including cell function
## Aggregrate building data
buildings_aggr <- aggregate(Gebruiksdo ~ BuildingID, data = buildings, paste, collapse = ",")
## Check aggregated buildings
str(buildings_aggr)
names <- c("Residential", "Meeting", "Cell", "Healthcare", "Industry", "Office", "Accommodation", "Education", "Sport", "Shop", "Other")
## For every column in names set all values in rows to zero
for (name in names){
buildings_aggr[,name] <- 0
}
## Make index in column where specific function is found and set value in that column at that index to 1
buildings_aggr$Residential[(grepl("woonfunctie", buildings_aggr$Gebruiksdo))] <- 1
buildings_aggr$Meeting[(grepl("bijeenkomstfunctie", buildings_aggr$Gebruiksdo))] <- 1
buildings_aggr$Cell[(grepl("celfunctie", buildings_aggr$Gebruiksdo))] <- 1
buildings_aggr$Healthcare[(grepl("gezondheidszorgfunctie", buildings_aggr$Gebruiksdo))] <- 1
buildings_aggr$Industry[(grepl("industriefunctie", buildings_aggr$Gebruiksdo))] <- 1
buildings_aggr$Office[(grepl("kantoorfunctie", buildings_aggr$Gebruiksdo))] <- 1
buildings_aggr$Accommodation[(grepl("logiesfunctie", buildings_aggr$Gebruiksdo))] <- 1
buildings_aggr$Education[(grepl("onderwijsfunctie", buildings_aggr$Gebruiksdo))] <- 1
buildings_aggr$Sport[(grepl("sportfunctie", buildings_aggr$Gebruiksdo))] <- 1
buildings_aggr$Shop[(grepl("winkelfunctie", buildings_aggr$Gebruiksdo))] <- 1
buildings_aggr$Other[(grepl("overige gebruiksfunctie", buildings_aggr$Gebruiksdo))] <- 1
## Save BuildingID as text, because number is not correctly stored in excel if stored as a number
buildings_aggr$BuildingID <- as.character(buildings_aggr$BuildingID)
## Write data to .csv
write.csv(buildings_aggr, file = "D:/Workspace/ExtraData/AddressBuildingAmsterdamConcatenated.csv")
```