gjf: A tool for fixing invalid GeoJSON objects
The goal of this tool is to make it as easy as possible to fix invalid GeoJSON objects through Python or Command Line.
Installation
pip install gjf
Verify installation by running
gjf --version
Features
- Fix all types of GeoJSON objects, including FeatureCollection and Geometry Collection. If there is nothing to fix the object will be returned as is.
- Can validate GeoJSON objects, and print explanations if the object is not valid.
- Can be used within Python or command line
Usage
Python
Say, you have a GeoJSON object defined as follows:
obj = {"type":"Polygon","coordinates":[[[45.892166,25.697688],[45.894522,25.696483],[45.897131,25.695144],[45.898814,25.694268],[45.900496,25.693394],[45.901284,25.692983],[45.903946,25.697312],[45.894791,25.701933],[45.894621,25.701657],[45.892593,25.698379],[45.892166,25.697688]],[[45.892086,25.697729],[45.892166,25.697688],[45.892086,25.697729]]]}
You can simply call apply_fixes_if_needed
from gjf.geojson_fixer import apply_fixes_if_needed
fixed_obj = apply_fixes_if_needed(obj)
You can also flip coordinates order by toggling flip_coords
from gjf.geojson_fixer import apply_fixes_if_needed
fixed_obj_with_flipped_coordinates = apply_fixes_if_needed(obj, flip_coords=True)
You can also check whether a GeoJSON object is valid or not by calling validity
from gjf.geojson_fixer import validity
validity(obj)
Will result ('invalid', ['Too few points in geometry component[45.892086 25.697729]', ''])
CLI
gjf invalid.geojson
gjf will fix the file, and output to invalid_fixed.geojson by default. If you need the output directed in another way you can use --output-method as directed below. It is also possible to fix multiple files, as below.
gjf invalid_1.geojson invalid_2.geojson
Above will output fixed GeoJSON objects to invalid_1_fixed.geojson and invalid_2_fixed.geojson.
CLI Arguments
--versionprint version and exit--validatevalidate GeoJSON file, and print the error message if it is not valid, without attempting to fix it.--flipFlip coordinates order-o, --output-method [overwrite|new_file|print]- Default is
new_file, wheregjfwill output fixed GeoJSON object to file with the postfix_fixed. Whereasoverwritewill write the fixed GeoJSON object to the source file, overwriting the original file in process. Lastly,printwill output the fixed GeoJSON object on the terminal
- Default is
gjf --output-method print invalid.geojson
This would print fixed invalid.geojson on the terminal
Issues
Feel free to open an issue if you have any problems.
Special Thanks
Metadata
Release files for gjf 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gjf-0.1.2.tar.gz | 5.8 kB | Without provenance | Details for gjf-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gjf-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for gjf-0.1.2-py3-none-any.whl |
Total release size: 12.2 kB
Release files / gjf-0.1.2.tar.gz
| Download URL | gjf-0.1.2.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f3d141a64d4fa655bd1a5e79ed79c4304f658520f649594af5d25fa5eade523
|
|
BLAKE2b-256 checksum How to use checksums |
d2ad6e8e8d6ca8bcf0ce8e0630a5c4bb5a652ee10b37df37d0730fa3a0a2836a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Release files / gjf-0.1.2-py3-none-any.whl
| Download URL | gjf-0.1.2-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aef2f6f38f7fd2dbf629328238641e1a1251931e3b3d6bd0c25a1a2c1bea5a20
|
|
BLAKE2b-256 checksum How to use checksums |
df861750ed917534e97dd4ed54b5c929fde087ce98ef3cad42c0030711630ffa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Security for gjf 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.