Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
saschagobel committed Jun 21, 2021
1 parent 8a43450 commit a9f484a
Show file tree
Hide file tree
Showing 5 changed files with 866 additions and 59 deletions.
45 changes: 36 additions & 9 deletions code/data.R → code/01-data.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
# ---------------------------------------------------------------------------------------
# DEGURBA POSTCODE AREAS
# Sascha Göbel
# Script for packages
# Sascha Goebel
# Script for downloading and processing data
# June 2021
# ---------------------------------------------------------------------------------------


# imports -------------------------------------------------------------------------------
cat(underline("IMPORTS"),"
''
# downloads and imports -----------------------------------------------------------------
cat(underline("DOWNLOADS AND IMPORTS"),"
'./data/cntr_polygons/NUTS_RG_01M_2021_3035_LEVL_0.shp'
'./data/pop_grid/JRC_1K_POP_2018.tif'
'./data/fua_polygons/URAU_RG_01M_2018_3035_FUA.shp'
'./data/postcode_areas/PLZO_PLZ.shp'
'./data/postcode_areas/OSM_PLZ_072019.shp'
'./data/postcode_areas/codigos_postales.shp'
'./data/postcode_areas/codes_postaux_region.shp'
'./data/postcode_areas/Sectors.shp'
")

# exports -------------------------------------------------------------------------------
cat(underline("EXPORTS"),"
''
'./data/cntr_polygons/ch_cntr_polygon.shp'
'./data/cntr_polygons/de_cntr_polygon.shp'
'./data/cntr_polygons/es_cntr_polygon.shp'
'./data/cntr_polygons/fr_cntr_polygon.shp'
'./data/cntr_polygons/uk_cntr_polygon.shp'
'./data/pop_grid/ch_pop_grid.tif'
'./data/pop_grid/de_pop_grid.tif'
'./data/pop_grid/es_pop_grid.tif'
'./data/pop_grid/fr_pop_grid.tif'
'./data/pop_grid/uk_pop_grid.tif'
'./data/fua_polygons/ch_fua_polygons.shp'
'./data/fua_polygons/de_fua_polygons.shp'
'./data/fua_polygons/es_fua_polygons.shp'
'./data/fua_polygons/fr_fua_polygons.shp'
'./data/fua_polygons/uk_fua_polygons.shp'
'./data/postcode_areas/ch_postcode_polygons.shp'
'./data/postcode_areas/de_postcode_polygons.shp'
'./data/postcode_areas/es_postcode_polygons.shp'
'./data/postcode_areas/fr_postcode_polygons.shp'
'./data/postcode_areas/uk_postcode_polygons.shp'
")

# content -------------------------------------------------------------------------------
cat(underline("CONTENT"),"
DOWNLOAD POPULATION GRID, BOUNDARY, FUNCTIONAL URBAN AREA, AND POSTCODE DATA
PROCESS BOUNDARY, POPULATION GRID, FUNCTIONAL URBAN AREA, AND POSTCODE DATA
Line 53 - PREPARATIONS
Line 73 - DOWNLOAD POPULATION GRID, BOUNDARY, FUNCTIONAL URBAN AREA, AND POSTCODE DATA
Line 189 - PROCESS BOUNDARY, POPULATION GRID, FUNCTIONAL URBAN AREA, AND POSTCODE DATA
")


Expand All @@ -29,7 +56,7 @@ cat(underline("CONTENT"),"
rm(list=ls(all=TRUE))

# set working directory -----------------------------------------------------------------
setwd("D://projects/rude/")
setwd("degurba-postcode-areas")

# install and load packages -------------------------------------------------------------
source("./code/packages.R")
Expand Down
59 changes: 29 additions & 30 deletions code/degurba.R → code/02-degurba.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
# ---------------------------------------------------------------------------------------
# DEGURBA POSTCODE AREAS
# Sascha Göbel
# Sascha Goebel
# Script for applying degurba to grid cells and postcode areas
# June 2021
# ---------------------------------------------------------------------------------------


# imports -------------------------------------------------------------------------------
cat(underline("IMPORTS"),"
''
'./data/pop_grid/ch_pop_grid.tif'
'./data/pop_grid/de_pop_grid.tif'
'./data/pop_grid/es_pop_grid.tif'
'./data/pop_grid/fr_pop_grid.tif'
'./data/pop_grid/uk_pop_grid.tif'
'./data/fua_polygons/ch_fua_polygons.shp'
'./data/fua_polygons/de_fua_polygons.shp'
'./data/fua_polygons/es_fua_polygons.shp'
'./data/fua_polygons/fr_fua_polygons.shp'
'./data/fua_polygons/uk_fua_polygons.shp'
'./data/postcode_areas/ch_postcode_polygons.shp'
'./data/postcode_areas/de_postcode_polygons.shp'
'./data/postcode_areas/es_postcode_polygons.shp'
'./data/postcode_areas/fr_postcode_polygons.shp'
'./data/postcode_areas/uk_postcode_polygons.shp'
")

# exports -------------------------------------------------------------------------------
cat(underline("EXPORTS"),"
''
'./data/grid_classifications'
'./data/postcode_classifications'
'./data/postcode_degurba_lists/ch_postcode_degurba'
'./data/postcode_degurba_lists/de_postcode_degurba'
'./data/postcode_degurba_lists/es_postcode_degurba'
'./data/postcode_degurba_lists/fr_postcode_degurba'
'./data/postcode_degurba_lists/uk_postcode_degurba'
")

# content -------------------------------------------------------------------------------
cat(underline("CONTENT"),"
PREPARATIONS
CLASSIFY GRID CELLS
CLASSIFY POSTCODE AREAS
Line 47 - PREPARATIONS
Line 60 - CLASSIFY GRID CELLS
Line 88 - CLASSIFY POSTCODE AREAS
")


Expand All @@ -30,14 +50,13 @@ cat(underline("CONTENT"),"
rm(list=ls(all=TRUE))

# set working directory -----------------------------------------------------------------
setwd("D://projects/rude/")
setwd("degurba-postcode-areas")

# install and load packages -------------------------------------------------------------
source("./code/packages.R")
source("./code/functions.R")



#### CLASSIFY GRID CELLS ================================================================

# import country-specific population grids ----------------------------------------------
Expand All @@ -63,17 +82,7 @@ grid_classifications <- grid_classifications %>%
purrr::map2(.x = grid_classifications, .f = raster::addLayer)

# save grid classifications -------------------------------------------------------------
path <- file.path("./data","grid_classifications")
if (!dir.exists(path)) {
path %>%
dir.create(recursive = TRUE)
}
file_names <- paste0(c("ch", "de", "es", "fr", "uk"), "_grid_classifications.grd")
if (any(!file.exists(paste0(path, "/", file_names)))) {
grid_classifications %>%
purrr::map2(.y = paste0(path, "/", file_names),
.f = raster::writeRaster)
}
saveRDS(grid_classifications, "./data/grid_classifications")


#### CLASSIFY POSTCODE AREAS ============================================================
Expand All @@ -92,17 +101,7 @@ postcode_classifications <- grid_classifications %>%
purrr::map2(.y = postcode_polygons, .f = cbind)

# save postcode classifications ---------------------------------------------------------
path <- file.path("./data","postcode_classifications")
if (!dir.exists(path)) {
path %>%
dir.create(recursive = TRUE)
}
file_names <- paste0(c("ch", "de", "es", "fr", "uk"), "_postcode_classifications")
if (any(!file.exists(paste0(path, "/", file_names)))) {
postcode_classifications %>%
purrr::map2(.y = paste0(path, "/", file_names),
.f = saveRDS)
}
saveRDS(postcode_classifications, "./data/postcode_classifications")

# extract classified postcode lists -----------------------------------------------------
ch_postcode_degurba <- postcode_classifications[[1]] %>%
Expand Down
Loading

0 comments on commit a9f484a

Please sign in to comment.