Validates and fixes GeoJSON
Project description
Validate and automatically fixes invalid GeoJSON. 🌎 Webapp and 🐍 Python package.
The only tool that addresses all issues:
- Invalid GeoJSON according to specification: e.g. duplicate nodes, wrong winding order, unclosed
- Problematic with some tools & APIs: e.g. self-intersection, holes, crossing anti-meridian
🎈 Try it out: geojson-validator webapp 🎈
Python package
Installation
pip install geojson-validator
Validate GeoJSON
Input can be any GeoJSON (dictionary, filepath, url), shapely geometry, or anything with a __geo_interface__
.
import geojson_validator
geojson_input = {'type': 'FeatureCollection',
'features': [{'type': 'Feature', 'geometry':
{'type': 'Polygon', 'coordinates': [[[-59.758285, 8.367035], ...]]}}]}
geojson_validator.validate(geojson_input)
The result gives the reason and positional index of the invalid geometry.
{"invalid":
{"duplicate_nodes": [2]},
"problematic":
{"self_intersection": [0, 2],
"crosses_antimeridian": [1]},
"count_geometry_types":
{"Polygon": 2,
"MultiPolygon": 1}}
Fix GeoJSON
Coming Soon!
Parameters
It is possible to select only specific criteria for validation and fixing. For comprehensive criteria descriptions, see the geojson-invalid-geometry list.
# Invalid according to the GeoJSON specification
criteria_invalid = ["unclosed", "duplicate_nodes", "less_three_unique_nodes", "exterior_not_ccw",
"interior_not_cw", "inner_and_exterior_ring_intersect", "crs_defined",
"outside_lat_lon_boundaries"]
# Problematic with some tools & APIs
criteria_problematic = ["holes", "self_intersection", "excessive_coordinate_precision",
"more_than_2d_coordinates", "crosses_antimeridian"]
geojson_validator.validate(geojson, criteria_invalid, criteria_problematic)
TODO:
- Put on website projects
- Automatically fix geometries
- Release 0.1, delete 0.0.1
- Check for incorrect geometry data type in type vs. geometry pattern
- bbox order and other criteria
- Multihtreading?
- Add tests for invalid/prob for each geometry type (gpt)
- refactor main
- add bbox option?
No:
- Filsupport wkt etc. that would require more dependencies.
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
geojson-validator-0.1.0.tar.gz
(12.0 kB
view hashes)
Built Distribution
Close
Hashes for geojson_validator-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9e9b6a92d5d8edc9436ca5018aa016e0f42e766ad7070dfcd13a21bd9b5f24a |
|
MD5 | fc62ab4ef097c1c91fb1bfe7e831292c |
|
BLAKE2b-256 | 0cd8ba4f05c211d0578264b277562ec2ceb80fe2403109d37bc1a8a665c4d5a2 |