Cheat Sheet: Planet Command Line Interface

If you haven't used it yet, the Planet Command Line Interface (or CLI) allows you to search, and download images. It supports batch activation and download and can be a powerful tool if you are working with a lot of imagery. Your command line in windows is the command prompt and NOT the PowerShell, and it is the terminal in both Mac OS and most Linux distributions. Windows OS does not come with a default Python installed so you can learn how to install Python for your Operating system here. Once you have python installed you can test it by typing pip -h in your command prompt or terminal. This will make sure your system can access python and the pip installer and then install the Planet CLI by typing 

pip install planet

 

To Initialize the Planet CLI (You only have to do this once)
planet init
Initializes the planet client (you need your email address and password for your planet account)

Search Image Only
This tool allows you to search for availability of images the example here searches for all images in 2018 however since that is a large number the --limit allows you to limit how many images you want to look at. If you remove the --limit flag in the current setup the tool will print all images of the type PSScene4Band analytic in 2018 that intersects with your geometry and has cloud cover less than 20%)

planet data search --item-type 'PSScene4Band' --asset-type 'analytic' --date acquired gt '2018-01-01' --date acquired lt '2018-12-31' --range cloud_cover lt '0.2' --geom "full path to geometry.geojson" --limit 'Maximum number of images to search for'

Batch Download Images
This tool activates and downloads Planet data. In this example, the tool searches for all images in January 2018 and downloads it to a destination folder. If you remove the --dest flag in the current setup the tool will download all images of the type PSScene4Band analytic in January 2018 that intersects with your geometry and has cloud cover less than 20% to the current folder you are in your command line)

planet data download --item-type 'PSScene4Band' --asset-type 'analytic' --date acquired gt '2018-01-01' --date acquired lt '2018-02-01' --range cloud_cover lt '0.2' --geom "full path to geometry.geojson" --dest 'full path to folder where you want to download all images'

Quick tip: replace asset-type analytic with analytic_xml in the download and you get metadata. You can get a reference to all items and assets here

Download Image Footprints with Metadata
This allows you to download the image footprints along with the metadata for each image as a geojson file. You can open this geojson file in geojson.io and export it as a shapefile, or kml or whatever you want to work with. This is useful when you want the metadata and footprints to make some estimates about the final data you may be interested in download without using up your Quota. For example, the current setup downloads all image footprints of type PSScene4Band analytic from Jan 1 to Jan 10 with cloud cover less than 20% . Again you can specify a limit or the maximum number of images to look for or remove it to get all images. 

planet data search --item-type 'PSScene4Band' --asset-type 'analytic' --date acquired gt '2018-01-01' --date acquired lt '2018-10-01' --range cloud_cover lt '0.2' --geom "full path to geometry.geojson" --limit 'Maximum number of images to search for' >>"full path to footprint.geojson"

Pro tip: Do not give it a large date range or a large geometry, the Geojson file will get large quickly and the process may fail.

Search and Download a Single Image using ID
You can do this easily using a string filter, look for a specific image id, for example, if you have downloaded a single image and you want the exact metadata file associated with it you can use this to search and download that single image or metadata as needed.

To search (Image and metadata for a Single Image)

planet data search --string-in id 20180912_133342_0f3b --item-type PSScene4Band --asset-type analytic

To download (Image and metadata for a Single Image)

planet data download --string-in id 20180912_133342_0f3b --item-type PSScene4Band --asset-type analytic --dest "full path where you want to download image"

planet data download --string-in id 20180912_133342_0f3b --item-type PSScene4Band --asset-type analytic_xml --dest "full path where you want to download image metadata"

This is not a complete list of all capabilities of the CLI but this is some of the most common ones I use and I think will be useful. Feel free to add more to the discussion.

4

Comments

