osm-chordify
Download, filter, and export OSM road networks using population-density-based boundaries. Intersect the resulting geometries with polygon grids (TAZ, census tracts, ISRM cells, etc.) and map them to BEAM/MATSim simulation network.
No AI Training Use: The contents of this repository may not be used to train, fine-tune, evaluate, benchmark, or improve machine learning or artificial intelligence models without prior written permission. See NOAI.
Installation
Requires Python 3.10+.
From PyPI:
pip install osm-chordify
From GitHub:
pip install git+https://github.com/LBNL-UCB-STI/osm-chordify.git
For development:
git clone https://github.com/LBNL-UCB-STI/osm-chordify.git
cd osm-chordify
pip install -e ".[dev]"
U.S. Census API key
build_osm_by_pop_density uses the U.S. Census Bureau API to fetch population data for density-based filtering. Set your API key as an environment variable:
export CENSUS_API_KEY="your_key_here"
To make it persistent, add the line above to your ~/.bashrc, ~/.zshrc, or .env file.
Get a free key at https://api.census.gov/data/key_signup.html.
You can also pass the key directly to the example scripts with --census-api-key.
API
from osm_chordify import (
build_area_mask_from_counties,
build_osm_by_pop_density,
create_osm_highway_filter,
intersect_polygons_with_zones,
intersect_road_network_with_county_zones,
intersect_road_network_with_zones,
spatial_left_join_with_zones,
intersect_zones_with_zones,
map_osm_with_beam_network,
)
Core functions:
build_area_mask_from_counties: build a fused county-based land mask or whole-area mask from FIPS codesbuild_osm_by_pop_density: build a multi-layer OSM network from county / tract / CBG boundaries and density filtersintersect_polygons_with_zones: cascade an already-intersected polygon layer into a new zone layerintersect_road_network_with_county_zones: intersect a network with county polygons fetched by state/county FIPS codesintersect_road_network_with_zones: intersect network edges with zone polygonsspatial_left_join_with_zones: spatially left-join any geometry layer with zone attributes while keeping unmatched rowsintersect_zones_with_zones: intersect one polygon zone layer with anothermap_osm_with_beam_network: join BEAM network attributes onto OSM geometries
Intersection outputs always include:
proportionlink_length_m
These columns always describe the latest intersection step. In chained intersections, earlier polygon columns are carried forward unchanged, and only the current step adds new unlabeled or <label>_... metrics plus the new zone attributes.
For dense grids, intersect_road_network_with_zones(...) can optionally
prefilter zones to the overall road-network bounding box before exact
intersection:
prefilter_zones_to_network_bbox=Falsedisables the prefilterprefilter_zones_to_network_bbox=Truekeeps only zones intersecting the network bounding box
This reduces the zone set before exact intersection and shows a dedicated
Filtering zones progress bar. Zones kept by the bounding-box prefilter that
still contain no intersecting link pieces are preserved instead of being
dropped; the fixed numeric intersection columns remain null for those rows.
For rectangular or polygon link workflows, use
intersect_polygons_with_zones(...). It computes overlap proportions from
polygon area, derives <label>_link_length_m (or link_length_m without a
label) from the source polygon length column, and prefilters zones to the
input-layer bounding box by default.
For cascading polygon workflows, use:
intersect_polygons_with_zones(...)- preserves all existing columns from the input polygon layer
- adds new zone attributes with a label prefix such as
inmap_*oraermod_* - computes current-step metrics:
<label>_proportion<label>_link_length_m
spatial_left_join_with_zones(...)- keeps all input rows
- appends zone attributes where matched, using a label prefix such as
county_* - leaves zone columns null where no zone intersects
Mask generation semantics:
include_water=False- land mask
- uses shoreline-clipped cartographic county boundaries
- fuses counties without taking a convex hull
- optional
buffer_mis applied to that non-convex land geometry
include_water=True- whole-area mask
- uses full TIGER/Line county boundaries
- takes the convex hull of the fused counties
- optional
buffer_mis applied to that convex whole-area geometry
Networks can be exported as GraphML, PKL, GPKG, OSM XML, OSM PBF, and GeoJSON.
You can also run the main workflows via CLI:
python -m osm_chordify.main --help
Examples
See the examples/ directory for complete, runnable scripts:
| Script | Description |
|---|---|
build_sfbay.py |
Build OSM network for the SF Bay Area (9 counties) |
build_seattle.py |
Build OSM network for Seattle metro (4 counties + ferry) |
compare_osm_pbf.py |
Compare validation and diagnostics metrics across two built .osm.pbf artifacts |
intersect_zones.py |
Intersect one polygon zone layer with another |
intersect_and_map_sfbay.py |
Intersect OSM with polygon grid and map BEAM network |
diagnose_osm_pbf.py |
Validate and diagnose a built .osm.pbf artifact |
For commands, output layout, validation behavior, and project structure, see docs/USAGE.md.
Metadata
Release files for osm-chordify 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| osm_chordify-0.2.4.tar.gz | 96.0 kB | Without provenance | Details for osm_chordify-0.2.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| osm_chordify-0.2.4-py3-none-any.whl | Python 3 | none | any | Details for osm_chordify-0.2.4-py3-none-any.whl |
Total release size: 158.6 kB
Release files / osm_chordify-0.2.4.tar.gz
| Download URL | osm_chordify-0.2.4.tar.gz |
|---|---|
| Size | 96.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e85c1b632c84291d8b7b988af53870b68efbe205a3ca8ccbaff458fac220bc7d
|
|
BLAKE2b-256 checksum How to use checksums |
05c0d5e09e13010f274ea52f26e62bd28b4f0c36fbd8f6949a77d6b4442897f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / osm_chordify-0.2.4-py3-none-any.whl
| Download URL | osm_chordify-0.2.4-py3-none-any.whl |
|---|---|
| Size | 62.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
45f4a1d5193fac0002b4e38b2c78aa9b719e80b028f5390be6ffd769a0b4917f
|
|
BLAKE2b-256 checksum How to use checksums |
996c6aa6c392d133acad6f40d110acb0d42504b110177a9a4ff8a2500ddd046d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Security for osm-chordify 0.2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.