Skip to main content

Click params for commmand line interfaces to GeoJSON

Project description

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


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

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)
            {'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.



The cligj.plugins module is deprecated and will be removed at version 1.0. Use click-plugins instead.

cligj can also facilitate loading external click-based plugins via setuptools entry points. The cligj.plugins module contains a special group() decorator that behaves exactly like except that it offers the opportunity load plugins and attach them to the group as it is istantiated.

from pkg_resources import iter_entry_points

import cligj.plugins
import click'module.entry_points'))
def cli():

    """A CLI application."""


def printer(arg):

    """Print arg."""

def plugins():

    """A sub-group that contains plugins from a different module."""

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for cligj, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size cligj-0.3.0-py2-none-any.whl (8.3 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size cligj-0.3.0-py3-none-any.whl (8.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size cligj-0.3.0.tar.gz (5.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page