Registry / serialization / pygeoif

pygeoif

JSON →
library1.6.0pypypi✓ verified 87d ago

PyGeoIf is a Python library providing a basic, pure-Python implementation of the `__geo_interface__` protocol. It enables the creation and manipulation of standard geospatial vector data types like Point, LineString, and Polygon, along with collections, making it suitable as a lightweight alternative to libraries like Shapely or as a foundation for building custom geospatial tools. The current version is 1.6.0, with an active release cadence, often aligning with Python version support changes and feature enhancements.

pip install pygeoif
INSTALL
IMPORT
SIG · PYGEOIF
P
pygeoif
serializationpythonv1.6.0
Install
1.6s avg
Import
52ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.055s · 18.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.050s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Point
from pygeoif import Point
LineString
from pygeoif import LineString
Polygon
from pygeoif import Polygon
Feature
from pygeoif import Feature
FeatureCollection
from pygeoif import FeatureCollection
from_wkt
from pygeoif import from_wkt
shape
from pygeoif import shape
from pygeoif.geometry import as_shape
The `as_shape` function was renamed to `shape` in version 1.0.0. The direct import from `pygeoif` is preferred.

This quickstart demonstrates how to create various geometry types (Point, LineString, Polygon), a Feature with properties, and how to import geometry from a Well-Known Text (WKT) string using `pygeoif`.

