Spatial Access

1.0.2 · active · verified Thu Apr 16

spatial-access is a Python package designed for measuring spatial accessibility to services. It provides tools to construct road networks, represent facilities and demand points, and compute various accessibility metrics like the Two-Step Floating Catchment Area (2SFCA) method. The current version is 1.0.2, and releases are made as needed to address issues and introduce features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple road network, define facilities and demand points using GeoDataFrames, and then compute spatial accessibility using the Two-Step Floating Catchment Area (2SFCA) method. It uses dummy data to ensure the example is runnable out-of-the-box.

from shapely.geometry import Point, LineString
import geopandas as gpd
import pandas as pd
import spatial_access as sa

# 1. Create dummy network data (nodes and edges)
# Nodes represent intersections or endpoints
nodes_df = pd.DataFrame({
    'id': [0, 1, 2, 3],
    'geometry': [Point(0, 0), Point(1, 0), Point(0, 1), Point(1, 1)]
})
nodes = gpd.GeoDataFrame(nodes_df, crs="EPSG:4326")

# Edges represent road segments connecting nodes
edges_df = pd.DataFrame({
    'id': [0, 1, 2, 3],
    'from': [0, 0, 1, 2],
    'to': [1, 2, 3, 3],
    'length': [1.0, 1.0, 1.0, 1.0], # A 'weight' or 'cost' column
    'geometry': [
        LineString([(0, 0), (1, 0)]),
        LineString([(0, 0), (0, 1)]),
        LineString([(1, 0), (1, 1)]),
        LineString([(0, 1), (1, 1)])
    ]
})
edges = gpd.GeoDataFrame(edges_df, crs="EPSG:4326")

# 2. Create dummy facility and demand data
# Facilities (e.g., hospitals, stores) with capacity
facilities_df = pd.DataFrame({
    'id': [0, 1],
    'capacity': [10, 15],
    'geometry': [Point(0.1, 0.1), Point(0.9, 0.9)]
})
facilities = gpd.GeoDataFrame(facilities_df, crs="EPSG:4326")

# Demand points (e.g., population centroids) with demand
demand_df = pd.DataFrame({
    'id': [0, 1],
    'demand': [5, 8],
    'geometry': [Point(0.2, 0.2), Point(0.8, 0.8)]
})
demand = gpd.GeoDataFrame(demand_df, crs="EPSG:4326")


# 3. Initialize Network and Access objects
# The 'length' column is used as the weight for shortest path calculations
network = sa.Network(nodes, edges, "length")

# Create the Access model, linking network, facilities, and demand
access_model = sa.Access(network, facilities, demand, "capacity", "demand")

# 4. Compute 2SFCA accessibility
# Using a distance threshold of 10 units (arbitrary for dummy data)
# and a Gaussian weight function. The result is (Si, Dj) where Si is 
# accessibility for demand points and Dj for facilities.
print("Calculating 2SFCA accessibility...")
accessibility_scores = access_model.two_sfca(10, weight_function="gaussian")

# Print accessibility scores for demand points
print("\nAccessibility scores for demand points (Si):")
print(accessibility_scores[0].head())

view raw JSON →