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.3.0.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.3.0-py3-none-any.whl (10.5 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nyc_geo_toolkit-0.3.0.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.3.0.tar.gz
Algorithm Hash digest
SHA256 103a96975bbb9e73e8679b5a020ee15810bdf20e83276bfc5d0caf8b5e5da814
MD5 c63aeee39452fdafd72cf3f3f3991cf4
BLAKE2b-256 216d9769c73c3255ce78e54367558a4c78d1f317c679f86260db4395fc1a1759

See more details on using hashes here.

Provenance

The following attestation bundles were made for nyc_geo_toolkit-0.3.0.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.3.0-py3-none-any.whl.

File metadata

  • Download URL: nyc_geo_toolkit-0.3.0-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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ba543bbfc2e97997c8a73b1853ea8827581047eb1ff81cfd9aeed1f8b824ee2
MD5 d2c530c0ec05b2dd0c0fa94335262555
BLAKE2b-256 02b225e40c383dd0fd1e70aad95b12264f9cd6fbb5b2535f6abdc0e6da6f9a5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nyc_geo_toolkit-0.3.0-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