@@ -5,24 +5,24 @@ title: More CLI Tips & Tricks
5
5
## About
6
6
7
7
This document shows off a range of more advanced command-line workflows, making use of a wider range
8
- of tools in the command-line & geospatial ecosystem. Some of them can be a pain to install, like
9
- GDAL/OGR, and several pop in and out of web tools, so these are kept out of the main tutorial
10
- section.
8
+ of tools in the command-line & geospatial ecosystem. Some of them can be a pain to install, like
9
+ GDAL/OGR, and several pop in and out of web tools, so these are kept out of the main tutorial
10
+ section.
11
11
12
12
** WORK IN PROGRESS** : This document is still under construction, with a number of TODO’s remaining,
13
13
but we are publishing as there’s a lot of good information here.
14
14
15
15
## Tools used
16
16
17
- * ** [ GDAL/OGR] ( https://gdal.org ) ** - We’ll mostly use OGR, the vector tooling.
17
+ * ** [ GDAL/OGR] ( https://gdal.org ) ** - We’ll mostly use OGR, the vector tooling.
18
18
Great for things like format conversion and basic simplification.
19
19
* ** [ Keplergl_cli] ( https://github.com/kylebarron/keplergl_cli#usage ) ** - Nice tool to call the
20
- awesome kepler.gl library from the commandline. Useful for visualization of large amounts of
20
+ awesome kepler.gl library from the commandline. Useful for visualization of large amounts of
21
21
geojson.
22
22
* ** [ GeoJSON.io] ( https://geojson.io/ ) ** - Simple tool to do editing of geojson, useful for creating
23
23
AOI’s. It integrates with github, but the ability to save a GeoJSON to github doesn't seem to work so well.
24
24
* ** [ Placemark.io] ( https://placemark.io ) ** - More advanced tool from the creator of GeoJSON.io, very
25
- nice for creating AOI’s and piping them in, with lots of rich geometry editing features.
25
+ nice for creating AOI’s and piping them in, with lots of rich geometry editing features.
26
26
* ** [ MapShaper] ( https://github.com/mbloch/mapshaper ) ** - Tool to do interactive simplification of
27
27
GeoJSON, has a nice CLI.
28
28
* ** [ STACTools] ( https://github.com/stac-utils/stactools ) ** - CLI for working with STAC data. There
@@ -34,14 +34,28 @@ future.
34
34
35
35
### Geometry Inputs
36
36
37
- While the command-line can often be quicker than using a UI, one place that can be slower is
37
+ While the command-line can often be quicker than using a UI, one place that can be slower is
38
38
getting the geometry input for searching or clipping. Hand-editing GeoJSON is a huge pain, so most
39
- people will open up a desktop tool like QGIS or ArcGIS Pro and save the file. But there are a few
39
+ people will open up a desktop tool like QGIS or ArcGIS Pro and save the file. But there are a few
40
40
tools that can get you back into the CLI workflow more quickly.
41
41
42
+ #### Use the Features API
43
+ Rather than using GeoJSON in the SDK, upload your GeoJSON to the [ Features API] ( https://developers.planet.com/docs/apis/features/ ) and use references
44
+ across the system with the sdk.
45
+ References are used in the geometry block of our services in a GeoJSON blob like:
46
+ ``` json
47
+ "geometry" :
48
+ {
49
+ "content" : " pl:features/my/[collection-id]/[feature-id]" ,
50
+ "type" : " ref"
51
+ }
52
+ ```
53
+ Or as a string in a geometry option like ` "pl:features/my/[collection-id]/[feature-id]" `
54
+
55
+
42
56
#### Draw with GeoJSON.io
43
57
44
- One great tool for quickly drawing on a map and getting GeoJSON output is
58
+ One great tool for quickly drawing on a map and getting GeoJSON output is
45
59
[ GeoJSON.io] ( https://geojson.io ) . You can draw and save the file, but an even faster workflow
46
60
is to use your operating system’s clipboard to command-line tools.
47
61
@@ -62,7 +76,7 @@ pbpaste | planet data filter --geom - | planet data search SkySatCollect --filt
62
76
63
77
A really fantastic tool for working with GeoJSON is [ Placemark] ( https://placemark.io ) . It is a
64
78
commercial tool that you’ll have to pay for, but it’s got a really nice feature that makes it very
65
- compatible with command-line workflows. You can easily grab the URL of any individual GeoJSON
79
+ compatible with command-line workflows. You can easily grab the URL of any individual GeoJSON
66
80
feature and stream it in as your geometry using ` curl ` :
67
81
68
82
![ Stream from Placemark] ( https://user-images.githubusercontent.com/407017/179412209-2365d79a-9260-47e5-9b08-9bc5b84b6ddc.gif )
@@ -80,8 +94,8 @@ let you pipe (`|`) the output more directly.
80
94
81
95
#### Copy GeoJSON to clipboard
82
96
83
- One of the quicker routes to visualizing search output is to copy the output to your clipboard and paste into a
84
- tool that will take GeoJSON and visualize it.
97
+ One of the quicker routes to visualizing search output is to copy the output to your clipboard and paste into a
98
+ tool that will take GeoJSON and visualize it.
85
99
86
100
You can do this on GeoJSON.io:
87
101
@@ -101,7 +115,7 @@ planet data filter --string-in strip_id 5743669 | planet data search PSScene --f
101
115
102
116
#### Post to Github as gist
103
117
104
- Another easy option that is a bit more persistent is to post to Github using the
118
+ Another easy option that is a bit more persistent is to post to Github using the
105
119
[ ` gh ` cli tool] ( https://github.com/cli/cli ) . Specifically using the ` gist create ` command.
106
120
107
121
The following command will get the latest SkySat image captured, upload to github, and open
@@ -135,13 +149,13 @@ planet data filter --string-in strip_id $stripid | planet data search PSScene --
135
149
136
150
One of the best tools to visualize large numbers of imagery footprints is a tool called [ kepler.gl] ( https://kepler.gl/ ) ,
137
151
which has a really awesome command-line version which is perfect for working with Planet’s CLI. To get the CLI go to
138
- [ keplergl_cli] ( https://github.com/kylebarron/keplergl_cli ) and follow the
152
+ [ keplergl_cli] ( https://github.com/kylebarron/keplergl_cli ) and follow the
139
153
[ installation instructions] ( https://github.com/kylebarron/keplergl_cli#install ) . Be sure to get a Mapbox API key (from
140
154
the [ access tokens] ( https://account.mapbox.com/access-tokens/ ) page) - just sign up for a free account if you don't have
141
155
one already. The kepler CLI won't work at all without getting one and setting it as the ` MAPBOX_API_KEY ` environment
142
156
variable.
143
157
144
- Once it’s set up you can just pipe any search command directly to ` kepler ` (it usually does fine even without
158
+ Once it’s set up you can just pipe any search command directly to ` kepler ` (it usually does fine even without
145
159
` planet collect ` to go from ndgeojson to geojson). For example:
146
160
147
161
``` console
@@ -179,9 +193,9 @@ curl -s https://api.placemark.io/api/v1/map/a0BWUEErqU9A1EDHZWHez/feature/91a073
179
193
180
194
#### Large Dataset Visualization
181
195
182
- Oftentimes it can be useful to visualize a large amount of data, to really get a sense of the
183
- coverage and then do some filtering of the output. For this we recommend downloading the output
184
- to disk. Getting 20,000 skysat collects will take at least a couple of minutes, and will be over
196
+ Oftentimes it can be useful to visualize a large amount of data, to really get a sense of the
197
+ coverage and then do some filtering of the output. For this we recommend downloading the output
198
+ to disk. Getting 20,000 skysat collects will take at least a couple of minutes, and will be over
185
199
100 megabytes of GeoJSON on disk.
186
200
187
201
``` console
@@ -255,7 +269,7 @@ Smaller ratios preserve the character of concave features better.
255
269
256
270
##### Simplification with OGR
257
271
258
- The other thing you’ll likely want to do to visualize large amounts of data is to simplify it
272
+ The other thing you’ll likely want to do to visualize large amounts of data is to simplify it
259
273
some. Many simplification tools call for a 'tolerance', often set in degrees. For SkySat some useful values are:
260
274
261
275
| tolerance | result |
@@ -264,7 +278,7 @@ some. Many simplification tools call for a 'tolerance', often set in degrees. Fo
264
278
| 0.01 | Messes with the shape a bit, but the footprint generally looks the same, with a couple vertices off. |
265
279
| 0.1 | Mashes the shape, often into a triangle, but still useful for understanding broad coverage. |
266
280
267
- It’s worth experimenting with options between these as well. The more simplification the easier it is for programs to
281
+ It’s worth experimenting with options between these as well. The more simplification the easier it is for programs to
268
282
render the results. ` ogr2ogr ` includes the ability to simplify any output:
269
283
270
284
``` console
@@ -277,14 +291,14 @@ Alternative - use convex hull. TODO: test this, write it up
277
291
ogr2ogr skysat-convex.gpkg skysat.geojson ogr2ogr -sql "select st_convexhull(geometry) from skysat" -dialect sqlite
278
292
```
279
293
280
- Other alternative for really big ones, centroid. GDAL should be able to do this, need to figure out the similar
294
+ Other alternative for really big ones, centroid. GDAL should be able to do this, need to figure out the similar
281
295
sql.
282
296
283
297
#### Simplification with Mapshaper
284
298
285
- Another great tool is [ Mapshaper] ( https://github.com/mbloch/mapshaper ) , which excels at simplification. It offers a
286
- web-based user interface to see the results of simplification, and also a command-line tool you can use if you
287
- find a simplification percentage you’re happy with. After you get it
299
+ Another great tool is [ Mapshaper] ( https://github.com/mbloch/mapshaper ) , which excels at simplification. It offers a
300
+ web-based user interface to see the results of simplification, and also a command-line tool you can use if you
301
+ find a simplification percentage you’re happy with. After you get it
288
302
[ installed] ( https://github.com/mbloch/mapshaper#installation ) you can fire up the UI with:
289
303
290
304
``` console
@@ -300,13 +314,13 @@ interface, or you can also run the command-line program:
300
314
mapshaper -i footprints.geojson -simplify 15% -o simplified.geojson
301
315
```
302
316
303
- Once you find a simplification amount you’re happy with you can use it as a piped output.
317
+ Once you find a simplification amount you’re happy with you can use it as a piped output.
304
318
305
319
``` console
306
320
planet data search --limit 20 SkySatCollect - | planet collect - | mapshaper -i - -simplify 15% -o skysat-ms2.geojson
307
321
```
308
322
309
- Mapshaper also has more simplification algorithms to try out, so we recommend diving into the
323
+ Mapshaper also has more simplification algorithms to try out, so we recommend diving into the
310
324
[ CLI options] ( https://github.com/mbloch/mapshaper/wiki/Command-Reference ) .
311
325
312
326
#### Simplification with QGIS
@@ -316,7 +330,7 @@ Another good tool for simplification is QGIS.
316
330
TODO: Flesh out this section, add in command-line qgis_processing option.
317
331
318
332
Other simplification options for large datasets:
319
-
333
+
320
334
* Use QGIS, run 'convex hull' (Vector -> Geoprocessing -> Convex Hull). Good idea to convert to gpkg or shapefile before you open in qgis if large.
321
335
322
336
### Advanced jq
@@ -327,7 +341,7 @@ Other simplification options for large datasets:
327
341
- get id by array number
328
342
329
343
``` console
330
- planet orders list | jq -rs '.[3] | "\(.id) \(.created_on) \(.name) \(.state)"'
344
+ planet orders list | jq -rs '.[3] | "\(.id) \(.created_on) \(.name) \(.state)"'
331
345
```
332
346
(limit can get the most recent, but not a second or third)
333
347
0 commit comments