Click params for commmand line interfaces to GeoJSON
Project description
Common arguments and options for GeoJSON processing commands, using Click.
cligj is for Python developers who create command line interfaces for geospatial data. cligj allows you to quickly build consistent, well-tested and interoperable CLIs for handling GeoJSON.
Arguments
files_in_arg Multiple files
files_inout_arg Multiple files, last of which is an output file.
features_in_arg GeoJSON Features input which accepts multiple representations of GeoJSON features and returns the input data as an iterable of GeoJSON Feature-like dictionaries
Options
verbose_opt
quiet_opt
format_opt
JSON formatting options
indent_opt
compact_opt
Coordinate precision option
precision_opt
Geographic (default), projected, or Mercator switch
projection_geographic_opt
projection_projected_opt
projection_mercator_opt
Feature collection or feature sequence switch
sequence_opt
use_rs_opt
GeoJSON output mode option
geojson_type_collection_opt
geojson_type_feature_opt
def geojson_type_bbox_opt
Example
Here’s an example of a command that writes out GeoJSON features as a collection or, optionally, a sequence of individual features. Since most software that reads and writes GeoJSON expects a text containing a single feature collection, that’s the default, and a LF-delimited sequence of texts containing one GeoJSON feature each is a feature that is turned on using the --sequence option. To write sequences of feature texts that conform to the GeoJSON Text Sequences standard (and might contain pretty-printed JSON) with the ASCII Record Separator (0x1e) as a delimiter, use the --rs option
import click
import cligj
import json
def process_features(features):
for feature in features:
# TODO process feature here
yield feature
@click.command()
@cligj.features_in_arg
@cligj.sequence_opt
@cligj.use_rs_opt
def pass_features(features, sequence, use_rs):
if sequence:
for feature in process_features(features):
if use_rs:
click.echo(u'\x1e', nl=False)
click.echo(json.dumps(feature))
else:
click.echo(json.dumps(
{'type': 'FeatureCollection',
'features': list(process_features(features))}))
On the command line, the generated help text explains the usage
Usage: pass_features [OPTIONS] FEATURES...
Options:
--sequence / --no-sequence Write a LF-delimited sequence of texts
containing individual objects or write a single
JSON text containing a feature collection object
(the default).
--rs / --no-rs Use RS (0x1E) as a prefix for individual texts
in a sequence as per http://tools.ietf.org/html
/draft-ietf-json-text-sequence-13 (default is
False).
--help Show this message and exit.
And can be used like this
$ cat data.geojson
{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]}
$ pass_features data.geojson
{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]}
$ cat data.geojson | pass_features
{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]}
$ cat data.geojson | pass_features --sequence
{'type': 'Feature', 'id': '1'}
{'type': 'Feature', 'id': '2'}
$ cat data.geojson | pass_features --sequence --rs
^^{'type': 'Feature', 'id': '1'}
^^{'type': 'Feature', 'id': '2'}
In this example, ^^ represents 0x1e.
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
File details
Details for the file cligj-0.7.2.tar.gz
.
File metadata
- Download URL: cligj-0.7.2.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4bc13d623356b373c2c27c53dbd9c68cae5d526270bfa71f6c6fa69669c6b27 |
|
MD5 | 357ed96c1c52c8d276352387bb5909f6 |
|
BLAKE2b-256 | ea0d837dbd5d8430fd0f01ed72c4cfb2f548180f4c68c635df84ce87956cff32 |
Provenance
File details
Details for the file cligj-0.7.2-py3-none-any.whl
.
File metadata
- Download URL: cligj-0.7.2-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1ca117dbce1fe20a5809dc96f01e1c2840f6dcc939b3ddbb1111bf330ba82df |
|
MD5 | 8d481e0845c3b5ea6dc5f2e51168e1a1 |
|
BLAKE2b-256 | 738643fa9f15c5b9fb6e82620428827cd3c284aa933431405d1bcf5231ae3d3e |