@@ -19,7 +19,15 @@ includes:
19
19
Expressions are evaluated by ` fio_planet.features.snuggs.eval() ` . Let's look at
20
20
some examples using that function.
21
21
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.
23
31
24
32
## Builtin Python functions
25
33
@@ -28,27 +36,31 @@ Note: the outer parentheses are not optional within `snuggs.eval()`.
28
36
``` python
29
37
>> > snuggs.eval(' (bool 0)' )
30
38
False
39
+
31
40
```
32
41
33
42
` range ` :
34
43
35
44
``` python
36
45
>> > snuggs.eval(' (range 1 4)' )
37
46
range (1 , 4 )
47
+
38
48
```
39
49
40
50
` list ` :
41
51
42
52
``` python
43
53
>> > snuggs.eval(' (list (range 1 4))' )
44
54
[1 , 2 , 3 ]
55
+
45
56
```
46
57
47
58
Values can be bound to names for use in expressions.
48
59
49
60
``` python
50
61
>> > snuggs.eval(' (list (range start stop))' , start = 0 , stop = 5 )
51
62
[0 , 1 , 2 , 3 , 4 ]
63
+
52
64
```
53
65
54
66
## Itertools functions
@@ -58,6 +70,7 @@ Here's an example of using `itertools.repeat()`.
58
70
``` python
59
71
>> > snuggs.eval(' (list (repeat "*" times))' , times = 6 )
60
72
[' *' , ' *' , ' *' , ' *' , ' *' , ' *' ]
73
+
61
74
```
62
75
63
76
## Shapely functions
@@ -67,13 +80,15 @@ Here's an expression that evaluates to a Shapely Point instance.
67
80
``` python
68
81
>> > snuggs.eval(' (Point 0 0)' )
69
82
< POINT (0 0 )>
83
+
70
84
```
71
85
72
86
The expression below evaluates to a MultiPoint instance.
73
87
74
88
``` python
75
89
>> > snuggs.eval(' (union (Point 0 0) (Point 1 1))' )
76
90
< MULTIPOINT (0 0 , 1 1 )>
91
+
77
92
```
78
93
79
94
## Functions specific to fio-planet
@@ -91,20 +106,23 @@ geometries.
91
106
< GEOMETRYCOLLECTION (POINT (0 0 ), POINT (1 1 ))>
92
107
>> > snuggs.eval(' (list (dump (collect (Point 0 0) (Point 1 1))))' )
93
108
[< POINT (0 0 )> , < POINT (1 1 )> ]
109
+
94
110
```
95
111
96
112
The ` identity ` function returns its single argument.
97
113
98
114
``` python
99
115
>> > snuggs.eval(' (identity 42)' )
100
116
42
117
+
101
118
```
102
119
103
120
To count the number of vertices in a geometry, use ` vertex_count ` .
104
121
105
122
``` python
106
123
>> > snuggs.eval(' (vertex_count (Point 0 0))' )
107
124
1
125
+
108
126
```
109
127
110
128
The ` area ` , ` buffer ` , ` distance ` , ` length ` , ` simplify ` , and ` set_precision `
@@ -119,6 +137,7 @@ longitude and latitude degrees, by a given distance in meters.
119
137
``` python
120
138
>> > snuggs.eval(' (buffer (Point 0 0) :distance 100)' )
121
139
< POLYGON ((0.001 0 , 0.001 0 , 0.001 0 , 0.001 0 , 0.001 - 0.001 , 0.001 - 0.001 , 0 ... >
140
+
122
141
```
123
142
124
143
The `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.
128
147
31214.451487413342
129
148
>> > snuggs.eval(' (length (buffer (Point 0 0) :distance 100))' )
130
149
627.3096977558143
150
+
131
151
```
132
152
133
153
The `distance` between two geometries is in meters.
134
154
135
155
```python
136
156
>> > snuggs.eval(' (distance (Point 0 0) (Point 0.1 0.1))' )
137
157
15995.164946207413
158
+
138
159
```
139
160
140
161
A geometry can be simplified to a tolerance value in meters using `simplify` .
@@ -144,6 +165,7 @@ There are more examples of this function under
144
165
```python
145
166
>> > snuggs.eval(' (simplify (buffer (Point 0 0) :distance 100) :tolerance 100)' )
146
167
< POLYGON ((0.001 0 , 0 - 0.001 , - 0.001 0 , 0 0.001 , 0.001 0 ))>
168
+
147
169
```
148
170
149
171
The `set_precision` function snaps a geometry to a fixed precision grid with a
@@ -152,23 +174,24 @@ size in meters.
152
174
```python
153
175
>> > snuggs.eval(' (set_precision (Point 0.001 0.001) :grid_size 500)' )
154
176
< POINT (0 0 )>
177
+
155
178
```
156
179
157
180
# # Feature and geometry context for expressions
158
181
159
182
`fio- filter ` and `fio- map ` evaluate expressions in the context of a GeoJSON
160
183
feature 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.
163
186
164
187
```lisp
165
- <= (distance g (Point - 105.0 39.753056 )) 50.0
188
+ -- 8 < -- " tests/test_cli.py:filter "
166
189
```
167
190
168
191
`fio- reduce ` evaluates expressions in the context of the sequence of all input
169
192
geometries, named `c` . For example, this expression dissolves input
170
193
geometries using Shapely' s `unary_union`.
171
194
172
195
```lisp
173
- unary_union c
196
+ -- 8 < -- " tests/test_cli.py:reduce "
174
197
```
0 commit comments