4
.. image:: https://travis-ci.org/mapbox/cligj.svg
5
:target: https://travis-ci.org/mapbox/cligj
7
.. image:: https://coveralls.io/repos/mapbox/cligj/badge.png?branch=master
8
:target: https://coveralls.io/r/mapbox/cligj?branch=master
10
Common arguments and options for GeoJSON processing commands, using Click.
15
Here's an example of a command that writes out GeoJSON features as a collection
16
or, optionally, a sequence of individual features. Since most software that
17
reads and writes GeoJSON expects a text containing a single feature collection,
18
that's the default, and a LF-delimited sequence of texts containing one GeoJSON
19
feature each is a feature that is turned on using the ``--sequence`` option.
20
To write sequences of feature texts that conform to the `JSON Text Sequences
22
<http://tools.ietf.org/html/draft-ietf-json-text-sequence-13>`__ (and might
23
contain pretty-printed JSON) with the ASCII Record Separator (0x1e) as
24
a delimiter, use the ``--rs`` option
26
.. code-block:: python
35
def features(sequence, use_rs):
37
{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]
39
for feature in features:
41
click.echo(b'\x1e', nl=False)
42
click.echo(json.dumps(feature))
44
click.echo(json.dumps(
45
{'type': 'FeatureCollection', 'features': features}))
47
On the command line it works like this.
49
.. code-block:: console
52
{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]}
55
{'type': 'Feature', 'id': '1'}
56
{'type': 'Feature', 'id': '2'}
58
$ features --sequence --rs
59
^^{'type': 'Feature', 'id': '1'}
60
^^{'type': 'Feature', 'id': '2'}
62
In this example, ``^^`` represents 0x1e.