API Reference¶
The stable reference for this package is the top-level nyc_geo_toolkit
namespace. This page is generated directly from that namespace so the published
API docs, the package __all__, and the consumer contract stay aligned.
Underscore-prefixed modules are internal implementation details and are not part of the supported public surface.
Loading & Discovery¶
Reusable NYC geography resources, normalization helpers, and boundary loaders.
list_boundary_layers ¶
list_boundary_layers() -> tuple[str, ...]
Return the names of all available boundary layers.
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
Layer names in catalog order (e.g. |
Example
list_boundary_layers() ('borough', 'community_district', 'council_district', ...)
Source code in src/nyc_geo_toolkit/_loaders.py
58 59 60 61 62 63 64 65 66 67 68 | |
list_boundary_values ¶
list_boundary_values(
layer: str, *, vintage: int | None = None
) -> tuple[str, ...]
Return the canonical values for a boundary layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
Boundary layer name or alias (e.g. |
required |
vintage
|
int | None
|
Optional vintage year. Defaults to the layer's default vintage. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
Canonical value strings for every feature in the layer. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the layer name is unsupported. |
Source code in src/nyc_geo_toolkit/_loaders.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
list_available_vintages ¶
list_available_vintages(
layer: str | None = None,
) -> dict[str, tuple[int, ...]] | tuple[int, ...]
Return available vintage years for boundary layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str | None
|
A specific layer name or alias. When |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, tuple[int, ...]] | tuple[int, ...]
|
A tuple of vintage years when layer is given, or a dict mapping |
dict[str, tuple[int, ...]] | tuple[int, ...]
|
layer names to vintage tuples when layer is |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the layer name is unsupported. |
Example
list_available_vintages("census_tract") (2000, 2010, 2020) list_available_vintages() {'borough': (2020,), 'census_tract': (2000, 2010, 2020), ...}
Source code in src/nyc_geo_toolkit/_loaders.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
vintage_for_census_decade ¶
vintage_for_census_decade(layer: str, decade: int) -> int
Return the actual vintage year for a layer given a census decade.
Most layers align directly with census decades (2000, 2010, 2020), but some use different years. For example, council districts are redistricted in 2013 and 2023 rather than 2010 and 2020.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
Boundary layer name or alias. |
required |
decade
|
int
|
A census decade year ( |
required |
Returns:
| Type | Description |
|---|---|
int
|
The vintage year that corresponds to the requested decade. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the layer or decade has no mapping. |
Example
vintage_for_census_decade("council_district", 2020) 2023
Source code in src/nyc_geo_toolkit/_loaders.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
load_nyc_boundaries ¶
load_nyc_boundaries(
layer: str = "community_district",
*,
values: str | tuple[str, ...] | list[str] | None = None,
vintage: int | None = None,
) -> BoundaryCollection
Load packaged NYC boundary features for a given geography layer.
Returns a typed BoundaryCollection containing all features for the
requested layer, optionally filtered to specific values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
Boundary layer name. One of |
'community_district'
|
values
|
str | tuple[str, ...] | list[str] | None
|
Optional filter. A single value string, or a sequence of values.
Values are normalized automatically (e.g. |
None
|
vintage
|
int | None
|
Optional vintage year. Defaults to the layer's default vintage (2020 for most layers, 2023 for council districts). |
None
|
Returns:
| Type | Description |
|---|---|
BoundaryCollection
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the layer or vintage is unsupported, or no features match the requested values. |
Example
boundaries = load_nyc_boundaries("borough", values="Manhattan") len(boundaries.features) 1 boundaries.vintage 2020
Source code in src/nyc_geo_toolkit/_loaders.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
load_nyc_boundaries_geodataframe ¶
load_nyc_boundaries_geodataframe(
layer: str = "community_district",
*,
values: str | tuple[str, ...] | list[str] | None = None,
vintage: int | None = None,
) -> gpd.GeoDataFrame
Load packaged NYC boundaries as a GeoPandas GeoDataFrame.
Requires the spatial extra (pip install nyc-geo-toolkit[spatial]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
Boundary layer name or alias. |
'community_district'
|
values
|
str | tuple[str, ...] | list[str] | None
|
Optional value filter (see |
None
|
vintage
|
int | None
|
Optional vintage year. |
None
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
A |
GeoDataFrame
|
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If geopandas or shapely is not installed. |
ValueError
|
If the layer, vintage, or values are unsupported. |
Source code in src/nyc_geo_toolkit/_loaders.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
load_boundaries ¶
load_boundaries(
source: str | Path, *, vintage: int | None = None
) -> BoundaryCollection
Load boundaries from a packaged layer name or a GeoJSON file path.
When source is a recognized layer name (or alias), delegates to
load_nyc_boundaries. When it is a file path, reads and parses
the GeoJSON file directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path
|
A layer name string (e.g. |
required |
vintage
|
int | None
|
Optional vintage year, used only when source is a layer name. |
None
|
Returns:
| Type | Description |
|---|---|
BoundaryCollection
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the layer is unsupported or the file cannot be parsed. |
Source code in src/nyc_geo_toolkit/_loaders.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
load_nyc_census_tracts ¶
load_nyc_census_tracts(
*,
values: str | tuple[str, ...] | list[str] | None = None,
vintage: int | None = None,
) -> BoundaryCollection
Load NYC census tract boundaries.
Convenience wrapper around load_nyc_boundaries("census_tract", ...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
str | tuple[str, ...] | list[str] | None
|
Optional tract filter (11-digit GEOIDs or 7-digit borough codes). |
None
|
vintage
|
int | None
|
Optional vintage year (available: 2000, 2010, 2020). |
None
|
Returns:
| Type | Description |
|---|---|
BoundaryCollection
|
A |
Source code in src/nyc_geo_toolkit/_loaders.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
load_nyc_council_districts ¶
load_nyc_council_districts(
*,
values: str | tuple[str, ...] | list[str] | None = None,
vintage: int | None = None,
) -> BoundaryCollection
Load NYC City Council district boundaries.
Convenience wrapper around load_nyc_boundaries("council_district", ...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
str | tuple[str, ...] | list[str] | None
|
Optional district number filter (e.g. |
None
|
vintage
|
int | None
|
Optional vintage year (available: 2013, 2023). |
None
|
Returns:
| Type | Description |
|---|---|
BoundaryCollection
|
A |
Source code in src/nyc_geo_toolkit/_loaders.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
load_nyc_neighborhood_tabulation_areas ¶
load_nyc_neighborhood_tabulation_areas(
*,
values: str | tuple[str, ...] | list[str] | None = None,
vintage: int | None = None,
) -> BoundaryCollection
Load NYC Neighborhood Tabulation Area boundaries.
Convenience wrapper around
load_nyc_boundaries("neighborhood_tabulation_area", ...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
str | tuple[str, ...] | list[str] | None
|
Optional NTA code filter (e.g. |
None
|
vintage
|
int | None
|
Optional vintage year (available: 2010, 2020). |
None
|
Returns:
| Type | Description |
|---|---|
BoundaryCollection
|
A |
Source code in src/nyc_geo_toolkit/_loaders.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
describe_layer ¶
describe_layer(
layer: str, *, vintage: int | None = None
) -> BoundaryLayerSpec
Return metadata about a boundary layer including provenance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
Boundary layer name or alias. |
required |
vintage
|
int | None
|
Optional vintage year. Defaults to the layer's default vintage. |
None
|
Returns:
| Type | Description |
|---|---|
BoundaryLayerSpec
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the layer or vintage is unsupported. |
Example
spec = describe_layer("census_tract", vintage=2010) spec.source_name 'US Census Bureau TIGER/Line'
Source code in src/nyc_geo_toolkit/_loaders.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
Normalization¶
Reusable NYC geography resources, normalization helpers, and boundary loaders.
normalize_borough_name ¶
normalize_borough_name(value: str) -> str
Normalize a borough name to its canonical uppercase form.
Accepts common aliases and abbreviations (e.g. "bk" → "BROOKLYN",
"mn" → "MANHATTAN").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
A borough name, abbreviation, or alias. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Canonical uppercase borough name (e.g. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the value is empty or not a recognized borough. |
Source code in src/nyc_geo_toolkit/_normalize.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
normalize_boundary_layer ¶
normalize_boundary_layer(layer: str) -> str
Normalize a boundary layer name to its canonical form.
Accepts common aliases such as "zip" → "zcta",
"nta" → "neighborhood_tabulation_area", and
"community_board" → "community_district".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
A layer name or alias string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Canonical layer name (e.g. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the layer is not recognized. |
Source code in src/nyc_geo_toolkit/_normalize.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
normalize_boundary_value ¶
normalize_boundary_value(layer: str, value: str) -> str
Normalize a single boundary value for a given layer.
Each layer has its own normalization rules. For example, community
district values like "bk 01" become "BROOKLYN 01", and
census tract values accept both 7-digit borough codes and 11-digit
GEOIDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
Boundary layer name or alias. |
required |
value
|
str
|
A raw boundary value string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The canonical normalized value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the value cannot be parsed for the given layer. |
Source code in src/nyc_geo_toolkit/_normalize.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
normalize_boundary_values ¶
normalize_boundary_values(
layer: str, values: str | Iterable[str] | None
) -> tuple[str, ...] | None
Normalize one or more boundary values for a layer.
Accepts a single string, an iterable of strings, or None.
Each value is passed through normalize_boundary_value.
Duplicates are removed while preserving order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
Boundary layer name or alias. |
required |
values
|
str | Iterable[str] | None
|
A single value, iterable of values, or |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, ...] | None
|
A deduplicated tuple of normalized values, or |
tuple[str, ...] | None
|
input is |
Source code in src/nyc_geo_toolkit/_normalize.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
Models¶
Reusable NYC geography resources, normalization helpers, and boundary loaders.
BoundaryCollection
dataclass
¶
A collection of boundary features for one geography type and vintage.
Attributes:
| Name | Type | Description |
|---|---|---|
geography |
str
|
Canonical layer name shared by all features. |
features |
tuple[BoundaryFeature, ...]
|
Tuple of |
vintage |
int
|
Year the boundary data represents. |
Source code in src/nyc_geo_toolkit/_models.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
BoundaryFeature
dataclass
¶
A single boundary feature with canonical geography metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
geography |
str
|
Canonical layer name (e.g. |
geography_value |
str
|
Canonical identifier for this feature
(e.g. |
geometry |
dict[str, Any]
|
GeoJSON geometry object ( |
properties |
dict[str, Any]
|
Additional properties from the source data, excluding
|
Source code in src/nyc_geo_toolkit/_models.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
BoundaryLayerSpec
dataclass
¶
Metadata describing one packaged NYC boundary layer.
Attributes:
| Name | Type | Description |
|---|---|---|
layer |
str
|
Canonical layer name (e.g. |
display_name |
str
|
Human-readable label for the layer. |
resource_path |
str
|
Package-relative path to the GeoJSON file. |
vintage |
int
|
Year this boundary data represents (e.g. |
source_name |
str
|
Name of the data source organization. |
source_url |
str
|
URL to the source data page. |
feature_count |
int
|
Expected number of features in the layer. |
Source code in src/nyc_geo_toolkit/_models.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
Conversion¶
Reusable NYC geography resources, normalization helpers, and boundary loaders.
boundaries_to_geojson ¶
boundaries_to_geojson(
boundaries: BoundaryCollection,
) -> dict[str, object]
Convert a BoundaryCollection to a GeoJSON FeatureCollection dict.
Each feature includes geography and geography_value in its
properties alongside any additional source properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundaries
|
BoundaryCollection
|
A typed boundary collection. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
A GeoJSON-compatible dict with |
Source code in src/nyc_geo_toolkit/_conversions.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
boundaries_to_dataframe ¶
boundaries_to_dataframe(
boundaries: BoundaryCollection,
) -> pd.DataFrame
Convert a BoundaryCollection to a pandas DataFrame.
Requires the dataframes extra
(pip install nyc-geo-toolkit[dataframes]).
Columns include geography, geography_value, geometry
(as a raw GeoJSON dict), and any additional source properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundaries
|
BoundaryCollection
|
A typed boundary collection. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A |
Raises:
| Type | Description |
|---|---|
ImportError
|
If pandas is not installed. |
Source code in src/nyc_geo_toolkit/_conversions.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
Geodesy¶
Reusable NYC geography resources, normalization helpers, and boundary loaders.
haversine_distance_meters ¶
haversine_distance_meters(
latitude_a: float,
longitude_a: float,
latitude_b: float,
longitude_b: float,
) -> float
Return the great-circle distance between two WGS84 points in meters.
Uses the haversine formula. No external dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude_a
|
float
|
Latitude of the first point (decimal degrees). |
required |
longitude_a
|
float
|
Longitude of the first point (decimal degrees). |
required |
latitude_b
|
float
|
Latitude of the second point (decimal degrees). |
required |
longitude_b
|
float
|
Longitude of the second point (decimal degrees). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Distance in meters. |
Source code in src/nyc_geo_toolkit/_geodesy.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
walk_radius_meters ¶
walk_radius_meters(
minutes: float,
*,
meters_per_minute: float = DEFAULT_WALKING_METERS_PER_MINUTE,
) -> float
Convert a walking-time threshold into an approximate radius in meters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minutes
|
float
|
Walking time in minutes (must be positive). |
required |
meters_per_minute
|
float
|
Walking speed. Defaults to 80 m/min (~3 mph). |
DEFAULT_WALKING_METERS_PER_MINUTE
|
Returns:
| Type | Description |
|---|---|
float
|
Approximate radius in meters. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If minutes or meters_per_minute is not positive. |
Source code in src/nyc_geo_toolkit/_geodesy.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
build_circle_polygon ¶
build_circle_polygon(
latitude: float,
longitude: float,
radius_meters: float,
*,
sides: int = 24,
) -> tuple[tuple[float, float], ...]
Return a WGS84 polygon approximating a circle around a point.
Coordinates are returned as (longitude, latitude) pairs following
the GeoJSON convention. The polygon is closed (first point == last).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
Center latitude (decimal degrees). |
required |
longitude
|
float
|
Center longitude (decimal degrees). |
required |
radius_meters
|
float
|
Circle radius in meters (must be positive). |
required |
sides
|
int
|
Number of polygon sides (minimum 8). |
24
|
Returns:
| Type | Description |
|---|---|
tuple[tuple[float, float], ...]
|
A tuple of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If radius_meters is not positive or sides < 8. |
Source code in src/nyc_geo_toolkit/_geodesy.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
Spatial Helpers¶
Reusable NYC geography resources, normalization helpers, and boundary loaders.
centroids_from_boundaries ¶
centroids_from_boundaries(
boundaries: BoundaryCollection,
*,
representative: bool = False,
) -> BoundaryCollection
Compute per-feature centroids as a Point BoundaryCollection.
For every polygon or multi-polygon feature in boundaries, returns a
GeoJSON Point geometry at either the geometric centroid (default) or
the shapely representative_point (guaranteed to fall inside the
polygon, useful for non-convex shapes like community districts with
concave shorelines). Feature identity — geography, geography_value,
and properties — round-trips verbatim, so the returned collection
can be fed back through :func:boundaries_to_geojson or
:func:boundaries_to_dataframe.
Requires the spatial extra (pip install nyc-geo-toolkit[spatial]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundaries
|
BoundaryCollection
|
A |
required |
representative
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
BoundaryCollection
|
A new |
BoundaryCollection
|
GeoJSON |
BoundaryCollection
|
preserved. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If shapely is not installed. |
ValueError
|
If |
Example
from nyc_geo_toolkit import ( ... centroids_from_boundaries, ... load_nyc_boundaries, ... ) cds = load_nyc_boundaries("community_district") points = centroids_from_boundaries(cds) points.features[0].geometry["type"] 'Point'
Source code in src/nyc_geo_toolkit/_ops.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
clip_boundaries_to_bbox ¶
clip_boundaries_to_bbox(
boundaries: BoundaryCollection,
*,
min_longitude: float,
min_latitude: float,
max_longitude: float,
max_latitude: float,
) -> BoundaryCollection
Clip boundary features to an axis-aligned bounding box.
Features that do not intersect the bounding box are dropped.
Features that partially overlap are clipped to the box.
Requires the spatial extra (pip install nyc-geo-toolkit[spatial]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundaries
|
BoundaryCollection
|
A |
required |
min_longitude
|
float
|
Western edge (WGS84 degrees). |
required |
min_latitude
|
float
|
Southern edge (WGS84 degrees). |
required |
max_longitude
|
float
|
Eastern edge (WGS84 degrees). |
required |
max_latitude
|
float
|
Northern edge (WGS84 degrees). |
required |
Returns:
| Type | Description |
|---|---|
BoundaryCollection
|
A new |
Raises:
| Type | Description |
|---|---|
ImportError
|
If shapely is not installed. |
ValueError
|
If the bounding box is degenerate or no features intersect. |
Source code in src/nyc_geo_toolkit/_ops.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
add_osm_basemap ¶
add_osm_basemap(
axes: Any, *, provider: Any | None = None
) -> None
Add a basemap to a matplotlib axes in Web Mercator projection.
Defaults to CartoDB Positron tiles. Requires the spatial extra
(pip install nyc-geo-toolkit[spatial]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axes
|
Any
|
A matplotlib |
required |
provider
|
Any | None
|
An optional contextily tile provider. Defaults to
|
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If contextily is not installed. |
Source code in src/nyc_geo_toolkit/_basemap.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
to_web_mercator ¶
to_web_mercator(geodataframe: Any) -> Any
Return a copy of a GeoDataFrame reprojected to EPSG:3857 (Web Mercator).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geodataframe
|
Any
|
A geopandas |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A new |
Source code in src/nyc_geo_toolkit/_basemap.py
28 29 30 31 32 33 34 35 36 37 | |
bbox_around ¶
bbox_around(
point: tuple[float, float], meters: float
) -> tuple[float, float, float, float]
Return a WGS84 bounding box around a point.
Computes the axis-aligned envelope of a circle with radius meters in Web Mercator, then reprojects to EPSG:4326.
Requires the spatial extra
(pip install nyc-geo-toolkit[spatial]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
tuple[float, float]
|
|
required |
meters
|
float
|
Buffer radius in real-world meters (must be positive). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float
|
|
|
EPSG |
float
|
4326. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If geopandas or shapely is not installed. |
ValueError
|
If meters is not positive. |
Source code in src/nyc_geo_toolkit/_basemap.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
Constants¶
Reusable NYC geography resources, normalization helpers, and boundary loaders.
SUPPORTED_BOROUGHS
module-attribute
¶
SUPPORTED_BOROUGHS: Final[tuple[BoroughName, ...]] = (
BOROUGH_BRONX,
BOROUGH_BROOKLYN,
BOROUGH_MANHATTAN,
BOROUGH_QUEENS,
BOROUGH_STATEN_ISLAND,
)
SUPPORTED_BOUNDARY_GEOGRAPHIES
module-attribute
¶
SUPPORTED_BOUNDARY_GEOGRAPHIES: Final[tuple[str, ...]] = (
"borough",
"community_district",
"council_district",
"neighborhood_tabulation_area",
"census_tract",
"zcta",
)
BOROUGH_STATEN_ISLAND
module-attribute
¶
BOROUGH_STATEN_ISLAND: Final[BoroughName] = 'STATEN ISLAND'