命令行界面

Fiona的新命令行界面是一个名为“fio”的程序。

Usage: fio [OPTIONS] COMMAND [ARGS]...

  Fiona command line interface.

Options:
  -v, --verbose     Increase verbosity.
  -q, --quiet       Decrease verbosity.
  --version         Show the version and exit.
  --gdal-version    Show the version and exit.
  --python-version  Show the version and exit.
  --help            Show this message and exit.

Commands:
  bounds   Print the extent of GeoJSON objects
  calc     Calculate GeoJSON property by Python expression
  cat      Concatenate and print the features of datasets
  collect  Collect a sequence of features.
  distrib  Distribute features from a collection.
  dump     Dump a dataset to GeoJSON.
  env      Print information about the fio environment.
  filter   Filter GeoJSON features by python expression.
  info     Print information about a dataset.
  insp     Open a dataset and start an interpreter.
  load     Load GeoJSON to a dataset in another format.
  ls       List layers in a datasource.
  rm       Remove a datasource or an individual layer.

它是用 click 开发得而且在1.1.6版中是新的功能。

界限

1.4.5版中的新功能。

Fio-bounds从stdin读取LF或RS分隔的geojson文本(特性或集合),并将其边界(有或无其他数据)打印到stdout。

没有选择,它的工作方式如下:

$ fio cat docs/data/test_uk.shp | head -n 1 \
> | fio bounds
[0.735, 51.357216, 0.947778, 51.444717]

使用 --with-id 给你

$ fio cat docs/data/test_uk.shp | head -n 1 \
> | fio bounds --with-id
{"id": "0", "bbox": [0.735, 51.357216, 0.947778, 51.444717]}

calc

在1.7b1版中是新的功能

此calc命令使用指定的表达式在GeoJSON特性上创建一个新属性。

在受限命名空间中计算的表达式在包含4个函数( ` sum ` , ` pow ` , ` min ` , ` max ` ) , math 模块,匀称的 shape 函数,类型转换(bool, int, str, len, float)和一个表示要评价特性对象 f 。这个 f 对象允许以javascript样式的点标记进行访问,以方便使用。

将为每个特性计算表达式,并将其返回值作为指定的属性名称添加到属性中。默认情况下不会覆盖现有属性( 引发异常 )。

$ fio cat data.shp | fio calc sumAB  "f.properties.A + f.properties.B"

cat

此cat命令连接一个或多个数据集的特性,并将它们打印为 JSON文本系列 of features. In other words: GeoJSON feature objects, possibly pretty printed, optionally separated by ASCII RS (x1e) chars using --rs.

fio cat 的输出可以用管道输送到 fio load 来创建新的连接数据集。

$ fio cat docs/data/test_uk.shp docs/data/test_uk.shp \
> | fio load /tmp/double.shp --driver Shapefile
$ fio info /tmp/double.shp --count
96
$ fio info docs/data/test_uk.shp --count
48

在1.4.0版中的新功能。

cat命令提供了过滤数据的可选方法,这与 fio filter tool. A bounding box --bbox w,s,e,n tests for a spatial intersection with the geometries. An attribute filter --where TEXT can use an SQL WHERE clause . 如果将多个数据集传递给 fio cat ,WHERE子句中使用的属性必须对每个数据集有效。

收集

此collect命令采用GeoJSON特性对象的JSON文本序列,例如 fio cat 的输出并写入GeoJSON特性集合。

$ fio cat docs/data/test_uk.shp docs/data/test_uk.shp \
> | fio collect > /tmp/collected.json
$ fio info /tmp/collected.json --count
96

在1.4.0版中的新功能。

分布区

与fio collect相反,fio distrib采用GeoJSON特性集合,并编写GeoJSON特性对象的JSON文本序列。

$ fio info --count tests/data/coutwildrnp.shp
67
$ fio cat tests/data/coutwildrnp.shp | fio collect | fio distrib | wc -l
67

在1.4.0版中的新功能。

dump

此dump命令读取向量数据集,并将GeoJSON特性集合写入stdout。它的输出可以通过管道传输到 fio load (见下文)。

