Skip to content

Instantly share code, notes, and snippets.

@daranzolin
Created December 20, 2024 17:20
Show Gist options
  • Save daranzolin/8bb4f51d0d5f430c2adc823f1dfe5982 to your computer and use it in GitHub Desktop.
Save daranzolin/8bb4f51d0d5f430c2adc823f1dfe5982 to your computer and use it in GitHub Desktop.
Gist to calculate the areas of SF CBDs, commercial land use, and total parcel area
library(sf)
library(mapview)
library(tidyverse)
library(measurements)
library(units)
library(glue)
# Dissolve and summarize CBD parcel areas
cbd_parcels <- st_read("data/cbd_parcels.shp")
cbds_area <- cbd_parcels %>%
group_by() %>%
summarize() %>%
mutate(area = st_area(.)) %>%
pull()
# Convert to square miles, already in square meter units
units(cbds_area) = "mi2"
# Get land use from DataSF
# Note: "The commercial data was not updated; the commercial data will be updated in next year's 2024 release."
# Cf. https://sfplanninggis.s3.amazonaws.com/LUDB_2023_Summary.pdf
sf_landuse <- st_read("https://data.sfgov.org/resource/fdfd-xptc.geojson?$limit=9999999")
# totalcomm = Total Commercial Only Sq Ft
# Cf. https://data.sfgov.org/Geographic-Locations-and-Boundaries/San-Francisco-Land-Use-2023/fdfd-xptc/about_data
comm_area <- sf_landuse %>%
st_drop_geometry() %>%
summarize(comm_area = sum(as.numeric(totalcomm))) %>%
pull()
# Convert from square feet to square miles
units(comm_area) <- as_units("ft2")
units(comm_area) = "mi2"
# SF area
# doesn't include area of the streets
sf_area <- sf_landuse %>%
st_transform(7131) %>%
group_by() %>%
summarize() %>%
mutate(area = st_area(.)) %>%
pull()
# convert to square miles, already in square meter units
units(sf_area) = "mi2"
# Statements
glue("CBDs in San Francisco cover {scales::percent(as.numeric(cbds_area/comm_area), accuracy = 0.1)} of all commercially zoned land in the city.")
# CBDs in San Francisco cover 15.2% of all commercially zoned land in the city.
glue("CBDs cover {scales::percent(as.numeric(cbds_area/sf_area), accuracy = 0.1)} of San Francisco.")
# CBDs cover 4.5% of San Francisco.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment