more coherent variable names

This commit is contained in:
Jeremy Kidwell 2022-03-31 10:59:31 +01:00
parent 3b48a6639e
commit 3180a86ee7

101
script.R
View file

@ -12,35 +12,84 @@ buildings <- st_read("./data/OS_Open_Zoomstack_district_buildings.gpkg")
# open country shapefiles
countries <- st_read("data/infuse_ctry_2011.shp")
# 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")
# 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")
# 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")
# 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)
# 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))
# Write results to a file:
st_write(difference, "data/countries_cropped_union_buffer_150.gpkg")
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")
# Invert polygons in this new layer
inversion <- st_difference(countries$geom, difference)
inversion_ctry <- st_difference(difference_ctry, countries_simplified_100m$geom)
# Write results to a file:
st_write(inversion, "data/countries_cropped_union_buffer_150_inverted.gpkg")
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")
## 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")
## Process countries shapefile -----
difference_ctry <- st_difference(countries$geom, buildings_buffer)
# Write results to a file:
st_write(difference_ctry, "data/infuse_ctry_2011_buildings_overlay.gpkg")
# Invert polygons in this new layer
inversion <- st_difference(difference_ctry, countries$geom)
# Write results to a file:
st_write(inversion, "data/infuse_ctry_2011_buildings.gpkg")
# 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")
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")