@@ -19,7 +19,15 @@ includes:
1919Expressions are evaluated by ` fio_planet.features.snuggs.eval() ` . Let's look at
2020some examples using that function.
2121
22- Note: the outer parentheses are not optional within ` snuggs.eval() ` .
22+ !!! note
23+
24+ The outer parentheses are not optional within `snuggs.eval()`.
25+
26+ !!! note
27+
28+ `snuggs.eval()` does not use Python's builtin `eval()` but isn't intended
29+ to be a secure computing environment. Expressions which access the
30+ computer's filesystem and create new processes are possible.
2331
2432## Builtin Python functions
2533
@@ -28,27 +36,31 @@ Note: the outer parentheses are not optional within `snuggs.eval()`.
2836``` python
2937>> > snuggs.eval(' (bool 0)' )
3038False
39+
3140```
3241
3342` range ` :
3443
3544``` python
3645>> > snuggs.eval(' (range 1 4)' )
3746range (1 , 4 )
47+
3848```
3949
4050` list ` :
4151
4252``` python
4353>> > snuggs.eval(' (list (range 1 4))' )
4454[1 , 2 , 3 ]
55+
4556```
4657
4758Values can be bound to names for use in expressions.
4859
4960``` python
5061>> > snuggs.eval(' (list (range start stop))' , start = 0 , stop = 5 )
5162[0 , 1 , 2 , 3 , 4 ]
63+
5264```
5365
5466## Itertools functions
@@ -58,6 +70,7 @@ Here's an example of using `itertools.repeat()`.
5870``` python
5971>> > snuggs.eval(' (list (repeat "*" times))' , times = 6 )
6072[' *' , ' *' , ' *' , ' *' , ' *' , ' *' ]
73+
6174```
6275
6376## Shapely functions
@@ -67,13 +80,15 @@ Here's an expression that evaluates to a Shapely Point instance.
6780``` python
6881>> > snuggs.eval(' (Point 0 0)' )
6982< POINT (0 0 )>
83+
7084```
7185
7286The expression below evaluates to a MultiPoint instance.
7387
7488``` python
7589>> > snuggs.eval(' (union (Point 0 0) (Point 1 1))' )
7690< MULTIPOINT (0 0 , 1 1 )>
91+
7792```
7893
7994## Functions specific to fio-planet
@@ -91,20 +106,23 @@ geometries.
91106< GEOMETRYCOLLECTION (POINT (0 0 ), POINT (1 1 ))>
92107>> > snuggs.eval(' (list (dump (collect (Point 0 0) (Point 1 1))))' )
93108[< POINT (0 0 )> , < POINT (1 1 )> ]
109+
94110```
95111
96112The ` identity ` function returns its single argument.
97113
98114``` python
99115>> > snuggs.eval(' (identity 42)' )
10011642
117+
101118```
102119
103120To count the number of vertices in a geometry, use ` vertex_count ` .
104121
105122``` python
106123>> > snuggs.eval(' (vertex_count (Point 0 0))' )
1071241
125+
108126```
109127
110128The ` area ` , ` buffer ` , ` distance ` , ` length ` , ` simplify ` , and ` set_precision `
@@ -119,6 +137,7 @@ longitude and latitude degrees, by a given distance in meters.
119137``` python
120138>> > snuggs.eval(' (buffer (Point 0 0) :distance 100)' )
121139< POLYGON ((0.001 0 , 0.001 0 , 0.001 0 , 0.001 0 , 0.001 - 0.001 , 0.001 - 0.001 , 0 ... >
140+
122141```
123142
124143The `area` and `length` of this polygon have units of square meter and meter.
@@ -128,13 +147,15 @@ The `area` and `length` of this polygon have units of square meter and meter.
12814731214.451487413342
129148>> > snuggs.eval(' (length (buffer (Point 0 0) :distance 100))' )
130149627.3096977558143
150+
131151```
132152
133153The `distance` between two geometries is in meters.
134154
135155```python
136156>> > snuggs.eval(' (distance (Point 0 0) (Point 0.1 0.1))' )
13715715995.164946207413
158+
138159```
139160
140161A geometry can be simplified to a tolerance value in meters using `simplify` .
@@ -144,6 +165,7 @@ There are more examples of this function under
144165```python
145166>> > snuggs.eval(' (simplify (buffer (Point 0 0) :distance 100) :tolerance 100)' )
146167< POLYGON ((0.001 0 , 0 - 0.001 , - 0.001 0 , 0 0.001 , 0.001 0 ))>
168+
147169```
148170
149171The `set_precision` function snaps a geometry to a fixed precision grid with a
@@ -152,23 +174,24 @@ size in meters.
152174```python
153175>> > snuggs.eval(' (set_precision (Point 0.001 0.001) :grid_size 500)' )
154176< POINT (0 0 )>
177+
155178```
156179
157180# # Feature and geometry context for expressions
158181
159182`fio- filter ` and `fio- map ` evaluate expressions in the context of a GeoJSON
160183feature and its geometry attribute. These are named `f` and `g` . For example,
161- here is an expression that tests whether the input feature is within 50 meters
162- of the given point.
184+ here is an expression that tests whether the input feature is within 62.5
185+ kilometers of the given point.
163186
164187```lisp
165- <= (distance g (Point - 105.0 39.753056 )) 50.0
188+ -- 8 < -- " tests/test_cli.py:filter "
166189```
167190
168191`fio- reduce ` evaluates expressions in the context of the sequence of all input
169192geometries, named `c` . For example, this expression dissolves input
170193geometries using Shapely' s `unary_union`.
171194
172195```lisp
173- unary_union c
196+ -- 8 < -- " tests/test_cli.py:reduce "
174197```
0 commit comments