cligj - Click parameters for GeoJSON CLIs
cligj provides a collection of reusable Click parameter and option decorators specifically designed for building command-line interfaces that interact with GeoJSON data. It simplifies handling GeoJSON input/output, feature processing, and related geospatial concerns within Click applications. The current version is 0.7.2, and it maintains a stable release cadence typical for a mature utility library.
Warnings
- deprecated The `cligj.old_precision_opt` decorator is deprecated. While still functional, it's recommended to switch to `cligj.precision_opt` for explicit control over GeoJSON floating-point precision.
- gotcha Users often confuse `cligj.features_in_info` and `cligj.io_in_info`. `features_in_info` is for iterating individual GeoJSON features, typically from a FeatureCollection or a GeoJSON sequence. `io_in_info` provides file-like objects for the entire input/output stream, suitable for commands that read or write a single GeoJSON object or need byte-level control.
- gotcha While `cligj` technically supports Python 2.7, Python 2 reached End-of-Life in 2020. New projects and ongoing development should exclusively target Python 3. Although the library's `requires_python` range supports 2.7, relying on it for new work is discouraged and may lead to compatibility issues with other modern dependencies.
Install
-
pip install cligj
Imports
- features_in_info
from cligj import features_in_info
- io_in_info
from cligj import io_in_info
- precision_opt
from cligj import precision_opt
- use_rs_opt
from cligj import use_rs_opt
- interleaved_opt
from cligj import interleaved_opt
Quickstart
import click
import json
import sys
from cligj import features_in_info
@click.command()
@features_in_info
def cli(src_features):
"""
Reads GeoJSON features from stdin, adds a feature index to properties,
and writes the modified features to stdout as a GeoJSON sequence.
Usage example:
echo '{"type":"Feature","properties":{},"geometry":null}' | python your_script.py
"""
for f, i in src_features:
f['properties']['f_idx'] = i['f_idx']
click.echo(json.dumps(f))
if __name__ == '__main__':
cli()