uk_census_shapes_clipped/script.R

95 lines
5.2 KiB
R
Raw Normal View History

2022-03-21 17:19:03 +00:00
require(tidyverse)
require(sf)
# Load admin polygons:
oa11 <- st_read("./data/infuse_oa_lyr_2011.shp")
# download 2011 LSOA polygons - level 2
lsoa11 <- st_read("./data/infuse_lsoa_lyr_2011.shp")
# download local authorities data for whole UK - level 1 (least detailed)
local_authorities <- st_read("data/infuse_dist_lyr_2011.shp")
# Load buildings shapefile:
buildings <- st_read("./data/OS_Open_Zoomstack_district_buildings.gpkg")
2022-03-21 18:51:18 +00:00
# open country shapefiles
countries <- st_read("data/infuse_ctry_2011.shp")
2022-03-21 17:19:03 +00:00
2022-03-31 09:59:31 +00:00
# Generate simplified versions at 10m:
oa11_simplified_10m <- st_simplify(oa11, dTolerance = 10) # 10 m
lsoa11_simplified_10m <- st_simplify(lsoa11, dTolerance = 10) # 10 m
local_authorities_simplified_10m <- st_simplify(local_authorities, dTolerance = 10) # 10 m
countries_simplified_10m <- st_simplify(countries, dTolerance = 10) # 10 m
st_write(oa11_simplified_10m, "data/infuse_oa_lyr_2011_simplified_10m.gpkg")
st_write(lsoa11_simplified_10m, "data/infuse_lsoa_lyr_2011_simplified_10m.gpkg")
st_write(local_authorities_simplified_10m, "data/infuse_dist_lyr_2011_simplified_10m.gpkg")
st_write(countries_simplified_10m, "data/infuse_ctry_2011_simplified_10m.gpkg")
# Generate simplified versions at 100m:
oa11_simplified_100m <- st_simplify(oa11, dTolerance = 100) # 100 m
lsoa11_simplified_100m <- st_simplify(lsoa11, dTolerance = 100) # 100 m
local_authorities_simplified_100m <- st_simplify(local_authorities, dTolerance = 100) # 100 m
countries_simplified_100m <- st_simplify(countries, dTolerance = 100) # 100 m
st_write(oa11_simplified_100m, "data/infuse_oa_lyr_2011_simplified_100m.gpkg")
st_write(lsoa11_simplified_100m, "data/infuse_lsoa_lyr_2011_simplified_100m.gpkg")
st_write(local_authorities_simplified_100m, "data/infuse_dist_lyr_2011_simplified_100m.gpkg")
st_write(countries_simplified_100m, "data/infuse_ctry_2011_simplified_100m.gpkg")
## Initial work on data with buildings shapefile for large scale visualation -----
# Create modest buffer around quite small building polygons for the sake of visualisation at
# very large scale where small polygons can appear as points. Initial work in QGIS confirmed that 150m
# will render coherent shapes at national zoom level after dissolving
# Use union to dissolve and merge overlapping shapes
buildings_buffer <- st_union(st_buffer(buildings,150))
2022-03-21 17:19:03 +00:00
# Write results to a file:
2022-03-31 09:59:31 +00:00
st_write(buildings_buffer, "data/OS_Open_Zoomstack_district_buildings_buffered.gpkg")
## Process countries simplified shapefiles -----
# Generate a masking layer, based on difference between buffered buildings layer and admin shapefile
# with filled space for unoccupied layers
difference_ctry <- st_difference(countries_simplified_100m$geom, buildings_buffer)
## Write results to a file:
st_write(difference_ctry, "data/infuse_ctry_2011_simplified_100_buildings_overlay_.gpkg")
# Simplify layer
difference_ctry_simplified = st_simplify(difference_ctry, dTolerance = 100) # 100 m
st_write(difference_ctry_simplified, "data/infuse_ctry_2011_simplified_100_buildings_overlay_simplified.gpkg")
2022-03-21 17:19:03 +00:00
# Invert polygons in this new layer
2022-03-31 09:59:31 +00:00
inversion_ctry <- st_difference(difference_ctry, countries_simplified_100m$geom)
2022-03-21 17:19:03 +00:00
# Write results to a file:
2022-03-31 09:59:31 +00:00
st_write(inversion_ctry, "data/infuse_ctry_2011_simplified_100_buildings.gpkg")
inversion_ctry_simplified = st_simplify(inversion_ctry, dTolerance = 100) # 100 m
st_write(inversion_ctry_simplified, "data/infuse_ctry_2011_simplified_100_buildings_simplified.gpkg")
2022-03-21 18:51:18 +00:00
2022-03-31 09:59:31 +00:00
## Process local authorities simplified shapefiles -----
difference_la <- st_difference(local_authorities_simplified_100m$geom, buildings_buffer)
## Write results to a file:
st_write(difference_la, "data/infuse_dist_lyr_2011_simplified_100_buildings_overlay.gpkg")
# Simplify layer
difference_simplified = st_simplify(difference_la, dTolerance = 100) # 100 m
st_write(difference_simplified, "data/infuse_dist_lyr_2011_simplified_100_buildings_overlay_simplified.gpkg")
# Invert polygons in this new layer
inversion_la <- st_difference(difference_la, local_authorities_simplified_100m$geom)
# Write results to a file:
st_write(inversion_la, "data/infuse_dist_lyr_2011_simplified_100_buildings.gpkg")
inversion_simplified_la = st_simplify(inversion_la, dTolerance = 100) # 100 m
st_write(inversion_simplified_la, "data/infuse_dist_lyr_2011_simplified_100_buildings_simplified.gpkg")
2022-03-21 17:19:03 +00:00
2022-03-31 09:59:31 +00:00
## Process countries shapefile -----
difference_ctry <- st_difference(countries$geom, buildings_buffer)
2022-03-21 17:19:03 +00:00
# Write results to a file:
2022-03-31 09:59:31 +00:00
st_write(difference_ctry, "data/infuse_ctry_2011_buildings_overlay.gpkg")
2022-03-21 17:19:03 +00:00
# Invert polygons in this new layer
2022-03-31 09:59:31 +00:00
inversion <- st_difference(difference_ctry, countries$geom)
2022-03-21 17:19:03 +00:00
# Write results to a file:
2022-03-31 09:59:31 +00:00
st_write(inversion, "data/infuse_ctry_2011_buildings.gpkg")
2022-03-21 18:51:18 +00:00
# Create simplified version:
2022-03-31 09:59:31 +00:00
inversion_simplified = st_simplify(inversion, dTolerance = 100) # 100 m
st_write(inversion_simplified, "data/infuse_ctry_2011_buildings_simplified.gpkg")
## Process local authorities shapefile -----
difference_la <- st_difference(local_authorities$geom, buildings_buffer)
# Write results to a file:
st_write(difference_la, "data/infuse_dist_lyr_2011_buildings_overlay.gpkg")
# Invert polygons in this new layer
inversion_la <- st_difference(difference_la, local_authorities$geom)
# Write results to a file:
st_write(inversion_la, "data/infuse_dist_lyr_2011_buildings.gpkg")