$ fio dump docs/data/test_uk.shp --indent 2 --precision 2 | head
{
  "features": [
    {
      "geometry": {
        "coordinates": [
          [
            [
              0.9,
              51.36
            ],

您可以选择使用 --x-json-seq 转储JSON文本序列. 从1.4.0版开始, fio cat 是生成序列的更佳工具。

$ fio dump docs/data/test_uk.shp --precision 2 --x-json-seq | head -n 2
{"geometry": {"coordinates": [[[0.9, 51.36], [0.89, 51.36], [0.79, 51.37], [0.78, 51.37], [0.77, 51.38], [0.76, 51.38], [0.75, 51.39], [0.74, 51.4], [0.73, 51.41], [0.74, 51.43], [0.75, 51.44], [0.76, 51.44], [0.79, 51.44], [0.89, 51.42], [0.9, 51.42], [0.91, 51.42], [0.93, 51.4], [0.94, 51.39], [0.94, 51.38], [0.95, 51.38], [0.95, 51.37], [0.95, 51.37], [0.94, 51.37], [0.9, 51.36], [0.9, 51.36]]], "type": "Polygon"}, "id": "0", "properties": {"AREA": 244820.0, "CAT": 232.0, "CNTRY_NAME": "United Kingdom", "FIPS_CNTRY": "UK", "POP_CNTRY": 60270708.0}, "type": "Feature"}
{"geometry": {"coordinates": [[[-4.66, 51.16], [-4.67, 51.16], [-4.67, 51.16], [-4.67, 51.17], [-4.67, 51.19], [-4.67, 51.19], [-4.67, 51.2], [-4.66, 51.2], [-4.66, 51.19], [-4.65, 51.16], [-4.65, 51.16], [-4.65, 51.16], [-4.66, 51.16]]], "type": "Polygon"}, "id": "1", "properties": {"AREA": 244820.0, "CAT": 232.0, "CNTRY_NAME": "United Kingdom", "FIPS_CNTRY": "UK", "POP_CNTRY": 60270708.0}, "type": "Feature"}

信息

此info命令将有关数据集的信息作为JSON对象打印。

$ fio info docs/data/test_uk.shp --indent 2
{
  "count": 48,
  "crs": "+datum=WGS84 +no_defs +proj=longlat",
  "driver": "ESRI Shapefile",
  "bounds": [
    -8.621389,
    49.911659,
    1.749444,
    60.844444
  ],
  "schema": {
    "geometry": "Polygon",
    "properties": {
      "CAT": "float:16",
      "FIPS_CNTRY": "str:80",
      "CNTRY_NAME": "str:80",
      "AREA": "float:15.2",
      "POP_CNTRY": "float:15.2"
    }
  }
}

您可以这样处理JSON,例如, underscore-cli.

$ fio info docs/data/test_uk.shp | underscore extract count
48

您还可以选择获取单个信息项作为纯文本(而不是JSON)字符串

$ fio info docs/data/test_uk.shp --count
48
$ fio info docs/data/test_uk.shp --bounds
-8.621389 49.911659 1.749444 60.844444

load

此load命令从stdin中读取GeoJSON特性,并使用其他格式将其写入向量数据集。

$ fio dump docs/data/test_uk.shp \
> | fio load /tmp/test.shp --driver Shapefile

此命令还支持GeoJSON文本序列。将检测RS分离序列。如果要加载LF分隔序列,必须指定 --x-json-seq .

$ fio cat docs/data/test_uk.shp | fio load /tmp/foo.shp --driver Shapefile
$ fio info /tmp/foo.shp --indent 2
{
  "count": 48,
  "crs": "+datum=WGS84 +no_defs +proj=longlat",
  "driver": "ESRI Shapefile",
  "bounds": [
    -8.621389,
    49.911659,
    1.749444,
    60.844444
  ],
  "schema": {
    "geometry": "Polygon",
    "properties": {
      "AREA": "float:24.15",
      "CNTRY_NAME": "str:80",
      "POP_CNTRY": "float:24.15",
      "FIPS_CNTRY": "str:80",
      "CAT": "float:24.15"
    }
  }
}

下划线cli process命令是将GeoJSON特性集合转换为功能序列的另一种方法。

$ fio dump docs/data/test_uk.shp \
> | underscore process \
> 'each(data.features,function(o){console.log(JSON.stringify(o))})' \
> | fio load /tmp/test-seq.shp --x-json-seq --driver Shapefile

过滤器

此filter命令从stdin读取GeoJSON特性并将该特性写入stdout if 中,该特性的表达式值将 True

在受限制的命名空间中计算的python表达式包含3个函数(sum, min, max) , math 模块,匀称的 shape 函数和表示评价特性的对象 f 。这个 f 对象允许以javascript样式的点标记进行访问,以方便使用。

如果表达式求值为“truthy”值,则将逐字打印该特性。否则,此特性将从输出中排除。

$ fio cat data.shp \
> | fio filter "f.properties.area > 1000.0" \
> | fio collect > large_polygons.geojson

将创建一个geojson文件,其中只包含来自 data.shp 区域超过给定阈值的那些特性。

注意此工具与 fio cat --where TEXT ... ,它提供特性属性的SQL WHERE子句筛选。

rm

这个 fio rm 命令删除整个数据源或多层数据源中的单个层。如果数据源由多个文件(例如ESRI shapefile)组成,则将删除所有文件都。

$ fio rm countries.shp
$ fio rm --layer forests land_cover.gpkg

1.8.0版中的新功能。

坐标参考系转换

此``fio cat`` 命令可以选择将特征几何转换为用 --dst_crs 指定的新坐标参考系. 这个 fio collect 命令可以选择从 --src_crs 指定的坐标参考系转换默认的WGS84 GeoJSON CRS。像collect一样, fio load 可以接受非WGS84特性,但由于它可以以GeoJSON以外的格式写入文件,因此可以选择指定 --dst_crs . 例如,WGS84特性从docs/data/test_uk.shp读取,

$ fio cat docs/data/test_uk.shp --dst_crs EPSG:3857 \
> | fio collect --src_crs EPSG:3857 > /tmp/foo.json

通过epsg:3857(网络墨卡托)绕道,并由fio cat转换回wgs84。下列,

$ fio cat docs/data/test_uk.shp --dst_crs EPSG:3857 \
> | fio load --src_crs EPSG:3857 --dst_crs EPSG:4326 --driver Shapefile \
> /tmp/foo.shp

执行相同的操作,但用于esri shapefile输出。

1.4.2版中的新功能。