View source: R/tracts_to_polygon.R
| tracts_to_polygon | R Documentation |
tracts_to_polygon() performs a dasymetric interpolation with the following steps:
census tract totals are allocated to CNEFE dwelling points inside each tract;
allocated values are aggregated to user-provided polygons (neighborhoods, administrative divisions, custom areas, etc.).
The function uses DuckDB with spatial extensions for the heavy work.
Unlike cnefe_counts() and compute_lumi(), this function does not expose a
backend argument and relies on DuckDB exclusively. The dominant cost here is
a spatial overlay between the full CNEFE point set of the municipality and the
census tract polygons, which is a different workload from the tabular
aggregation those other functions perform. Running that overlay in R would
take prohibitively long in medium and large municipalities, so a pure-R
fallback would offer users a path that does not finish rather than a slower
one.
tracts_to_polygon(
code_muni,
polygon,
year = 2022,
vars = c("pop_ph", "pop_ch"),
crs_output = NULL,
cache = TRUE,
cache_dir = NULL,
verbose = TRUE
)
code_muni |
Integer. Seven-digit IBGE municipality code. |
polygon |
An |
year |
Integer. The CNEFE data year. Currently only 2022 is supported. Defaults to 2022. |
vars |
Character vector. Names of tract-level variables to interpolate. Supported variables:
For a reference table mapping these variable names to the official IBGE census tract codes and descriptions, see tracts_variables_ref. Allocation rules:
|
crs_output |
The CRS for the output object. Default is |
cache |
Logical. Whether to use the package cache for the census tract assets and the CNEFE files. |
cache_dir |
Character. Directory to use for cached downloads. If |
verbose |
Logical. Whether to print step messages and timing. |
An sf object with the user-provided polygons and the requested
interpolated variables. The output CRS matches the original polygon CRS
(or crs_output if specified).
# Interpolate population to user-provided polygons (neighborhoods of Lauro de Freitas-BA)
# Using geobr to download neighborhood boundaries
library(geobr)
nei_ldf <- subset(
read_neighborhood(year = 2022),
code_muni == 2919207
)
poly_pop <- tracts_to_polygon(
code_muni = 2919207,
polygon = nei_ldf,
vars = c("pop_ph", "pop_ch"),
cache = FALSE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.