cligj


Namecligj JSON
Version 0.7.2 PyPI version JSON
download
home_pagehttps://github.com/mapbox/cligj
SummaryClick params for commmand line interfaces to GeoJSON
upload_time2021-05-28 21:23:27
maintainer
docs_urlNone
authorSean Gillies
requires_python>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            cligj
======

.. image:: https://travis-ci.com/mapbox/cligj.svg
   :target: https://travis-ci.com/mapbox/cligj

.. image:: https://coveralls.io/repos/mapbox/cligj/badge.png?branch=master
   :target: https://coveralls.io/r/mapbox/cligj?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 <https://tools.ietf.org/html/rfc8142>`__ (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.


.. code-block:: python

    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

.. code-block:: console

    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

.. code-block:: console

    $ 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.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mapbox/cligj",
    "name": "cligj",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4",
    "maintainer_email": "",
    "keywords": "",
    "author": "Sean Gillies",
    "author_email": "sean@mapbox.com",
    "download_url": "https://files.pythonhosted.org/packages/ea/0d/837dbd5d8430fd0f01ed72c4cfb2f548180f4c68c635df84ce87956cff32/cligj-0.7.2.tar.gz",
    "platform": "",
    "description": "cligj\n======\n\n.. image:: https://travis-ci.com/mapbox/cligj.svg\n   :target: https://travis-ci.com/mapbox/cligj\n\n.. image:: https://coveralls.io/repos/mapbox/cligj/badge.png?branch=master\n   :target: https://coveralls.io/r/mapbox/cligj?branch=master\n\nCommon arguments and options for GeoJSON processing commands, using Click.\n\n`cligj` is for Python developers who create command line interfaces for geospatial data.\n`cligj` allows you to quickly build consistent, well-tested and interoperable CLIs for handling GeoJSON.\n\n\nArguments\n---------\n\n``files_in_arg``\nMultiple files\n\n``files_inout_arg``\nMultiple files, last of which is an output file.\n\n``features_in_arg``\nGeoJSON Features input which accepts multiple representations of GeoJSON features\nand returns the input data as an iterable of GeoJSON Feature-like dictionaries\n\nOptions\n--------\n\n``verbose_opt``\n\n``quiet_opt``\n\n``format_opt``\n\nJSON formatting options\n~~~~~~~~~~~~~~~~~~~~~~~\n\n``indent_opt``\n\n``compact_opt``\n\nCoordinate precision option\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n``precision_opt``\n\nGeographic (default), projected, or Mercator switch\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n``projection_geographic_opt``\n\n``projection_projected_opt``\n\n``projection_mercator_opt``\n\nFeature collection or feature sequence switch\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n``sequence_opt``\n\n``use_rs_opt``\n\nGeoJSON output mode option\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n``geojson_type_collection_opt``\n\n``geojson_type_feature_opt``\n\n``def geojson_type_bbox_opt``\n\nExample\n-------\n\nHere's an example of a command that writes out GeoJSON features as a collection\nor, optionally, a sequence of individual features. Since most software that\nreads and writes GeoJSON expects a text containing a single feature collection,\nthat's the default, and a LF-delimited sequence of texts containing one GeoJSON\nfeature each is a feature that is turned on using the ``--sequence`` option.\nTo write sequences of feature texts that conform to the `GeoJSON Text Sequences\nstandard <https://tools.ietf.org/html/rfc8142>`__ (and might contain\npretty-printed JSON) with the ASCII Record Separator (0x1e) as a delimiter, use\nthe ``--rs`` option\n\n.. warning:: Future change warning\n   GeoJSON sequences (`--sequence`), not collections (`--no-sequence`), will be\n   the default in version 1.0.0.\n\n\n.. code-block:: python\n\n    import click\n    import cligj\n    import json\n\n    def process_features(features):\n        for feature in features:\n            # TODO process feature here\n            yield feature\n\n    @click.command()\n    @cligj.features_in_arg\n    @cligj.sequence_opt\n    @cligj.use_rs_opt\n    def pass_features(features, sequence, use_rs):\n        if sequence:\n            for feature in process_features(features):\n                if use_rs:\n                    click.echo(u'\\x1e', nl=False)\n                click.echo(json.dumps(feature))\n        else:\n            click.echo(json.dumps(\n                {'type': 'FeatureCollection',\n                 'features': list(process_features(features))}))\n\nOn the command line, the generated help text explains the usage\n\n.. code-block:: console\n\n    Usage: pass_features [OPTIONS] FEATURES...\n\n    Options:\n    --sequence / --no-sequence  Write a LF-delimited sequence of texts\n                                containing individual objects or write a single\n                                JSON text containing a feature collection object\n                                (the default).\n    --rs / --no-rs              Use RS (0x1E) as a prefix for individual texts\n                                in a sequence as per http://tools.ietf.org/html\n                                /draft-ietf-json-text-sequence-13 (default is\n                                False).\n    --help                      Show this message and exit.\n\nAnd can be used like this\n\n.. code-block:: console\n\n    $ cat data.geojson\n    {'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]}\n\n    $ pass_features data.geojson\n    {'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]}\n\n    $ cat data.geojson | pass_features\n    {'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]}\n\n    $ cat data.geojson | pass_features --sequence\n    {'type': 'Feature', 'id': '1'}\n    {'type': 'Feature', 'id': '2'}\n\n    $ cat data.geojson | pass_features --sequence --rs\n    ^^{'type': 'Feature', 'id': '1'}\n    ^^{'type': 'Feature', 'id': '2'}\n\nIn this example, ``^^`` represents 0x1e.\n\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Click params for commmand line interfaces to GeoJSON",
    "version": "0.7.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "8d481e0845c3b5ea6dc5f2e51168e1a1",
                "sha256": "c1ca117dbce1fe20a5809dc96f01e1c2840f6dcc939b3ddbb1111bf330ba82df"
            },
            "downloads": -1,
            "filename": "cligj-0.7.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8d481e0845c3b5ea6dc5f2e51168e1a1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4",
            "size": 7069,
            "upload_time": "2021-05-28T21:23:26",
            "upload_time_iso_8601": "2021-05-28T21:23:26.877779Z",
            "url": "https://files.pythonhosted.org/packages/73/86/43fa9f15c5b9fb6e82620428827cd3c284aa933431405d1bcf5231ae3d3e/cligj-0.7.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "357ed96c1c52c8d276352387bb5909f6",
                "sha256": "a4bc13d623356b373c2c27c53dbd9c68cae5d526270bfa71f6c6fa69669c6b27"
            },
            "downloads": -1,
            "filename": "cligj-0.7.2.tar.gz",
            "has_sig": false,
            "md5_digest": "357ed96c1c52c8d276352387bb5909f6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4",
            "size": 9803,
            "upload_time": "2021-05-28T21:23:27",
            "upload_time_iso_8601": "2021-05-28T21:23:27.935951Z",
            "url": "https://files.pythonhosted.org/packages/ea/0d/837dbd5d8430fd0f01ed72c4cfb2f548180f4c68c635df84ce87956cff32/cligj-0.7.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-05-28 21:23:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "mapbox",
    "github_project": "cligj",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cligj"
}
        
Elapsed time: 0.04057s