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!
Features
- Supports 2D and 3D singlepart geometries (Point, LineString, Polygon) and their multi-part equivalents (MultiPoint, MultiLineString, MultiPolygon)
- Store attributes alongside geometries with the
Featureobject - Group features as
FeatureCollectionobjects - 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
FeatureCollectionas 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4013c08ed956e812893be618a2429f374af83d64ce556b303c12e33f8b0f0b0d
|
|
| MD5 |
9eb8b6a86cedf41d0212d8d184dcde97
|
|
| BLAKE2b-256 |
5037180c146ac61b5510896984a747258eda10225747a10d7fd2ef8e7d09421e
|
Provenance
The following attestation bundles were made for glod-0.1.1.tar.gz:
Publisher:
publish.yml on michaelreed-geo/glod
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
glod-0.1.1.tar.gz -
Subject digest:
4013c08ed956e812893be618a2429f374af83d64ce556b303c12e33f8b0f0b0d - Sigstore transparency entry: 1103329149
- Sigstore integration time:
-
Permalink:
michaelreed-geo/glod@4312c3d62c3863873e88effe889f88adae6befd5 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/michaelreed-geo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4312c3d62c3863873e88effe889f88adae6befd5 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eea4c8687cc998bdb097df4e381972df960300a46d2eeae2f52840b31c7acac0
|
|
| MD5 |
6a9ac95c545a5d32510bf9ec439b97a6
|
|
| BLAKE2b-256 |
f83fbdb55bda1a39b36f11ab4da6ff16ddb57dd8e748dd7ed5b50d43745fb311
|
Provenance
The following attestation bundles were made for glod-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on michaelreed-geo/glod
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
glod-0.1.1-py3-none-any.whl -
Subject digest:
eea4c8687cc998bdb097df4e381972df960300a46d2eeae2f52840b31c7acac0 - Sigstore transparency entry: 1103329221
- Sigstore integration time:
-
Permalink:
michaelreed-geo/glod@4312c3d62c3863873e88effe889f88adae6befd5 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/michaelreed-geo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4312c3d62c3863873e88effe889f88adae6befd5 -
Trigger Event:
release
-
Statement type: