{"id":578,"library":"shapely","title":"Shapely","description":"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.","status":"active","version":"2.1.2","language":"python","source_language":"en","source_url":"https://github.com/shapely/shapely","tags":["GIS","geometry","geospatial","vector","spatial analysis","NumPy"],"install":[{"cmd":"pip install shapely","lang":"bash","label":"Install with pip"},{"cmd":"conda install shapely --channel conda-forge","lang":"bash","label":"Install with Conda (recommended)"}],"dependencies":[{"reason":"Shapely wraps the GEOS C++ library; it is dynamically linked. Binary wheels bundle GEOS, but source installs or specific environments might require manual GEOS installation/discovery.","package":"GEOS","optional":false},{"reason":"Required for vectorized (ufunc) operations and integration with array-like data, especially since Shapely 2.0.","package":"numpy","optional":false}],"imports":[{"symbol":"Point","correct":"from shapely import Point"},{"symbol":"Polygon","correct":"from shapely import Polygon"},{"symbol":"box","correct":"from shapely import box"},{"note":"Geometry subclasses are now available directly in the top-level `shapely` namespace (since 2.0), making `from shapely import Point` the preferred modern import. `from shapely.geometry import Point` still works for individual geometry types.","wrong":"import shapely.geometry.Point","symbol":"shapely.geometry.Point","correct":"from shapely.geometry import Point"},{"note":"The `shapely.geos` module is deprecated in 2.1.x; GEOS-version related attributes are now directly available from the top-level `shapely` namespace (e.g., `shapely.GEOS_VERSION`).","wrong":"import shapely.geos","symbol":"shapely.geos","correct":"from shapely import GEOS_VERSION"},{"note":"The `shapely.vectorized` module is deprecated in 2.1.x. Use top-level vectorized functions like `shapely.contains_xy` and `shapely.intersects_xy` instead.","wrong":"from shapely.vectorized import contains","symbol":"shapely.vectorized.contains","correct":"from shapely import contains_xy"}],"quickstart":{"code":"import shapely\nfrom shapely import Point, Polygon\n\n# Create a point and a polygon\npoint = Point(0, 0)\npolygon = Polygon([(0, 0), (1, 1), (1, 0)])\n\n# Perform a spatial operation\nintersection = point.intersection(polygon)\n\nprint(f\"Point: {point}\")\nprint(f\"Polygon: {polygon}\")\nprint(f\"Intersection: {intersection}\")\nprint(f\"Point within polygon: {polygon.contains(point)}\")\n\n# Example of a vectorized operation (Shapely 2.0+)\nimport numpy as np\ngeoms = np.array([Point(0.5, 0.5), Point(1.5, 0.5)])\nprint(f\"\\nVectorized contains: {shapely.contains(polygon, geoms)}\")","lang":"python","description":"This quickstart demonstrates creating basic `Point` and `Polygon` geometries and performing a simple spatial intersection. It also includes an example of a vectorized operation using NumPy arrays, a key performance feature introduced in Shapely 2.0."},"warnings":[{"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.","message":"Shapely 2.0 introduced a complete internal refactor (merging PyGEOS), making geometries immutable and changing how multi-part geometries behave.","severity":"breaking","affected_versions":"2.0.0+"},{"fix":"Use `np.asarray(geom.coords)` to convert geometry coordinates to a NumPy array.","message":"Direct conversion of geometry objects to NumPy arrays (`np.asarray(geom)`) is deprecated and removed in 2.0.","severity":"breaking","affected_versions":"2.0.0+"},{"fix":"Review the `STRtree` documentation for the updated `query()` method, which merges `query()` and `query_bulk()` and directly includes predicate evaluation.","message":"The `STRtree` API changed significantly in Shapely 2.0. Operations now return indices of input geometries instead of the geometries themselves.","severity":"breaking","affected_versions":"2.0.0+"},{"fix":"Always pass such parameters as keyword arguments (e.g., `geom.buffer(distance, quad_segs=16)` instead of `geom.buffer(distance, 16)`).","message":"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.","severity":"deprecated","affected_versions":"2.1.0+"},{"fix":"Always install Shapely via `conda install shapely --channel conda-forge` when using Conda to ensure proper GEOS linking.","message":"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.","severity":"gotcha","affected_versions":"All versions in Conda environments."},{"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.","message":"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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T16:15:44.036Z","next_check":"2026-06-26T00:00:00.000Z","problems":[],"ecosystem":"pypi","meta_description":null,"install_score":97,"install_tag":"verified","quickstart_score":77,"quickstart_tag":"verified","pypi_latest":"2.1.2","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.32,"mem_mb":8.3,"disk_size":"103.9M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.24,"mem_mb":8.3,"disk_size":"103.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":4,"import_time_s":0.23,"mem_mb":8.3,"disk_size":"97M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.19,"mem_mb":8.3,"disk_size":"97M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.37,"mem_mb":8.6,"disk_size":"112.1M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.38,"mem_mb":8.6,"disk_size":"112.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.9,"import_time_s":0.32,"mem_mb":8.6,"disk_size":"105M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.32,"mem_mb":8.6,"disk_size":"105M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.33,"mem_mb":8.2,"disk_size":"100.4M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.31,"mem_mb":8.2,"disk_size":"100.4M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.7,"import_time_s":0.37,"mem_mb":8.3,"disk_size":"93M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.32,"mem_mb":8.3,"disk_size":"93M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.28,"mem_mb":8.6,"disk_size":"99.9M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.33,"mem_mb":8.6,"disk_size":"99.7M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.7,"import_time_s":0.34,"mem_mb":8.6,"disk_size":"92M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.37,"mem_mb":8.6,"disk_size":"92M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":1,"wheel_type":null,"failure_reason":"build_error","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":4.6,"import_time_s":0.3,"mem_mb":7.3,"disk_size":"105M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.23,"mem_mb":7.3,"disk_size":"105M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":0}]}}