Validates and fixes GeoJSON
Project description
GeoJSON Validator
Validate GeoJSON and automatically fix invalid geometries. Like geojsonhint, but with geometry checks & fixes!
- 🔴 Detects invalid geometries & 🟢 fixes them : Unclosed, wrong winding order etc.
- 🟨 Problematic geometries (for many tools & APIs): Self-intersection, crossing anti-meridian etc.
- Checks 🧬 structure according to GeoJSON specification
- Use Website or Python package
🎈 geojson-validator.streamlit.app in the Browser 🎈
Quickstart Python
# Installation
pip install geojson-validator
Data input can be any type of GeoJSON object, a filepath/url, and anything with a __geo_interface__
(shapely, geopandas etc.).
import geojson_validator
geojson_input = {'type': 'FeatureCollection',
'features': [{'type': 'Feature', 'geometry':
{'type': 'Point', 'coordinates': [-59.758285, 8.367035]}}]}
geojson_validator.validate_structure(geojson_input)
geojson_validator.validate_geometries(geojson_input)
geojson_validator.fix_geometries(geojson_input)
1. Validate GeoJSON structure 🧬
Checks the structure & formatting of the GeoJSON, e.g. required elements, data & geometry types, coordinate array depth etc.
geojson_validator.validate_structure(geojson_input, check_crs=False)
Returns the reasons why the input does not conform to the GeoJSON specification.
Also gives the line location and feature index to more quickly localize the issues.
Example: {"Missing 'type' member": {"line": [4], "feature": [0]}
.
2. Validate geometries 🟥
Checks the GeoJSON geometry objects for inconsistencies and geometric issues. See geojson-invalid-geometry for a detailed description of all invalid and problematic criteria. You can choose to validate only specific criteria, by default all are selected.
# Invalid according to the GeoJSON specification
criteria_invalid = ["unclosed", "less_three_unique_nodes", "exterior_not_ccw",
"interior_not_cw", "inner_and_exterior_ring_intersect"]
# Problematic with some tools & APIs
criteria_problematic = ["holes", "self_intersection", "duplicate_nodes",
"excessive_coordinate_precision", "excessive_vertices",
"3d_coordinates", "outside_lat_lon_boundaries", "crosses_antimeridian"]
geojson_validator.validate_geometries(geojson, criteria_invalid, criteria_problematic)
Returns the reasons (example below) and positional indices of the invalid geometries, e.g. features [0, 3]
. Also indicates if a
sub-geometry of a MultiType geometry make it invalid e.g. {2:[0, 5]}
.
{"invalid":
{"unclosed": [0, 3],
"exterior_not_ccw": [{2:[0, 5]}],
"problematic":
{"crosses_antimeridian": [1]},
"count_geometry_types":
{"Polygon": 3,
"MultiPolygon": 1}}
3. Fix GeoJSON geometries 🟩
Automatically repairs some of the most common categories of invalid geometries.
Always fixes ["unclosed", "exterior_not_ccw", "interior_not_cw"].
Select additional, non-essential fixes with the parameter optional
.
More fixes and helper-functions (for issues that require user descisions) coming soon!
geojson_validator.fix_geometries(geojson_input, optional=["duplicate_nodes"])
The result is a GeoJSON FeatureCollection with the fixed geometries.
FAQ:
- Why not use geojson-pydantic for the schema validation? pydantic error messages a bit convulted (if one coordinate is issing error 4 times), very schema like, not custom, not easy to understand for no nprogrammers. often would need to be translated.
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-validator-0.5.2.tar.gz
.
File metadata
- Download URL: geojson-validator-0.5.2.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 248f966f713ab250677e7328062a81d63963341381e6477a18aea301ec26b6ca |
|
MD5 | 2c045451420acdf52739a2beeb59e336 |
|
BLAKE2b-256 | dd4d1baccc553c18ecddaaae20a09685e8d53196e72eaef98f42d57316059391 |
File details
Details for the file geojson_validator-0.5.2-py3-none-any.whl
.
File metadata
- Download URL: geojson_validator-0.5.2-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74e18d95afbb939fb6a50ab72348f5eb356280818d78cd46146145370c1f16b6 |
|
MD5 | 3a926456205d3aabfd54d056e79b557b |
|
BLAKE2b-256 | 646bcf49cc6c593d7416d2fcdf3cc252613fbb55c59b94921aeabfbda9a5dd28 |