Skip to main content

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

  • --version print version and exit
  • --validate validate GeoJSON file, and print the error message if it is not valid, without attempting to fix it.
  • --flip Flip coordinates order
  • -o, --output-method [overwrite|new_file|print]
    • Default is new_file, where gjf will output fixed GeoJSON object to file with the postfix _fixed. Whereas overwrite will write the fixed GeoJSON object to the source file, overwriting the original file in process. Lastly, print will output the fixed GeoJSON object on the terminal
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gjf-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

gjf-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file gjf-0.1.0.tar.gz.

File metadata

  • Download URL: gjf-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 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

Hashes for gjf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2a757d5b55484ffe2911ee3810dbfca8f98fbeb54f9124d86bb6f8358cf9999f
MD5 2306012574fce5e8e78849b454316af0
BLAKE2b-256 b691c016dc48a35af84a07b4c256a8786eed156e1fe2f8c02544a8a1221c31d0

See more details on using hashes here.

File details

Details for the file gjf-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gjf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 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

Hashes for gjf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de3b05e26ba99c0cbb69f0c620725695dfc0f0ead9b09a09ba280b5fc79d22e9
MD5 69cf4689e93e8fa64abfdd4bb096a288
BLAKE2b-256 78229f2ca26b0b5a325c76949a03bc38f97565f23071263e8cf058bbd0de19f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page