-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
208 lines (156 loc) · 7.87 KB
/
README.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
---
title: CatastroDownloader 0.1.1
date: "`r Sys.Date()`"
subtitle: Tool to download updated Spanish Catastro clean and single file
tags: [R,Catastro,sf, mapview, html, maps]
output: github_document
always_allow_html: yes
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
out.width = "100%"
)
```
# Description
The goal of this library is to download the complete updated Catastro layers
for a Province of Spain. Main benefits:
- Can be parallelized to download several Provinces at once. Moreover, it can be
configured to receive a mobile notification when finished.
- It merges all the municipalities in one file while keeping the minicipality name
as an attribute in order to use it as filter later on.
- It creates a single file in .gpkg format where 3 layers are stored:
- buildings
- buildingparts
- otherconstructions
- It stimates the building height for eacch of the polygons (given a height of floor above the ground).
# Installation
This packages has been tested in:
- Ubuntu 20.04 with R 4.0.3
- Windows 10 with R 4.0 + Rtools40
- macOS 10.15.7, R 4.0.3 y Rstudio 1.4
Install dependencies (libraries) in R:
```{r eval = FALSE, echo=TRUE}
# install libraries to install packages from github
install.packages("devtools"); library(devtools)
install_github("cesarkero/CatastroDownloader")
```
# Before try out
Please, use this library using your brain. Download just what you need and avoid constant masive downloads
as it will produce overload in public servers and this can lead to restrictions for the general public. So please, be kind with the service and let us all enjoy this data. For sure, don't try parallel for masive downloads until you have checked that this is a useful tool to you.
Moreover, if you just need catastro for a single or a few municipalities, just use the QGIS compelemnt [Spanish Inspire Catastral Downloader](https://github.com/sigdeletras/Spanish_Inspire_Catastral_Downloader).
[](https://github.com/sigdeletras/Spanish_Inspire_Catastral_Downloader)
Enjoy.
---
# Examples
## Single Province download
Get the list of available Provinces in the Catastro atom service:
```{r eval = FALSE, echo=TRUE}
library(CatastroDownloader)
# set parameters
catastropush <- "http://www.catastro.minhap.es/INSPIRE/buildings/ES.SDGC.bu.atom.xml"
# Catch Provinces Names in atom service
FeedProvinces(catastropush)
```
This is the list of provinces at `r Sys.Date()`:
[1] "Albacete" "Alicante" "Almería" "Avila" "Badajoz" "Baleares" "Barcelona" "Burgos" "Cáceres" "Cádiz"
[11] "Castellón" "Ciudad Real" "Córdoba" "Coruña" "Cuenca" "Girona" "Granada" "Guadalajara" "Huelva" "Huesca"
[21] "Jaén" "León" "Lleida" "La Rioja" "Lugo" "Madrid" "Málaga" "Murcia" "Ourense" "Oviedo"
[31] "Palencia" "Palmas (Las)" "Pontevedra" "Salamanca" "S.C. Tenerife" "Cantabria" "Segovia" "Sevilla" "Soria" "Tarragona"
[41] "Teruel" "Toledo" "Valencia" "Valladolid" "Zamora" "Zaragoza" "Cartagena" "Gijon" "Jerez Frontera" "Vigo"
[51] "Ceuta" "Melilla"
If you just need to download the catastro for a single Province use this:
```{r eval = FALSE, echo=TRUE}
# Set parameters
catastropush <- "http://www.catastro.minhap.es/INSPIRE/buildings/ES.SDGC.bu.atom.xml" #url for the atom service
output <- "../00_Output/" #where the .gpkg file will be stored
tempdir <- "./temp/" #careful as all files inside will be removed
rpush = TRUE #if you want a notification when finished (RPushbullet must be configured before)
overwrite = TRUE #overwrite .gpkg if exists
Hfloor = 3 #set desired height for each floor above the ground
catastroprovince('Melilla', catastropush, tempdir, output, rpush = TRUE, overwrite = FALSE, Hfloor = 3)
```
```{r echo = FALSE, fig.cap="Screenshots of generated files (.gpkg) for several excutions", out.width = '100%', fig.align="center"}
knitr::include_graphics("./man/figures/I01.png")
```
To show some data within R
```{r eval = FALSE, echo=TRUE}
# show some data
file <- paste0(output, 'Catastro_Ceuta_2021-01-26.gpkg')
layer <- st_read(file, 'buildingpart')
mapview(layer)
```
```{r echo = FALSE, fig.cap="Some example of buildingparts", out.width = '100%', fig.align="center"}
knitr::include_graphics("./man/figures/I06.png")
```
## Parallel process for several Provinces
Parallel process allows to download a list of desired Provinces with just one execution of the code.
Must be taken into acount that there are slight differences between the process within Linux and Windows.
### Parallel process for LINUX
```{r eval = FALSE, echo=TRUE}
# Set parameters
catastropush <- "http://www.catastro.minhap.es/INSPIRE/buildings/ES.SDGC.bu.atom.xml" #url for the atom service
output <- "../00_Output/" #where the .gpkg file will be stored
tempdir <- "./temp/" #careful as all files inside will be removed
rpush = TRUE #if you want a notification when finished (RPushbullet must be configured before)
overwrite = TRUE #overwrite .gpkg if exists
ncores = 16 #specify number of cores dedicated
Hfloor = 3 #set desired height for each floor above the ground
# Set list of provinces to download
provinceslist <- c("Zamora", "Vigo")
# Set parallel
cl <- parallel::makeCluster(ncores, type="FORK")
doParallel::registerDoParallel(cl)
# Execute function
foreach(i=provinceslist) %dopar% {catastroprovince(i,catastropush, tempdir, output, rpush, overwrite, Hfloor)}
# Stop parallel
stopCluster(cl)
```
### Parallel process for WINDOWS
```{r eval = FALSE, echo=TRUE}
# Set parameters
catastropush <- "http://www.catastro.minhap.es/INSPIRE/buildings/ES.SDGC.bu.atom.xml" #url for the atom service
output <- "../00_Output/" #where the .gpkg file will be stored
tempdir <- "./temp/" #careful as all files inside will be removed
rpush = TRUE #if you want a notification when finished (RPushbullet must be configured before)
overwrite = TRUE #overwrite .gpkg if exists
ncores = 16 #specify number of cores dedicated
Hfloor = 3 #set desired height for each floor above the ground
# Set list of provinces to download
provinceslist <- c("Zamora", "Vigo")
# Set parallel
cl <- parallel::makeCluster(ncores, type="PSOCK")
doParallel::registerDoParallel(cl)
clusterEvalQ(cl, library("CatastroDownloader")) # load libraries
clusterExport(cl, c('catastropush', 'output', 'tempdir', 'ncores'))
# Execute function
foreach(i=provinceslist) %dopar% {catastroprovince(i,catastropush, tempdir, output, rpush, overwrite, Hfloor)}
# Stop parallel
stopCluster(cl)
```
## Screenshots of the results
#### Notification
If you have previously configured [rpushbullet](https://github.com/eddelbuettel/rpushbullet)
you will get a notification in your devices when the process in completed.
<p align="center">
<img width="300" src="./man/figures/I08.png">
</p>
#### Screenshot of Ceuta
<p align="center">
<img width="800" src="./man/figures/I05.png">
</p>
#### Detail of Ceuta
<p align="center">
<img width="800" src="./man/figures/I04.png">
</p>
#### Screenshot of Orense (somewhere)
<p align="center">
<img width="800" src="./man/figures/I03.png">
</p>
# Notes for the future:
- May be a shiny app could be created (even using a selection with cursor both for Provinces and Municipalities)
- Need of improvement in speed of execution (the most time consuming task is merging all the municipalities layers into one...) May be it could be parallelized internaly ? What would happend when the parallel process is also "outside"?
- May be it is interesting to specified the desired CRS for the output.
---
# Corrections:
- When a province contains municipalities with different CRS's, all the layers will be transformed into the most common CRS.