@@ -5,24 +5,24 @@ title: More CLI Tips & Tricks
55## About
66
77This 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.
1111
1212** WORK IN PROGRESS** : This document is still under construction, with a number of TODO’s remaining,
1313but we are publishing as there’s a lot of good information here.
1414
1515## Tools used
1616
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.
1818Great for things like format conversion and basic simplification.
1919* ** [ 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
2121geojson.
2222* ** [ GeoJSON.io] ( https://geojson.io/ ) ** - Simple tool to do editing of geojson, useful for creating
2323AOI’s. It integrates with github, but the ability to save a GeoJSON to github doesn't seem to work so well.
2424* ** [ 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.
2626* ** [ MapShaper] ( https://github.com/mbloch/mapshaper ) ** - Tool to do interactive simplification of
2727GeoJSON, has a nice CLI.
2828* ** [ STACTools] ( https://github.com/stac-utils/stactools ) ** - CLI for working with STAC data. There
@@ -34,14 +34,28 @@ future.
3434
3535### Geometry Inputs
3636
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
3838getting 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
4040tools that can get you back into the CLI workflow more quickly.
4141
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+
4256#### Draw with GeoJSON.io
4357
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
4559[ GeoJSON.io] ( https://geojson.io ) . You can draw and save the file, but an even faster workflow
4660is to use your operating system’s clipboard to command-line tools.
4761
@@ -62,7 +76,7 @@ pbpaste | planet data filter --geom - | planet data search SkySatCollect --filt
6276
6377A really fantastic tool for working with GeoJSON is [ Placemark] ( https://placemark.io ) . It is a
6478commercial 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
6680feature and stream it in as your geometry using ` curl ` :
6781
6882![ 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.
8094
8195#### Copy GeoJSON to clipboard
8296
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.
8599
86100You can do this on GeoJSON.io:
87101
@@ -101,7 +115,7 @@ planet data filter --string-in strip_id 5743669 | planet data search PSScene --f
101115
102116#### Post to Github as gist
103117
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
105119[ ` gh ` cli tool] ( https://github.com/cli/cli ) . Specifically using the ` gist create ` command.
106120
107121The 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 --
135149
136150One of the best tools to visualize large numbers of imagery footprints is a tool called [ kepler.gl] ( https://kepler.gl/ ) ,
137151which 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
139153[ installation instructions] ( https://github.com/kylebarron/keplergl_cli#install ) . Be sure to get a Mapbox API key (from
140154the [ access tokens] ( https://account.mapbox.com/access-tokens/ ) page) - just sign up for a free account if you don't have
141155one already. The kepler CLI won't work at all without getting one and setting it as the ` MAPBOX_API_KEY ` environment
142156variable.
143157
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
145159` planet collect ` to go from ndgeojson to geojson). For example:
146160
147161``` console
@@ -179,9 +193,9 @@ curl -s https://api.placemark.io/api/v1/map/a0BWUEErqU9A1EDHZWHez/feature/91a073
179193
180194#### Large Dataset Visualization
181195
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
185199100 megabytes of GeoJSON on disk.
186200
187201``` console
@@ -255,7 +269,7 @@ Smaller ratios preserve the character of concave features better.
255269
256270##### Simplification with OGR
257271
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
259273some. Many simplification tools call for a 'tolerance', often set in degrees. For SkySat some useful values are:
260274
261275| tolerance | result |
@@ -264,7 +278,7 @@ some. Many simplification tools call for a 'tolerance', often set in degrees. Fo
264278| 0.01 | Messes with the shape a bit, but the footprint generally looks the same, with a couple vertices off. |
265279| 0.1 | Mashes the shape, often into a triangle, but still useful for understanding broad coverage. |
266280
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
268282render the results. ` ogr2ogr ` includes the ability to simplify any output:
269283
270284``` console
@@ -277,14 +291,14 @@ Alternative - use convex hull. TODO: test this, write it up
277291ogr2ogr skysat-convex.gpkg skysat.geojson ogr2ogr -sql "select st_convexhull(geometry) from skysat" -dialect sqlite
278292```
279293
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
281295sql.
282296
283297#### Simplification with Mapshaper
284298
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
288302[ installed] ( https://github.com/mbloch/mapshaper#installation ) you can fire up the UI with:
289303
290304``` console
@@ -300,13 +314,13 @@ interface, or you can also run the command-line program:
300314mapshaper -i footprints.geojson -simplify 15% -o simplified.geojson
301315```
302316
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.
304318
305319``` console
306320planet data search --limit 20 SkySatCollect - | planet collect - | mapshaper -i - -simplify 15% -o skysat-ms2.geojson
307321```
308322
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
310324[ CLI options] ( https://github.com/mbloch/mapshaper/wiki/Command-Reference ) .
311325
312326#### Simplification with QGIS
@@ -316,7 +330,7 @@ Another good tool for simplification is QGIS.
316330TODO: Flesh out this section, add in command-line qgis_processing option.
317331
318332Other simplification options for large datasets:
319-
333+
320334* Use QGIS, run 'convex hull' (Vector -> Geoprocessing -> Convex Hull). Good idea to convert to gpkg or shapefile before you open in qgis if large.
321335
322336### Advanced jq
@@ -327,7 +341,7 @@ Other simplification options for large datasets:
327341- get id by array number
328342
329343``` 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)"'
331345```
332346(limit can get the most recent, but not a second or third)
333347
0 commit comments