A Python library for enforcing polygon ring winding order in GeoJSON
Project description
geojson-rewind
A Python library for enforcing polygon ring winding order in GeoJSON
The GeoJSON spec mandates the right hand rule:
A linear ring MUST follow the right-hand rule with respect to the area it bounds, i.e., exterior rings are counterclockwise, and holes are clockwise.
This helps you generate compliant Polygon and MultiPolygon geometries.
Note: Co-ordinates in the input data are assumed to be WGS84 with (lon, lat) ordering, as per RFC 7946. Input with co-ordinates using any other CRS may lead to unexpected results.
Installation
pip install geojson-rewind
Usage
As a Library
Enforce RFC 7946 ring winding order (input/output is a GeoJSON string):
>>> from geojson_rewind import rewind
>>> input = """{
... "geometry": { "coordinates": [ [ [100, 0],
... [100, 1],
... [101, 1],
... [101, 0],
... [100, 0]]],
... "type": "Polygon"},
... "properties": {"foo": "bar"},
... "type": "Feature"}"""
>>> output = rewind(input)
>>> output
'{"geometry": {"coordinates": [[[100, 0], [101, 0], [101, 1], [100, 1], [100, 0]]], "type": "Polygon"}, "properties": {"foo": "bar"}, "type": "Feature"}'
>>> type(output)
<class 'str'>
Enforce RFC 7946 ring winding order (input/output is a python dict):
>>> from geojson_rewind import rewind
>>> input = {
... 'geometry': { 'coordinates': [ [ [100, 0],
... [100, 1],
... [101, 1],
... [101, 0],
... [100, 0]]],
... 'type': 'Polygon'},
... 'properties': {'foo': 'bar'},
... 'type': 'Feature'}
>>> output = rewind(input)
>>> output
{'geometry': {'coordinates': [[[100, 0], [101, 0], [101, 1], [100, 1], [100, 0]]], 'type': 'Polygon'}, 'properties': {'foo': 'bar'}, 'type': 'Feature'}
>>> type(output)
<class 'dict'>
On the Console
# Enforce ring winding order on a GeoJSON file
$ rewind in.geojson > out.geojson
# fetch GeoJSON from the web and enforce ring winding order
$ curl "https://myserver.com/in.geojson" | rewind
Acknowledgements
geojson-rewind
is a python port of Mapbox's javascript geojson-rewind package. Credit to Tom MacWright and contributors.
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
Built Distribution
File details
Details for the file geojson-rewind-1.0.1.tar.gz
.
File metadata
- Download URL: geojson-rewind-1.0.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.4.0-67-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 144eed294b0dea2e5a84257dec8dbf98b4db874f3b7092bc6bd3e782f826be5c |
|
MD5 | f0891cee652906cfce8a3cf09de9ccdc |
|
BLAKE2b-256 | 96a28db229e15d71f161e888f72447eece41e5cbf5f1044ecc4602f4da949ebc |
File details
Details for the file geojson_rewind-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: geojson_rewind-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.4.0-67-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61293a4ad63cabd5885ae504679f9375bbaeeff4b813e5fc9d4298bf59fafe39 |
|
MD5 | 53d335855f5d1a4b9a53c7c1e47197ce |
|
BLAKE2b-256 | 8429352e691f5d2476646dffa4d61f12e4b2de1e8d522f7050db3466029379c9 |