arealinterp

Areal interpolation between census tracts, districts and grids in Python: exact-overlay area weighting, target-density weighting, dasymetric mapping and Tobler pycnophylactic interpolation with volume checks.

Version 0.1.2 · Python >=3.9 · MIT licence
pip install arealinterp
PyPISourceIssuesChangelogCite (DOI)

arealinterp

PyPI version Python versions pipeline status License: MIT DOI Downloads

Areal interpolation between incompatible zone systems.

Census tracts never line up with planning districts, school catchments or grid cells. arealinterp moves counts and rates from one set of polygons to another with the classic methods, and it tells you how much of the total survived:

pip install arealinterp              # numpy only
pip install "arealinterp[shapely]"   # + shapely overlay backend

Requires Python 3.9 or newer.

Need more? tobler (PySAL) is a fuller alternative built on geopandas. It adds regression-based and model-based interpolation, H3 / hexagon utilities and raster masking through rasterio. arealinterp is a smaller package for when you don't want the geopandas stack. It has a dependency-free overlay engine, explicit diagnostics and a CLI.


Quick start (Python)

from arealinterp import area_weighted, read_geojson, write_geojson

tracts = read_geojson("tracts.geojson", id_field="GEOID")        # projected CRS!
districts = read_geojson("districts.geojson", id_field="code")

res = area_weighted(tracts, districts, extensive=["pop", "households"], intensive="median_rent")
print(res.as_dict("pop"))
print(res.volume["pop"])          # pop: source=152340 target=152340 diff=+0 (+0.000e+00)
write_geojson("districts_pop.geojson", districts, res)

Dasymetric and pycnophylactic variants share the same inputs and result type:

from arealinterp import (binary_dasymetric, dasymetric, estimate_class_densities,
                         pycnophylactic_interpolate, read_ascii_grid)

lc = read_ascii_grid("landcover.asc")            # 0 water, 1 low-, 2 high-density

bd = binary_dasymetric(tracts, districts, lc, "pop", inhabited=[1, 2])

est = estimate_class_densities(tracts, lc, "pop", threshold=0.8, presets={0: 0})
dd = dasymetric(tracts, districts, lc, "pop", densities=est.densities)
dd.details["surfaces"]["pop"]                    # the dasymetric population surface (Raster)

eb = dasymetric(tracts, districts, lc, "pop", percentages={2: 60, 1: 35, 0: 5})

pp = pycnophylactic_interpolate(tracts, districts, "pop", cell_size=100)
pp.details["pycno"]["pop"].surface               # smooth surface, volume-preserving

examples/quickstart.py runs all four methods on a synthetic town.

Quick start (command line)

# area weighting, GeoJSON out (the legacy "crs" member of the target file is copied)
arealinterp areal tracts.geojson districts.geojson --source-id GEOID --target-id code \
    -e pop -e households -i median_rent -o districts_pop.geojson

# attributes in a separate CSV
arealinterp areal tracts.geojson districts.geojson --source-id GEOID \
    --join census.csv -e pop -o out.csv

# target-density weighting
arealinterp tdw tracts_2000.geojson tracts_2020.geojson -e pop2000 --target-weight pop2020 -o out.csv

# dasymetric: binary / densities / percentages / estimated densities
arealinterp dasymetric tracts.geojson districts.geojson -e pop --raster lc.asc --inhabited 1,2
arealinterp dasymetric tracts.geojson districts.geojson -e pop --landcover lc.geojson \
    --class-field code --density high=10,low=3,other=0
arealinterp dasymetric tracts.geojson districts.geojson -e pop --raster lc.asc \
    --estimate --threshold 0.8 --preset 0=0 --surface pop_surface.asc

# pycnophylactic surface only, or summed over targets
arealinterp pycno tracts.geojson -e pop --cell-size 100 --surface pop.asc
arealinterp pycno tracts.geojson districts.geojson -e pop --cell-size 100 -o out.csv

# the raw intersection table
arealinterp overlay tracts.geojson districts.geojson -o overlay.csv

Without -o the estimates are written as CSV on stdout. The method summary and the volume report go to stderr.

API overview

