Skip to main content

cligj

https://travis-ci.org/mapbox/cligj.svg https://coveralls.io/repos/mapbox/cligj/badge.png?branch=master

Common arguments and options for GeoJSON processing commands, using Click.

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 JSON Text Sequences proposed 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

@click.command()
@cligj.sequence_opt
@cligj.use_rs_opt
def features(sequence, use_rs):
    features = [
        {'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]
    if sequence:
        for feature in features:
            if use_rs:
                click.echo(b'\x1e', nl=False)
            click.echo(json.dumps(feature))
    else:
        click.echo(json.dumps(
            {'type': 'FeatureCollection', 'features': features}))

On the command line it works like this.

$ features
{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]}

$ features --sequence
{'type': 'Feature', 'id': '1'}
{'type': 'Feature', 'id': '2'}

$ features --sequence --rs
^^{'type': 'Feature', 'id': '1'}
^^{'type': 'Feature', 'id': '2'}

In this example, ^^ represents 0x1e.

Metadata

Release files for cligj 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cligj 0.1.0
File Size Uploaded
cligj-0.1.0.tar.gz 2.9 kB Details

Release files / cligj-0.1.0.tar.gz

Download URL cligj-0.1.0.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b2a8fe0a5c273a5ea58540be6fc8823c44aa7b01b6c76a87f62ff15c41daebd5
BLAKE2b-256 checksum
How to use checksums
397ec1c75ce4731c8260284697c2f4cd02a982868db45ec0f31c3a3381f9c1e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.7.2

2 release files

0.7.1

2 release files

0.7.0

3 release files

0.6.0

3 release files

0.5.0

3 release files

0.4.0

3 release files

0.3.0

3 release files

0.2.0

3 release files

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page