uk_census_shapes_clipped/script.R

47 lines
2.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
# Create modest buffer around quite small building polygons for the sake of visualisation at very large scale where small polygons can appear as points
buffer <- st_buffer(buildings,150)
# Dissolve and merge overlapping shapes
union <- st_union(buffer)
# Generate a masking layer, with filled space for unoccupied layers
difference <- st_difference(local_authorities$geom, union)
# Write results to a file:
st_write(difference, "data/local_authorities_cropped_union_buffer_150.gpkg")
# Invert polygons in this new layer
inversion <- st_difference(local_authorities$geom, difference)
# Write results to a file:
st_write(inversion, "data/local_authorities_cropped_union_buffer_150_inverted.gpkg")
2022-03-21 18:51:18 +00:00
# Create simplified version:
inversion_simplified = st_simplify(inversion, dTolerance = 150) # 150 m
st_write(inversion_simplified, "data/local_authorities_cropped_union_buffer_150_inverted_simplified.gpkg")
2022-03-21 17:19:03 +00:00
# Create modest buffer around quite small building polygons for the sake of visualisation at very large scale where small polygons can appear as points
buffer <- st_buffer(buildings,150)
# Dissolve and merge overlapping shapes
union <- st_union(buffer)
# Generate a masking layer, with filled space for unoccupied layers
difference <- st_difference(countries$geom, union)
# Write results to a file:
st_write(difference, "data/countries_cropped_union_buffer_150.gpkg")
# Invert polygons in this new layer
inversion <- st_difference(countries$geom, difference)
# Write results to a file:
st_write(inversion, "data/countries_cropped_union_buffer_150_inverted.gpkg")
2022-03-21 18:51:18 +00:00
# Create simplified version:
inversion_simplified = st_simplify(inversion, dTolerance = 150) # 2000 m
st_write(inversion_simplified, "data/countries_cropped_union_buffer_150_inverted_simplified.gpkg")