Skip to main content

Reusable NYC geography resources, normalization helpers, and boundary loaders for Python tools.

Project description

nyc-geo-toolkit

Actions Status Documentation Status PyPI version PyPI platforms

nyc-geo-toolkit cover figure

Reusable NYC geography resources, normalization helpers, and boundary loaders for Python tools.

Authored by Blaise Albis-Burdige.

Why this exists

Every NYC data project needs borough boundaries, ZIP lookups, and district normalization. nyc-geo-toolkit ships canonical boundary GeoJSON and a stable Python API so downstream tools don't duplicate that work. Install the base package for zero-dependency boundary loading, or add optional extras for pandas, geopandas, and basemap helpers.

What this package provides

  • Packaged boundary layers for boroughs, community districts, council districts, NTAs, ZCTAs, and census tracts -- no runtime network dependency
  • Normalization helpers that turn messy user input ("bk", "01 Brooklyn", "zip code") into canonical values
  • Geodesy helpers for great-circle distance, walk-radius circles, and bounding boxes -- dependency-free
  • Typed models (BoundaryCollection, BoundaryFeature) for safe, inspectable boundary data
  • GeoJSON, DataFrame, and GeoDataFrame conversion with optional pandas and geopandas extras
  • Basemap and spatial helpers for Web Mercator reprojection, OSM tile overlays, and bbox clipping

Ecosystem

nyc-geo-toolkit is the shared geography core for a family of NYC data packages:

Package Description
nyc311 311 service request analysis and aggregation
subway-access Subway accessibility and coverage analysis
nyc-mesh Community mesh network coverage analysis

All three depend on the stable nyc_geo_toolkit namespace for boundary data, normalization, and spatial primitives.

Install

pip install nyc-geo-toolkit              # zero-dependency base
pip install "nyc-geo-toolkit[dataframes]" # + pandas helpers
pip install "nyc-geo-toolkit[spatial]"    # + geopandas, shapely, contextily
pip install "nyc-geo-toolkit[all]"        # everything

Quick start

Load and inspect boundaries

from nyc_geo_toolkit import list_boundary_layers, load_nyc_boundaries

print(list_boundary_layers())
# ('borough', 'community_district', 'council_district', ...)

queens = load_nyc_boundaries("borough", values="Queens")
print(queens.features[0].geography_value)  # "QUEENS"

Normalize messy input

from nyc_geo_toolkit import normalize_borough_name, normalize_boundary_value

normalize_borough_name("bk")  # "BROOKLYN"
normalize_boundary_value("community_district", "01 Brooklyn")  # "BROOKLYN 01"

Plot a boundary layer

from nyc_geo_toolkit import (
    load_nyc_boundaries_geodataframe,
    to_web_mercator,
    add_osm_basemap,
)

gdf = to_web_mercator(load_nyc_boundaries_geodataframe("borough"))
ax = gdf.plot(figsize=(8, 8), edgecolor="white", alpha=0.7, column="geography_value")
add_osm_basemap(ax)

Use geodesy helpers

from nyc_geo_toolkit import (
    haversine_distance_meters,
    walk_radius_meters,
    build_circle_polygon,
)

walk_radius_meters(10)  # 800.0 meters
haversine_distance_meters(40.7580, -73.9855, 40.7128, -74.006)  # ~5.2 km
polygon = build_circle_polygon(40.7128, -74.006, 800)  # 24-sided circle

API overview

Category Key functions
Discovery & loading list_boundary_layers(), list_boundary_values(), load_nyc_boundaries(), load_nyc_boundaries_geodataframe()
Normalization normalize_borough_name(), normalize_boundary_layer(), normalize_boundary_value(), normalize_boundary_values()
Geodesy haversine_distance_meters(), walk_radius_meters(), build_circle_polygon()
Spatial helpers add_osm_basemap(), to_web_mercator(), bbox_around(), clip_boundaries_to_bbox()
Conversion boundaries_to_geojson(), boundaries_to_dataframe()
Models & constants BoundaryCollection, BoundaryFeature, BoundaryLayerSpec, BOROUGH_*, SUPPORTED_BOROUGHS

Full reference: API docs

Examples

The repo ships self-contained examples under examples/:

Documentation

Home | Getting Started | Examples | API Reference | Architecture

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nyc_geo_toolkit-0.4.1.tar.gz (11.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nyc_geo_toolkit-0.4.1-py3-none-any.whl (10.5 MB view details)

Uploaded Python 3

File details

Details for the file nyc_geo_toolkit-0.4.1.tar.gz.

File metadata

  • Download URL: nyc_geo_toolkit-0.4.1.tar.gz
  • Upload date:
  • Size: 11.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nyc_geo_toolkit-0.4.1.tar.gz
Algorithm Hash digest
SHA256 8e28cd81511267302d41094d3765bc059b7faea5139d2ec80619df6b222d618b
MD5 42f48008b349e9bdc28a95c80fdd5bbc
BLAKE2b-256 d55aa86f0d101f75d6822751b99d2136a98c088d913d9ce1eb945d2b27b6bfb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for nyc_geo_toolkit-0.4.1.tar.gz:

Publisher: cd.yml on random-walks/nyc-geo-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nyc_geo_toolkit-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: nyc_geo_toolkit-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nyc_geo_toolkit-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3130b44b8315aeced757e188a3a38467d1574c7c001c44e8898c73442803083b
MD5 477dee49a57afda48154dc9db7ef162c
BLAKE2b-256 4c075dde590a8cbb705e280de9146ace4427fb180e46cec566add69037ce9376

See more details on using hashes here.

Provenance

The following attestation bundles were made for nyc_geo_toolkit-0.4.1-py3-none-any.whl:

Publisher: cd.yml on random-walks/nyc-geo-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page