9 comments
  • Hello Samapriya

    Is this the correct syntax to Batch Download Images

    C:\>planet data download --item-type 'PSScene3Band' --asset-type 'analytic' --date acquired gt '2019-01-01' --date acquired lt '2019-03-29' --range cloud_cover lt '0.2' --geom 'C:\razortek\year2019\projects\tulsa\texoma.json' --dest 'C:\razortek\year2019\projects'

    Am I missing something in the syntax following the above example

    planet data download --item-type 'PSScene3Band' --asset-type 'analytic' --date acquired gt '2018-01-01' --date acquired lt '2018-02-01' --range cloud_cover lt '0.2' --geom "full path to geometry.geojson" --dest 'full path to folder where you want to download all images'

    When I run the above command I receive the following error

    Error: Invalid value for "item--type": invalid choice 'PSSScene3Band'.

    Am I missing a symbol or selected the wrong symbol?

    Any help would be appreciated.

    Thanks

    Daniel Rodriguez

    0
  • Hi Daniel,

    The error message indicates that there was a spelling issue: PSSScene3Band should be PSScene3Band.

    Best,

    0
  • I deleted the extra S and still receive the same error mention above?

     

    C:\>planet data download --item-type 'PSScene3Band' --asset-type 'analytic' --date acquired gt '209-01-01' --date acquired lt '2019-03-29' --range cloud_cover lt '0.2' --geom 'C:\razortek\year2019\projects\tulsa\texoma.json' --dest 'C:\razortek\year2019\projects'


    Usage: planet data download [OPTIONS]
    Try "planet data download --help" for help.

    Error: Invalid value for "--item-type": invalid choice: 'PSScene3Band'.
    Choose from:
    MYD09GQ
    PSScene4Band
    SkySatScene
    PSScene3Band
    Sentinel1
    REScene
    REOrthoTile
    Sentinel2L1C
    MOD09GA
    MYD09GA
    SkySatCollect
    PSOrthoTile
    Landsat8L1G
    MOD09GQ

    C:\>

    I am missing a character?

    0
  • Hi Daniel,

    I guess on Windows, it might be necessary to remove the ' marks around the parameters. I also see that the date has a mistake that will cause you to download very old data: 209-01-01.

    I also suggest you add a limit to the number of items you download, at least to start:


    planet data download --item-type PSScene3Band --asset-type analytic --date acquired gt 2019-01-01 --date acquired lt 2019-03-29 --range cloud_cover lt 0.2 --geom 'C:\razortek\year2019\projects\tulsa\texoma.json' --dest 'C:\razortek\year2019\projects' --limit 1

    0
  • Hello Benjamin

    Thanks for your help on the syntax below

    planet data download --item-type PSScene3Band --asset-type analytic --date acquired gt 2019-01-01 --date acquired lt 2019-03-29 --range cloud_cover lt 0.2 --geom 'C:\razortek\year2019\projects\tulsa\texoma.json' --dest 'C:\razortek\year2019\projects' --limit 1

    When I ran the script it display lat long coordinates inside the dos screen. I have 2 questions

    1. Do you have to specific a json file to dump the coordinates into

    2. after the coordinates were display the message below was displayed

    Error:InValidAPIKey: No API key provided

    Where do I list RazorTek reseller API key in the script?

    Any help would be appreciated.

    Soooo close for the process to run correct.

    0
  • Hello Ben

     

    I forgot to login in with my planet username and password.

    I ran the above script and it did select an image based on the parameters listed and downloaded a tiff image question it did not create json file to be converted to a shapefile in ArcMap.

    Do I need to add a .json filename at the end of this command?  --dest 'C:\razortek\year2019\projects'

    Any help would appreciated

    0
  • Hi Daniel,

    There are a couple of things that might help

    The geometry object that you are passing should be a geojson, create one using geojson.io

    The setup you are using will only download the images and not export any geojson.

    planet data download --item-type PSScene3Band --asset-type analytic --date acquired gt 2019-01-01 --date acquired lt 2019-03-29 --range cloud_cover lt 0.2 --geom 'C:\razortek\year2019\projects\tulsa\texoma.json' --dest 'C:\razortek\year2019\projects' --limit 1

    I am not really sure what you are exporting to be used with ArcMap, The tool does not export shapefiles, but you can export the footprints of all the images you want into a GeoJSON file and then open it in geojson.io and export to shapefile

    planet data search --item-type PSScene3Band --asset-type analytic --date acquired gt 2019-01-01 --date acquired lt 2019-03-29 --range cloud_cover lt 0.2 --geom 'C:\razortek\year2019\projects\tulsa\texoma.json' --limit 1 > "path to footprint.geojson"

    Hope that helps

     

    Sam

    0
  • Hello Sam

    Thanks for the information. I tried to create geojson file but I am receiving the following error

    Error:Invalid value for "--limit": to it is not valid integer

    Here is the syntax I type

    planet data search --item-type PSScene3Band --asset-type analytic --date acquired gt 2019-03-10 --date acquired lt 2019-03-29 --range cloud_cover lt 0.2 --geom C:\razortek\year2019\projects\omaha\geospencer.json --limit 1>path to C:\razortek\year2019\omaha\footprint.geojson

    Is the syntax path not correct to create the footprint.geojson file or I am missing a character?

    Thanks

    Daniel

    0
  • You'll need to add a space before and after the > symbol.

    0

Please sign in to leave a comment.

Didn't find what you were looking for?

New post