All Projects → mapbox → cligj

mapbox / cligj

Licence: BSD-3-Clause license
Click-based argument and option decorators for Python GIS command line programs

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to cligj

cloudwatch-librato
Fetch AWS CloudWatch metrics and submit to Librato Metrics
Stars: ✭ 13 (-62.86%)
Mutual labels:  banished
nepomuk
A public transit router for GTFS feeds (currently only static) written in modern c++
Stars: ✭ 22 (-37.14%)
Mutual labels:  banished
geojson-coords
Extract coordinates from GeoJSON.
Stars: ✭ 29 (-17.14%)
Mutual labels:  banished
geocode-many
given an array of objects and a transform into a geocodable string, geocode them if possible
Stars: ✭ 13 (-62.86%)
Mutual labels:  banished
iconoblast
App icon dev info burning for iOS and Android.
Stars: ✭ 19 (-45.71%)
Mutual labels:  banished
weekend-picks-template
A template for browsing layers of TileMill maps. Part of the Map Sites templates from MapBox.
Stars: ✭ 24 (-31.43%)
Mutual labels:  banished
locator
A quick and easy way to build maps with markers
Stars: ✭ 30 (-14.29%)
Mutual labels:  banished
streambot
DEPRECATED (SEE README) Robot-assisted deploys to Lambda
Stars: ✭ 39 (+11.43%)
Mutual labels:  banished
node-eio
Control libeio from JavaScript
Stars: ✭ 14 (-60%)
Mutual labels:  banished
geojson-summary
Generate a plain-english summary of what is in a GeoJSON file.
Stars: ✭ 31 (-11.43%)
Mutual labels:  banished
mapbox-directions.js
Leaflet plugin for the Mapbox Directions API
Stars: ✭ 55 (+57.14%)
Mutual labels:  banished
grib-doctor
Utilities for handling quirks of weather data grib files.
Stars: ✭ 20 (-42.86%)
Mutual labels:  banished
diversify
Script for quickly creating varying sizes of app icons for iOS project asset catalogs.
Stars: ✭ 58 (+65.71%)
Mutual labels:  banished

cligj

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

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

Warning

Future change warning GeoJSON sequences (--sequence), not collections (--no-sequence), will be the default in version 1.0.0.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].