from pygeoif import Point, LineString, Polygon, Feature, from_wkt # Create a Point p = Point(1.0, -1.0) print(f"Point: {p}") print(f"Point Geo Interface: {p.__geo_interface__}") # Create a LineString l = LineString([(0, 0), (1, 1), (2, 0)]) print(f"LineString: {l}") # Create a Polygon with a hole exterior = [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)] interior = [(2, 2), (2, 8), (8, 8), (8, 2), (2, 2)] poly = Polygon(exterior, [interior]) print(f"Polygon: {poly.wkt}") # Create a Feature with properties feature_props = {'name': 'My Awesome Feature', 'id': 123} f = Feature(p, feature_props) print(f"Feature geometry type: {f.geometry.geom_type}") print(f"Feature properties: {f.properties}") # Create geometry from WKT wkt_point = from_wkt('POINT (5 10)') print(f"WKT Point: {wkt_point}")
Debug
Known issues
breakingPython 2 support was removed, and the minimum required Python version has changed multiple times. Version 1.0.0 required Python >=3.7. Version 1.6.0 dropped support for Python 3.8, now requiring Python >=3.9.
fix
Ensure your project runs on Python 3.9 or newer when using pygeoif 1.6.0 or later. For older pygeoif versions, check their specific Python requirements.
affects: <1.0.0, 1.0.0-1.5.x
breakingThe `as_shape` function was renamed to `shape` in version 1.0.0 to align with Shapely's API. Direct import `from pygeoif import shape` is the modern approach.
fix
Update imports from `from pygeoif.geometry import as_shape` to `from pygeoif import shape` and adjust calls accordingly.
affects: <1.0.0
breakingGeometries became immutable in version 1.2.0. Attempting to modify attributes of a geometry object (e.g., coordinates of a Point) directly will raise an error.
fix
Instead of modifying existing geometry objects, create new ones with the desired changes. For example, `new_point = Point(x + 1, y)` instead of `point.x += 1`.
affects: <1.2.0
gotchaWhile pygeoif implements the `__geo_interface__` protocol similarly to Shapely, their internal behavior for certain edge cases (e.g., validity checks, operations on degenerate geometries) can differ. This can lead to unexpected results if switching between libraries without thorough testing.
fix
If migrating from or interoperating with Shapely, thoroughly test your code with pygeoif, especially around geometry validation and complex operations. Consult both libraries' documentation for specific behavior details.
affects: All versions
gotcha`GeometryCollection` is part of the GeoJSON specification but is not universally supported across all GIS software or file formats (e.g., Shapefile).
fix
When exchanging data with other GIS tools or formats, be mindful that `GeometryCollection` objects might not be directly ingestible and may require decomposition into simpler geometry types.
affects: All versions
Errors
Common errors & fixes
TypeError: Object does not implement __geo_interface__
This error occurs when attempting to convert an object into a `pygeoif` geometry using `pygeoif.geometry.as_shape()` (or `pygeoif.shape()`) that does not adhere to the `__geo_interface__` protocol or is not a GeoJSON-compatible dictionary.
fix
Ensure the object passed to `as_shape` has a `__geo_interface__` attribute that returns a GeoJSON-like dictionary, or provide a valid GeoJSON-compatible dictionary directly. If using another library, ensure its geometry objects properly expose the `__geo_interface__`. 
```python
from pygeoif import geometry, shape
from shapely.geometry import Point as ShapelyPoint

# Correct: Using an object that implements __geo_interface__ (like Shapely's Point)
p_shapely = ShapelyPoint(1, 1)
py_geom = shape(p_shapely)

# Correct: Using a GeoJSON-compatible dictionary
geojson_dict = {'type': 'Point', 'coordinates': (2, 2)}
py_geom_from_dict = shape(geojson_dict)
```
cannot import name 'as_shape' from 'pygeoif.geometry'
This `ImportError` typically arises when using an older version of `pygeoif` where `as_shape` might not have been directly exposed under `pygeoif.geometry`, or when there's a misunderstanding about its location or intended use, especially in contexts where `shapely.geometry.asShape` (now deprecated in Shapely) was previously used. In modern `pygeoif` (v1.0+), the `shape` function is available directly under the `pygeoif` top-level module.
fix
Import the `shape` function directly from the `pygeoif` top-level module instead of `pygeoif.geometry`. If you specifically need `as_shape` and encounter this, ensure your `pygeoif` version is up-to-date, or use the recommended `shape` function. 
```python
# Incorrect (likely for older versions or if trying to match Shapely's old 'asShape')
# from pygeoif.geometry import as_shape

# Correct way to import and use in pygeoif (v1.0+)
from pygeoif import shape
from pygeoif.geometry import Point

py_point = Point(1, 1)
converted_geom = shape(py_point)
```
AttributeError: 'pygeoif.geometry.X' object has no attribute 'Y'
This error occurs when attempting to call a method or access an attribute on a `pygeoif` geometry object (e.g., `Point`, `LineString`, `Polygon`) that is not implemented by `pygeoif`. This often happens when developers accustomed to `Shapely` try to use `Shapely`-specific advanced geospatial operations (like `buffer`, `intersection`, `difference`, `intersects`, `contains`, etc.) directly on `pygeoif` objects, as `pygeoif` is a lightweight library with a more basic API.
fix
If you require advanced geospatial operations, convert your `pygeoif` geometries to `Shapely` geometries first using `shapely.geometry.shape()`, perform the operations, and then convert back to `pygeoif` if necessary. If only basic properties are needed, consult the `pygeoif` documentation for available attributes (`geom_type`, `bounds`, `wkt`) and methods. 
```python
from pygeoif.geometry import Point
from shapely.geometry import shape as shapely_shape
from shapely.geometry import Point as ShapelyPoint

py_point = Point(0, 0)

# Incorrect (pygeoif Point does not have a 'buffer' method)
# buffered_point = py_point.buffer(10)

# Correct: Convert to Shapely, perform operation, optionally convert back
shapely_point = shapely_shape(py_point)
buffered_shapely_point = shapely_point.buffer(10)

# If you need a pygeoif object again:
from pygeoif import shape as pygeoif_shape
buffered_pygeoif_point = pygeoif_shape(buffered_shapely_point.__geo_interface__)
```
ValueError: Failed to create geometry from WKT: unknown format
This error indicates that the Well-Known Text (WKT) string provided to `pygeoif.from_wkt()` is not in a recognized or valid format. This can happen due to typos, incorrect syntax (e.g., missing parentheses, incorrect coordinate separators), or non-standard WKT variations.
fix
Ensure the WKT string strictly adheres to the OGC Well-Known Text standard (e.g., 'POINT (X Y)', 'LINESTRING (X1 Y1, X2 Y2)', 'POLYGON ((X1 Y1, X2 Y2, X3 Y3, X1 Y1))'). Validate your WKT string with a known good example or a WKT validator if unsure. 
```python
from pygeoif import from_wkt

# Correct WKT string for a Point
point_wkt_valid = 'POINT (10 20)'
point_geom = from_wkt(point_wkt_valid)

# Incorrect WKT string (e.g., missing parentheses, wrong format)
# point_wkt_invalid = 'POINT 10 20'
# point_geom = from_wkt(point_wkt_invalid) # Would raise ValueError

# Correct WKT string for a LineString
linestring_wkt_valid = 'LINESTRING (30 10, 10 30, 40 40)'
linestring_geom = from_wkt(linestring_wkt_valid)
```
AttributeError: 'Point' object has no attribute 'coords'
Users accustomed to libraries like Shapely expect Point objects to have a `coords` attribute, but `pygeoif.Point` exposes coordinates directly via `x`, `y`, and optionally `z` attributes.
fix
Access individual coordinates using `point.x`, `point.y`, or create a tuple `(point.x, point.y)`.
Upgrade
Version history
1.6.0latest on PyPI · released Oct 1, 2025
Audit
Dependencies
pythonrequiredRequires Python 3.9 or newer.
Agent activity
4 hits · last 30 days
node
4
Resources
pygeoif — pip install pygeoif · libregistry