跳转到主要内容

点击params获取GeoJSON命令行界面

项目描述

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

使用Click的GeoJSON处理命令的常见参数和选项。

cligj适用于创建地理空间数据的命令行界面的Python开发者。cligj允许您快速构建一致、经过良好测试和互操作的CLI来处理GeoJSON。

参数

files_in_arg 多个文件

files_inout_arg 多个文件,最后一个为输出文件。

features_in_arg GeoJSON特征输入,接受多种GeoJSON特征的表示形式,并将输入数据作为GeoJSON特征样式的字典的可迭代对象返回

选项

verbose_opt

quiet_opt

format_opt

JSON格式化选项

indent_opt

compact_opt

坐标精度选项

precision_opt

地理(默认)、投影或墨卡托切换

projection_geographic_opt

projection_projected_opt

projection_mercator_opt

特征集合或特征序列切换

sequence_opt

use_rs_opt

GeoJSON输出模式选项

geojson_type_collection_opt

geojson_type_feature_opt

def geojson_type_bbox_opt

示例

以下是一个命令示例,它将GeoJSON功能以集合的形式输出,或者可选地以单个功能的序列输出。由于大多数读取和写入GeoJSON的软件都期望一个包含单个功能集合的文本,所以默认情况下是这种形式,而一个包含单个GeoJSON功能的LF分隔的文本序列是通过使用--sequence选项来启用的。要使用ASCII记录分隔符(0x1e)作为分隔符输出符合GeoJSON文本序列标准(可能包含格式化输出的JSON)的文本序列,请使用--rs选项。

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))}))

在命令行上,生成的帮助文本解释了用法

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.

并且可以像这样使用

$ 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'}

在此示例中,^^代表0x1e。

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码发行版

cligj-0.7.2.tar.gz (9.8 kB 查看哈希)

上传时间 源代码

构建发行版

cligj-0.7.2-py3-none-any.whl (7.1 kB 查看哈希)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面