PyGeoIf

1.6.0 · active · verified Tue Apr 14

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.

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →