Skip to main content

fio_planet: Fiona CLI plugins from Planet Labs.

Project description

A package of Fiona CLI plugin commands from Planet Labs.

https://github.com/planetlabs/fio-planet/actions/workflows/check.yml/badge.svg https://github.com/planetlabs/fio-planet/actions/workflows/test.yml/badge.svg

These commands are for creating Unix pipelines which manipulate streams of GeoJSON features. Such pipelines provide a subset of the functionality of more complicated tools such as PostGIS or GeoPandas and are intended for use with streams of hundreds to thousands of features, where the overhead of JSON serialization between pieces of a pipeline is tolerable.

Installation

python -m pip install --user fio-planet@https://github.com/planetlabs/fio-planet.git

Usage

fio-planet adds filter, map, and reduce commands to Fiona’s fio program. fio-filter evaluates an expression for each feature in a stream of GeoJSON features, passing those for which the expression is true. fio-map maps an expression over a stream of GeoJSON features, producing a stream of new features or other values. fio-reduce applies an expression to a sequence of GeoJSON features, reducing them to a single feature or other value.

These commands provide some of the features of spatial SQL, but act on features in a GeoJSON feature sequence instead of rows in a spatial table. fio-filter decimates a seqence of features, fio-map multiplies features, and fio-reduce turns a sequence of many features into a sequence of exactly one. In combination, many transformations are possible.

Expressions take the form of parenthesized lists which may contain other expressions. The first item in a list is the name of a function or method, or an expression that evaluates to a function. The second item is the function’s first argument or the object to which the method is bound. The remaining list items are the positional and keyword arguments for the named function or method. The list of functions and callables available in expressions includes:

  • Python builtins such as dict, list, and map

  • From functools: reduce.

  • All public functions from itertools, e.g., islice, and repeat

  • All functions importable from Shapely 2.0, e.g., Point, and unary_union

  • All methods of Shapely geometry classes.

Here’s an expression that evaluates to a Shapely Point instance. Point is a callable instance constructor and the pair of 0 values are positional arguments. Note that the outermost parentheses of an expression are optional.

(Point 0 0)

Here’s an expression that evaluates to a Polygon, using buffer. The inner expression (Point 0 0) evaluates to a Shapely Point instance, buffer evaluates to its instance method, and :distance 1.0 assigns a value of 1.0 to that method’s distance keyword argument.

buffer (Point 0 0) :distance 1.0

fio-filter and fio-map evaluate expressions in the context of a GeoJSON feature and its geometry attribute. These are named f and g. For example, here is an expression that tests whether the input feature is within a distance 1.0 of a given point.

<= (distance g (Point 0 0)) 1.0

fio-reduce evaluates expressions in the context of the sequence of all input geometries, which is named c. For example, this expression dissolves input geometries using Shapely’s unary_union.

unary_union c

fio-filter

For each feature read from stdin, fio-filter evaluates a pipeline of one or more steps described using methods from the Shapely library in Lisp-like expressions. If the pipeline expression evaluates to True, the feature passes through the filter. Otherwise the feature does not pass.

For example, this pipeline expression

$ fio cat zip+https://s3.amazonaws.com/fiona-testing/coutwildrnp.zip \
| fio filter '< (distance g (Point -109.0 38.5)) 1'

lets through all features that are less than one unit from the given point and filters out all other features.

fio-map

For each feature read from stdin, fio-map applies a transformation pipeline and writes a copy of the feature, containing the modified geometry, to stdout. For example, polygonal features can be “cleaned” by using a buffer g 0 pipeline.

$ fio cat zip+https://s3.amazonaws.com/fiona-testing/coutwildrnp.zip \
| fio map 'buffer g 0'

fio-reduce

Given a sequence of GeoJSON features (RS-delimited or not) on stdin this prints a single value using a provided transformation pipeline. The set of geometries of the input features in the context of these expressions is named “c”.

For example, the pipeline expression

$ fio cat zip+https://s3.amazonaws.com/fiona-testing/coutwildrnp.zip \
| fio reduce 'unary_union c'

dissolves the geometries of input features.

Support

For usage help, please use the project discussion forum or email developers@planet.com.

If you think you’ve found a bug, please use the project issue tracker.

Roadmap

Version 1.0 adds filter, map, and reduce to Fiona’s fio CLI.

Note that there are no conditional forms in 1.0’s expressions. The project will likely add a cond after 1.0.

Contributing

Before 1.0, the project is looking for feedback on the existing commands more than it is looking for new commands.

The project uses black, flake8, mypy, and tox for static checks and testing.

$ black src tests && flake8 && mypy && tox

Authors and acknowledgment

Contributors to this project are

License

Apache License, Version 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fio_planet-1.0a1.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

fio_planet-1.0a1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file fio_planet-1.0a1.tar.gz.

File metadata

  • Download URL: fio_planet-1.0a1.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for fio_planet-1.0a1.tar.gz
Algorithm Hash digest
SHA256 fa98305f712f8502f262bc18ab5fc8ef65c58ecbb0802f5791454c9e3e738cb4
MD5 7a9f7b90fb63f60a87de8df8f2a67b46
BLAKE2b-256 78e0b7cc2977116eb8dc99522a55620d2330d82e2bb2625c0b6108c89cdfd0ea

See more details on using hashes here.

File details

Details for the file fio_planet-1.0a1-py3-none-any.whl.

File metadata

  • Download URL: fio_planet-1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for fio_planet-1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 5a8847e358851f9989a1095689ed02b1d773c02101dffa395ad3beddfbe04197
MD5 ac635f2e2b6d4c7c15a1ec48217381e7
BLAKE2b-256 f1f5e7f4a07c31f06c956090aa6db33415580721d3e1dc3ba1c84c66b7f5d09c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page