7  Land-Use by Block

Code
import pandas as pd
from geosnap import DataStore
from geosnap.io import get_acs
from tobler.area_weighted import area_interpolate
from tobler.dasymetric import extract_raster_features
OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.
Code
%load_ext watermark
%watermark -a 'eli knaap' -u -d -iv
Author: eli knaap

Last updated: 2024-08-26

pandas: 2.2.2
Code
datasets = DataStore()
Code
dc_blocks = datasets.blocks_2020(states=["11"])
Code
dc_blocks.plot()

Code
nlcd_path = "https://spatial-ucr.s3.amazonaws.com/nlcd/landcover/nlcd_landcover_2021.tif"
Code
vals = pd.read_csv("../09_dynamics/nlcd_colors.csv")
codes = vals.code.unique().tolist()
Code
vals
code color description
0 11 70,107,159 Open Water
1 12 209,222,248 Perennial Snow/Ice
2 21 222,197,197 Developed, Open Space
3 22 217,146,130 Developed, Low Intensity
4 23 235,0,0 Developed, Medium Intensity
5 24 171,0,0 Developed High Intensity
6 31 179,172,159 Barren Land (Rock/Sand/Clay)
7 41 104,171,95 Deciduous Forest
8 42 28,95,44 Evergreen Forest
9 43 181,197,143 Mixed Forest
10 52 204,184,121 Shrub/Scrub
11 71 223,223,194 Grassland/Herbaceous
12 81 220,217,57 Pasture/Hay
13 82 171,108,40 Cultivated Crops
14 90 184,217,235 Woody Wetlands
15 95 108,159,184 Emergent Herbaceous Wetlands
Code
dclu = extract_raster_features(
    dc_blocks, nlcd_path, pixel_values=codes, collapse_values=False
)
Code
dclu["value"] = dclu["value"].replace(
    dict(zip(vals.code.values, vals.description.values))
)
Code
crs = dc_blocks.estimate_utm_crs()

dc_blocks = dc_blocks.to_crs(crs)
dclu = dclu.to_crs(crs)
Code
dclu.plot("value", categorical=True)

Code
dclu
value geometry
0 Developed, Open Space POLYGON ((323226.647 4318276.105, 323315.290 4...
1 Developed, Medium Intensity POLYGON ((323272.435 4318205.034, 323301.983 4...
2 Developed, Open Space POLYGON ((323361.078 4318185.376, 323390.626 4...
3 Developed, Open Space POLYGON ((323183.792 4318224.692, 323213.340 4...
4 Developed, Low Intensity POLYGON ((323354.424 4318156.393, 323413.519 4...
... ... ...
18301 Open Water POLYGON ((322913.364 4295807.330, 322942.914 4...
18302 Developed High Intensity POLYGON ((323031.565 4295781.132, 323061.115 4...
18303 Developed, Medium Intensity POLYGON ((322942.914 4295800.780, 323031.565 4...
18304 Developed High Intensity POLYGON ((322965.813 4295765.249, 323024.913 4...
18305 Open Water POLYGON ((322922.960 4295713.836, 322952.511 4...

18306 rows × 2 columns

Code
lu_blks = area_interpolate(
    source_df=dclu,
    target_df=dc_blocks.set_index("geoid"),
    categorical_variables=["value"],
)
lu_blks.columns = lu_blks.columns.str.replace("value_", "")
Code
lu_blks.head()
Developed, Open Space Developed, Medium Intensity Developed, Low Intensity Deciduous Forest Developed High Intensity Mixed Forest Woody Wetlands Barren Land (Rock/Sand/Clay) Pasture/Hay Grassland/Herbaceous Shrub/Scrub Open Water Cultivated Crops Emergent Herbaceous Wetlands Evergreen Forest geometry
geoid
110019800001089 0.622183 0.076952 0.182508 0.000000 0.043109 0.000000 0.000000 0.000027 0.000000 0.000000 0.000000 0.0 0.075222 0.0 0.000000 POLYGON ((322969.039 4306546.708, 322970.142 4...
110010056012005 0.000000 0.659626 0.000000 0.000000 0.183696 0.000000 0.000000 0.156679 0.000000 0.000000 0.000000 0.0 0.000000 0.0 0.000000 POLYGON ((321580.797 4307997.329, 321596.402 4...
110010005013003 0.013664 0.452591 0.111835 0.014578 0.407331 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.0 0.000000 0.0 0.000000 POLYGON ((321758.637 4310250.787, 321759.503 4...
110010005011000 0.182705 0.110337 0.240769 0.305913 0.009644 0.041115 0.001609 0.078323 0.007111 0.005618 0.009364 0.0 0.000000 0.0 0.007491 POLYGON ((321810.700 4311101.634, 321883.434 4...
110010111003035 0.271752 0.200615 0.301211 0.106136 0.028303 0.000000 0.077833 0.000000 0.014151 0.000000 0.000000 0.0 0.000000 0.0 0.000000 POLYGON ((329084.877 4308909.414, 329085.096 4...
Code
lu_blks.explore("Developed High Intensity", tiles="CartoDB Positron")
Make this Notebook Trusted to load map: File -> Trust Notebook

:::