Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions docs/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,17 @@ size in meters.

`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 50 meters
of the given point.
here is an expression that tests whether the input feature is within 62.5
kilometers of the given point.

```lisp
<= (distance g (Point -105.0 39.753056)) 50.0
--8<-- "tests/test_cli.py:filter"
```

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

```lisp
unary_union c
--8<-- "tests/test_cli.py:reduce"
```

## Snippet test

```python
--8<-- "tests/test_cli.py:map"
```
38 changes: 32 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,26 @@ def test_map_count():
with open("tests/data/trio.seq") as seq:
data = seq.read()

# --8<-- [start:map]
# Define our map arg using a mkdocs snippet.
arg = """
--8<-- [start:map]
centroid (buffer g 1.0)
--8<-- [end:map]
""".splitlines()[
2
].strip()

runner = CliRunner()
result = runner.invoke(
main_group,
["map", "centroid (buffer g 1.0)"],
input=data, foo=42,
["map", arg], # "centroid (buffer g 1.0)"],
input=data,
)
# --8<-- [end:map]

assert result.exit_code == 0
assert result.output.count('"type": "Point"') == 3


@pytest.mark.parametrize("raw_opt", ["--raw", "-r"])
def test_reduce_area(raw_opt):
"""Reduce features to their (raw) area."""
Expand All @@ -58,8 +66,17 @@ def test_reduce_union():
with open("tests/data/trio.seq") as seq:
data = seq.read()

# Define our reduce command using a mkdocs snippet.
arg = """
--8<-- [start:reduce]
unary_union c
--8<-- [end:reduce]
""".splitlines()[
2
].strip()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinlacaille I've got some tested CLI snippets! It's a little tortured, I'm working against Python to keep quotes out of the snippet section, but it works!

Screenshot from 2023-05-03 15-38-14


runner = CliRunner()
result = runner.invoke(main_group, ["reduce", "unary_union c"], input=data)
result = runner.invoke(main_group, ["reduce", arg], input=data)
assert result.exit_code == 0
assert result.output.count('"type": "Polygon"') == 1
assert result.output.count('"type": "LineString"') == 1
Expand Down Expand Up @@ -90,10 +107,19 @@ def test_filter():
with open("tests/data/trio.seq") as seq:
data = seq.read()

# Define our reduce command using a mkdocs snippet.
arg = """
--8<-- [start:filter]
< (distance g (Point 4 43)) 62.5E3
--8<-- [end:filter]
""".splitlines()[
2
].strip()

runner = CliRunner()
result = runner.invoke(
main_group,
["filter", "< (distance g (Point 4 43)) 62.5E3"],
["filter", arg],
input=data,
catch_exceptions=False,
)
Expand Down