点击params获取GeoJSON命令行界面
项目描述
使用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 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a4bc13d623356b373c2c27c53dbd9c68cae5d526270bfa71f6c6fa69669c6b27 |
|
MD5 | 357ed96c1c52c8d276352387bb5909f6 |
|
BLAKE2b-256 | ea0d837dbd5d8430fd0f01ed72c4cfb2f548180f4c68c635df84ce87956cff32 |
cligj-0.7.2-py3-none-any.whl 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c1ca117dbce1fe20a5809dc96f01e1c2840f6dcc939b3ddbb1111bf330ba82df |
|
MD5 | 8d481e0845c3b5ea6dc5f2e51168e1a1 |
|
BLAKE2b-256 | 738643fa9f15c5b9fb6e82620428827cd3c284aa933431405d1bcf5231ae3d3e |