Skip to main content

geometry, low on dependencies

Project description

geometry, low on dependencies

glod is a Python package for handling simple geospatial geometries in a low-dependency way. It was developed to create a lightweight GIS means of interacting with web APIs which return spatial data without needing to rely on more extensive spatial packages.

The goal of this project, as the name suggests, is to keep the number of external dependencies low!

Dynamic TOML Badge
Dynamic TOML Badge

Features


  • Supports 2D and 3D singlepart geometries (Point, LineString, Polygon) and their multi-part equivalents (MultiPoint, MultiLineString, MultiPolygon)
  • Store attributes alongside geometries with the Feature object
  • Group features as FeatureCollection objects
  • Test geometric intersections between any two geometries with Geometry.intersects()
  • Access geometric properties (bounds, WKT, GeoJSON, CRS, has_z)
  • Construct geometries from WKT, GeoJSON, coordinate arrays, bounding boxes, or any object implementing __geo_interface__
  • Import/export FeatureCollection as GeoJSON files or CSV with a WKT geometry column
  • Implements the __geo_interface__ protocol for interoperability with other packages
  • Optional: uses pyproj for coordinate transforms (see Installation)

Installation


Usage

Typical usage

from glod import Feature, FeatureCollection, Geometry

# assume some data returned by an API
data = [
    {'id': 'point1', 'easting': 12, 'northing': 34, 'date': 2021},
    {'id': 'point2', 'easting': 56, 'northing': 78, 'date': 2023}
]
api_crs = 'EPSG:27700'

# turn each item of data into a glod Feature with geometry and attributes
all_features = []
for item in data:
    geometry = Geometry.from_coordinates(coordinates=(item['easting'], item['northing']), crs=api_crs)
    attributes = {'id': item['id'], 'date': item['date']}
    all_features.append(Feature(geometry, attributes))

# collate features as a FeatureCollection
collection = FeatureCollection(all_features)

# write to a geojson
geojson = collection.to_geojson('api_data.geojson')

# iterate through features
for feature in collection:
    print(feature.attributes['id'], feature.geometry.wkt, feature.geometry.crs)

# point1 POINT (12 34) EPSG:27700
# point2 POINT (56 78) EPSG:27700

Geometry construction

from glod import Geometry
from glod.geometry import Point, Polygon

# from WKT
line = Geometry.from_wkt("LINESTRING (0 0, 1 1, 2 0)", crs="EPSG:27700")

# from GeoJSON dict
point = Geometry.from_geojson({"type": "Point", "coordinates": [1.0, 2.0]}, crs="EPSG:27700")

# from a coordinate array (type inferred from structure)
poly = Geometry.from_coordinates([[[0, 0], [1, 0], [1, 1], [0, 0]]])

# from a bounding box
bbox = Polygon.from_bounds((0, 0, 10, 10), crs="EPSG:27700")

# from any object implementing __geo_interface__ (e.g. shapely)
glod_geom = Geometry.from_object(shapely_geom, crs="EPSG:27700")

Test geometry intersections

from glod import Geometry

geometry1 = Geometry.from_wkt("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))", crs="EPSG:3857")
geometry2 = Geometry.from_wkt("POLYGON ((5 5, 5 15, 15 15, 15 5, 5 5))", crs="EPSG:3857")

print(geometry1.intersects(geometry2))
# True

CSV I/O

# write to CSV with a WKT geometry column
collection.to_csv("data.csv")

# read back, supplying the CRS since CSV has no standard CRS field
collection2 = FeatureCollection.from_csv("data.csv", crs="EPSG:27700")

Coordinate Reference System (CRS) transforms

Transformation is handled by pyproj. Because this is an optional dependency, it must be internally enabled within glod by calling glod.config.set_use_pyproj(True) before running your code.

By default pyproj will be disabled every run time unless specifically enabled.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glod-0.1.1.tar.gz (39.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glod-0.1.1-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file glod-0.1.1.tar.gz.

File metadata

  • Download URL: glod-0.1.1.tar.gz
  • Upload date:
  • Size: 39.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for glod-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4013c08ed956e812893be618a2429f374af83d64ce556b303c12e33f8b0f0b0d
MD5 9eb8b6a86cedf41d0212d8d184dcde97
BLAKE2b-256 5037180c146ac61b5510896984a747258eda10225747a10d7fd2ef8e7d09421e

See more details on using hashes here.

Provenance

The following attestation bundles were made for glod-0.1.1.tar.gz:

Publisher: publish.yml on michaelreed-geo/glod

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glod-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: glod-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for glod-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eea4c8687cc998bdb097df4e381972df960300a46d2eeae2f52840b31c7acac0
MD5 6a9ac95c545a5d32510bf9ec439b97a6
BLAKE2b-256 f83fbdb55bda1a39b36f11ab4da6ff16ddb57dd8e748dd7ed5b50d43745fb311

See more details on using hashes here.

Provenance

The following attestation bundles were made for glod-0.1.1-py3-none-any.whl:

Publisher: publish.yml on michaelreed-geo/glod

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page