A tool to fix invalid GeoJSON objects
Project description
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
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 gjf-0.1.2.tar.gz.
File metadata
- Download URL: gjf-0.1.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f3d141a64d4fa655bd1a5e79ed79c4304f658520f649594af5d25fa5eade523
|
|
| MD5 |
299ca0122d5c3a2d17c66c3d3e485628
|
|
| BLAKE2b-256 |
d2ad6e8e8d6ca8bcf0ce8e0630a5c4bb5a652ee10b37df37d0730fa3a0a2836a
|
File details
Details for the file gjf-0.1.2-py3-none-any.whl.
File metadata
- Download URL: gjf-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aef2f6f38f7fd2dbf629328238641e1a1251931e3b3d6bd0c25a1a2c1bea5a20
|
|
| MD5 |
3d60124d2e193432865d57712a098936
|
|
| BLAKE2b-256 |
df861750ed917534e97dd4ed54b5c929fde087ce98ef3cad42c0030711630ffa
|