Function Purpose
overlay(sources, targets, backend=) Exact intersection areas (Overlay: sparse table, .matrix(), .records()).
area_weighted(sources, targets, extensive, intensive, allocate_total=) Goodchild & Lam areal weighting.
target_density_weighted(sources, targets, extensive, target_variable) Schroeder TDW.
dasymetric(sources, targets, ancillary, extensive, densities= / percentages=) Density or fixed-percentage dasymetric mapping (raster or polygons).
binary_dasymetric(..., inhabited=[...]) Binary dasymetric mapping.
estimate_class_densities(sources, ancillary, variable, threshold=, presets=) Percent-cover sampling of class densities.
pycnophylactic(sources, variable, cell_size) / pycnophylactic_interpolate(...) Tobler surface / surface summed over targets.
intersection, intersection_area, make_polygon, box, region_area Pure-Python polygon geometry.
read_geojson, write_geojson, write_csv, join_csv, read_ascii_grid, write_ascii_grid I/O.
volume_report, VolumeReport, InterpolationResult Diagnostics and results.

Zones are Zone(id, geometry, properties). Geometries are lists of oriented rings: exteriors counter-clockwise, holes clockwise. region_from_geojson converts any GeoJSON Polygon or MultiPolygon, whatever its ring orientation. Every method returns an InterpolationResult, which holds values ({variable: numpy array}), volume ({variable: VolumeReport}), notes (fallbacks and warnings) and details (backend, fallback sources, surfaces, class densities).

Methods and sources

Notation: y_s is the source value, A_s the source area, A_t the target area, A_st the area of s ∩ t, and A_sc / A_stc the area of land-cover class c inside s / s ∩ t.

Areal weighting (Goodchild & Lam 1980):

With allocate_total=True the extensive denominator becomes Σ_t A_st. Each source's whole value then goes to the targets it touches, which helps when coastlines were digitised differently.

Target-density weighting (Schroeder 2007): w_st = A_st · z_t / A_t, and y_t = Σ_s y_s · w_st / Σ_t' w_st'. Here z_t is an ancillary count on the targets. Sources that touch only z = 0 targets fall back to areal weighting.

Dasymetric mapping:

With raster ancillary data, each cell belongs to the zones that contain its centre, and the dasymetric surface is returned. With polygon ancillary data, the triple overlay s ∩ t ∩ c is computed exactly. Area not covered by any ancillary polygon, and nodata cells, form the class UNCOVERED. Sources with no weighted area fall back to areal weighting. Sources too small to contain a cell centre are interpolated with exact areal weighting. Both cases are reported.

Density estimation (Mennis 2003; Mennis & Hultgren 2006): for each class, the source zones covered by that class to at least threshold are pooled, and d_c = Σ y_s / Σ A_s. Mennis & Hultgren (2006) compared 70 %, 80 % and 90 % thresholds; threshold=1.0 is "contained" sampling. You can preset classes with presets=, for example water = 0. Classes that no zone samples get one shared residual density: the population left after the known classes, divided by their area. This rule is a simplification (see Limitations).

Pycnophylactic interpolation (Tobler 1979). Each cell starts at its zone's value divided by its cell count. Each iteration then:

  1. relaxes every cell towards the mean of its four rook neighbours, a Jacobi step towards the Laplace equation that minimises roughness;
  2. adds each zone's mean residual back;
  3. clips negative cells to zero;
  4. rescales each zone multiplicatively.

Every zone's volume therefore holds to rounding error after every iteration, which the tests check. The edge condition is either neumann (zero gradient) or zero (zero density outside the study area). Both are discussed by Tobler.

Polygon overlay engine. The boundary of A ∩ B is made of three parts: the parts of ∂A inside B, the parts of ∂B inside A, and the boundary pieces the two share running in the same direction. Pieces shared in opposite directions are common edges of adjacent zones and are dropped. The engine splits each edge at every intersection point and classifies each piece by its midpoint. The area then follows from the shoelace / Green's theorem sum over the kept pieces, and the pieces are chained back into rings. Nearly coincident vertices are snapped together within a relative tolerance (default 1e‑9 of the extent). The tests compare the engine with shapely on random concave polygons with holes, to 1e‑12.

References

Limitations

Academic citation

@software{eminoglu_arealinterp,
  author  = {Eminoğlu, Yusuf},
  title   = {arealinterp},
  year    = {2026},
  version = {0.1.2},
  doi     = {10.5281/zenodo.24122223},
  url     = {https://gitlab.com/geophilo1/arealinterp_sdk}
}

See also CITATION.cff.

Related Geophilo SDKs

License

MIT © 2026 Yusuf Eminoğlu. See LICENSE.

Other Geophilo SDKs