Skip to content

Commit

Permalink
Added CHANGELOG.md + LICENSE + README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yazeed44 committed Jun 20, 2021
1 parent 04ee1a6 commit 13e1062
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 0.1.0 (2021-06-20)
- 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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2021 Yazeed Almuqwishi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 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
```shell
pip install gjf
```
Verify installation by running
```shell
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:
```python
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`
```python
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`
```python
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`
```python
from gjf.geojson_fixer import validity
validity(obj)
```
Will result `('invalid', ['Too few points in geometry component[45.892086 25.697729]', ''])`
### CLI
```shell
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.
```shell
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

```shell
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
- [Shapely](https://github.com/Toblerity/Shapely)
- [geojson-rewind](https://github.com/chris48s/geojson-rewind)

0 comments on commit 13e1062

Please sign in to comment.