Shapely
raw JSON → 2.1.2 verified Tue May 12 auth: no python install: verified quickstart: verified
Shapely is a BSD-licensed Python package for manipulation and analysis of planar geometric objects. It wraps the widely deployed open-source geometry library GEOS (the engine of PostGIS) to provide both a feature-rich Geometry interface for scalar geometries and high-performance NumPy ufuncs for operations on arrays of geometries. The current version is 2.1.2, with a regular release cadence that includes bug fixes, new features, and compatibility updates for Python and GEOS versions.
pip install shapely Warnings
breaking Shapely 2.0 introduced a complete internal refactor (merging PyGEOS), making geometries immutable and changing how multi-part geometries behave. ↓
fix Geometries are now immutable and hashable; do not attempt in-place modification. For multi-part geometries (e.g., `MultiPolygon`), they are no longer sequence-like (no `len()`, not iterable, not indexable) – use the `.geoms` attribute to access individual parts.
breaking Direct conversion of geometry objects to NumPy arrays (`np.asarray(geom)`) is deprecated and removed in 2.0. ↓
fix Use `np.asarray(geom.coords)` to convert geometry coordinates to a NumPy array.
breaking The `STRtree` API changed significantly in Shapely 2.0. Operations now return indices of input geometries instead of the geometries themselves. ↓
fix Review the `STRtree` documentation for the updated `query()` method, which merges `query()` and `query_bulk()` and directly includes predicate evaluation.
deprecated Many function parameters, especially boolean flags like `normalized` or `include_z`, are being transitioned to keyword-only arguments. Passing them positionally is deprecated and raises warnings. ↓
fix Always pass such parameters as keyword arguments (e.g., `geom.buffer(distance, quad_segs=16)` instead of `geom.buffer(distance, 16)`).
gotcha When installing Shapely in a Conda environment, installing via `pip install shapely` can sometimes lead to issues with GEOS library discovery, potentially bundling an outdated GEOS. ↓
fix Always install Shapely via `conda install shapely --channel conda-forge` when using Conda to ensure proper GEOS linking.
gotcha Shapely is a planar geometry library; Z coordinates are generally ignored in geometric analysis, and geometries differing only in Z are not distinguished. `LineString([(0, 0, 0), (0, 0, 1)])` results in an invalid line with zero length. ↓
fix Be aware that Shapely's core operations are 2D. While geometries can store Z/M values (especially since 2.1.0), most analytical methods primarily use X and Y coordinates. Validate your geometry inputs to avoid unexpected behavior with Z differences.
Install
conda install shapely --channel conda-forge Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.32s 103.9M
3.10 alpine (musl) - - 0.24s 103.9M
3.10 slim (glibc) wheel 4.0s 0.23s 97M
3.10 slim (glibc) - - 0.19s 97M
3.11 alpine (musl) wheel - 0.37s 112.1M
3.11 alpine (musl) - - 0.38s 112.1M
3.11 slim (glibc) wheel 3.9s 0.32s 105M
3.11 slim (glibc) - - 0.32s 105M
3.12 alpine (musl) wheel - 0.33s 100.4M
3.12 alpine (musl) - - 0.31s 100.4M
3.12 slim (glibc) wheel 3.7s 0.37s 93M
3.12 slim (glibc) - - 0.32s 93M
3.13 alpine (musl) wheel - 0.28s 99.9M
3.13 alpine (musl) - - 0.33s 99.7M
3.13 slim (glibc) wheel 3.7s 0.34s 92M
3.13 slim (glibc) - - 0.37s 92M
3.9 alpine (musl) build_error - - - -
3.9 alpine (musl) - - - -
3.9 slim (glibc) wheel 4.6s 0.30s 105M
3.9 slim (glibc) - - 0.23s 105M
Imports
- Point
from shapely import Point - Polygon
from shapely import Polygon - box
from shapely import box - shapely.geometry.Point wrong
import shapely.geometry.Pointcorrectfrom shapely.geometry import Point - shapely.geos wrong
import shapely.geoscorrectfrom shapely import GEOS_VERSION - shapely.vectorized.contains wrong
from shapely.vectorized import containscorrectfrom shapely import contains_xy
Quickstart verified last tested: 2026-04-23
import shapely
from shapely import Point, Polygon
# Create a point and a polygon
point = Point(0, 0)
polygon = Polygon([(0, 0), (1, 1), (1, 0)])
# Perform a spatial operation
intersection = point.intersection(polygon)
print(f"Point: {point}")
print(f"Polygon: {polygon}")
print(f"Intersection: {intersection}")
print(f"Point within polygon: {polygon.contains(point)}")
# Example of a vectorized operation (Shapely 2.0+)
import numpy as np
geoms = np.array([Point(0.5, 0.5), Point(1.5, 0.5)])
print(f"\nVectorized contains: {shapely.contains(polygon, geoms)}")