skillfed

spopt

Spatial Optimization in PySAL

spopt v0.7.0 102.1K downloads/30d#12,891 on PyPI380
Permissive license BSD 3-Clause Active released

What it is and what it does

Spopt is a Python library for solving spatial optimization problems on geographic data, originating from PySAL's region module and now actively developed as a standalone package. It handles three main problem classes: regionalization (grouping geographic units into contiguous regions under constraints), facility location (siting facilities to serve demand across a network), and transportation-oriented modeling. The library integrates tightly with geopandas for spatial data handling, libpysal for spatial weights and connectivity, and pulp for constraint programming, allowing you to define optimization objectives and constraints over geographic features.

Typical workflows involve loading geographic data as GeoDataFrames, defining spatial relationships through weights matrices, and instantiating a model class (like MaxPHeuristic for regionalization or MCLP for facility location) with your data and parameters. The library handles the translation to an optimization problem, solves it via an external solver, and returns region assignments or facility locations as labels you can map back to your original data. It's designed for researchers and practitioners working with spatial planning, urban design, or resource allocation problems where geography and adjacency constraints matter.

Use it for:

  • Partition a country into regions for administrative planning or data collection while respecting population thresholds and geographic contiguity.
  • Locate emergency service facilities (hospitals, fire stations) to maximize coverage of demand points across a street network.
  • Group census tracts or neighborhoods into homogeneous clusters for analysis while maintaining spatial connectivity.
  • Solve max-p-regions problems to find the minimum number of regions that satisfy a population or attribute threshold.
  • Model transportation networks to optimize routing or service delivery under distance and capacity constraints.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Spopt solves spatial optimization problems including regionalization, facility location, and transportation-oriented modeling using geographic data and constraint-based algorithms.

Yes. Spopt is actively maintained, has no known vulnerabilities, installs with low friction, and fills a specific niche in spatial optimization that is not easily replicated by combining other packages. Install it if you are solving regionalization, facility location, or network-based optimization problems on geographic data; skip it if your work is purely aspatial or does not require constraint-based optimization.

Install

spopt on PyPI

pip

pip install spopt

uv

uv add spopt

poetry

poetry add spopt

Installing spopt

Before you install

Low friction installation with a pure-Python wheel. Actively maintained as of July 2026 with a stable release cycle; 13 runtime dependencies are all mature, widely-used scientific libraries.

License in practice

BSD 3-Clause is permissive; you may use, modify, and distribute spopt freely in commercial or proprietary projects provided you retain the license notice.

Quickstart

pip install spopt

import spopt
import geopandas
import libpysal
import numpy

mexico = geopandas.read_file(libpysal.examples.get_path("mexicojoin.shp"))
w = libpysal.weights.Queen.from_dataframe(mexico)
model = spopt.region.MaxPHeuristic(mexico, w, ["PCGDP1950"], "count", 4, 2)
model.solve()
mexico["regions"] = model.labels_

Requires Python 3.11 or later; pulp solver backend needs an external optimization engine (CBC is included by default).

Verify before relying

  • Performance characteristics and scalability limits for large geographic datasets are not quantified in the fact sheet.
  • Whether the package supports alternative solvers beyond pulp's default CBC backend.

Package facts

License BSD 3-Clause (permissive)
Python support supports the current Python release (>=3.11)
Install friction low — pure-Python wheel
Runtime dependencies 13 — geopandas, libpysal, mapclassify, networkx, numpy, pandas, pointpats, pulp, scikit-learn, scipy, shapely, spaghetti, tqdm
Maintenance actively maintained — 396 days since the last release
Last repo commit
First released
Downloads 102,102/month — #12,891 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: spopt-0.7.0-py3-none-any.whl

Keywords: spatial, optimization

Intended Audience :: Science/ResearchLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Topic :: Scientific/Engineering :: GIS

Tags

spatial optimization regionalizationfacility location modelinggeographic clustering constraintsspatial partitioning algorithmsnetwork-based optimizationgeopandas optimizationmax-p regions problem
spatial-optimizationregionalizationfacility-location

More GIS packages

Further reading