-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_celles_edificis.R
69 lines (47 loc) · 1.62 KB
/
01_celles_edificis.R
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
library(feedeR)
library(sf)
library(fs)
library(tidyverse)
library(lubridate)
library(classInt)
library(tmap)
library(rvest)
setwd("/home/marc/Documents/imatges_bcn")
# data downloaded using this method https://dominicroye.github.io/es/2019/visualizar-el-crecimiento-urbano/
url <- "http://www.catastro.minhap.es/INSPIRE/buildings/ES.SDGC.bu.atom.xml"
# importing rss
prov_enlaces <- feed.extract(url)
str(prov_enlaces) #estructura es lista
# extract table with links
prov_enlaces_tab <- as_tibble(prov_enlaces$items) %>%
mutate(title = repair_encoding(title))
# get rss url for BCN province
val_atom <- filter(prov_enlaces_tab, str_detect(title, "Barcelona")) %>% pull(link)
# import rss
val_enlaces <- feed.extract(val_atom)
# get table with links
val_enlaces_tab <- val_enlaces$items
# filter for city name
val_link <- filter(val_enlaces_tab, str_detect(title, "BARCELONA")) %>% pull(link)
val_link
# DOWNLOAD FILE
temp <- tempfile()
download.file(URLencode(val_link), temp)
unzip(temp, exdir = "buildings_bcn")
# read file
file_bcn <- dir_ls("buildings_bcn", regexp = "building.gml")
buildings <- st_read(file_bcn)
# check crs
bcn <- st_read("0301100100_UNITATS_ADM_POLIGONS.json")
bcn <- bcn |> filter(CONJ_DESCR == "Terme Municipal")
# filtrar per àrea <50 m2
buildings <- filter(buildings, as.numeric(st_area(geometry))>50)
buildings <- st_make_valid(buildings)
# unir polígons que es toquen
parts <- st_cast(st_union(buildings),"POLYGON")
parts <- st_sf(parts)
parts_f <- parts |>
rename("geometry" = "parts") |>
st_make_valid()
parts_f$uid <- seq_along(1:nrow(parts))
st_write(parts_f, "./parts_edificis.geojson")