Cityseer: Urban Network Analysis
Cityseer is a Python library providing computational tools for network-based pedestrian-scale urban analysis. It enables users to model urban environments, analyze accessibility, connectivity, and other urban metrics using spatial data and graph theory. The current version is 4.24.1, and it typically sees regular updates, often with significant changes between major versions.
Common errors
-
ModuleNotFoundError: No module named 'cityseer.graph'
cause Attempting to import or use the `Graph` object or its related modules from older (v3) Cityseer versions in v4+.fixThe `Graph` object has been removed in v4. All core network operations and data are now managed by the `cityseer.City` object. Use `City.from_osmnx(graph)` or similar constructors to create a `City` object, and then access network data and methods through it (e.g., `city.nodes`, `city.edges`). -
AttributeError: 'City' object has no attribute 'graph_from_bbox'
cause Calling a v3 standalone function (like `graph_from_bbox`) as a method on the new `City` object in v4+.fixIn v4+, `graph_from_bbox` and similar functions have been absorbed into the `City` constructor. Instead, initialize the `City` object directly with the bounding box or use `City.from_osmnx` with an already created OSMnx graph. E.g., `city = City('MyCity', bounding_box=(miny, minx, maxy, maxx), crs='EPSG:4326')`. -
pyproj.exceptions.CRSError: Invalid CRS: ...
cause The provided CRS string or object is not recognized or is malformed, often due to typos or incorrect EPSG codes.fixDouble-check the CRS string for correctness. Common valid options are `EPSG:4326` (WGS84 lat/lon) or local projected CRS codes (e.g., `EPSG:27700` for OSGB36). Ensure `pyproj` is up-to-date. If loading from a GeoDataFrame, use `gdf.crs` directly.
Warnings
- breaking Version 4.0.0 introduced significant breaking changes, refactoring the library around a central `City` object. Many standalone functions and older `Graph` objects were removed or moved into methods of the `City` class.
- gotcha Coordinate Reference System (CRS) handling is strict. You must explicitly provide a valid CRS (e.g., `crs='EPSG:4326'` for WGS84 or a projected CRS) when initializing a `City` object or importing data.
- gotcha Analyzing very large urban areas or extremely dense networks can lead to high memory consumption and long processing times. Cityseer is designed for pedestrian-scale analysis.
Install
-
pip install cityseer
Imports
- City
from cityseer.city import City
from cityseer import City
Quickstart
import osmnx as ox
from cityseer import City
# Define a place and retrieve its street network using OSMnx
place_name = 'Piedmont, California, USA'
G = ox.graph_from_place(place_name, network_type='walk')
# Create a Cityseer City object from the OSMnx graph
city = City.from_osmnx(G, crs='EPSG:4326')
# Perform a simple accessibility analysis
accessibility_result = city.analyze_accessibility(target_points=city.nodes.geometry)
# Print a sample of results (e.g., average accessibility)
print(f"Average accessibility (example): {accessibility_result.mean():.2f}")
# To save or visualize, you would typically use city.to_gdfs() or city.draw_network()
# For example, to get nodes with accessibility data:
# nodes_gdf = city.nodes.copy()
# nodes_gdf['accessibility'] = accessibility_result
# print(nodes_gdf.head())