Skip to main content

Click params for GeoJSON CLI

Project description

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.

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

cligj-0.1.0.tar.gz (2.9 kB view hashes)

Uploaded Source

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