Skip to content

Instantly share code, notes, and snippets.

@leighghunt
Last active October 27, 2020 02:09
Show Gist options
  • Save leighghunt/5c42efedbd36ae0594f9377cb734ca1c to your computer and use it in GitHub Desktop.
Save leighghunt/5c42efedbd36ae0594f9377cb734ca1c to your computer and use it in GitHub Desktop.
Planet API examples
curl -u <API_KEY>: -H 'Content-Type: application/json' -X POST -d '{"filter":{"type":"AndFilter","config":[{"type":"GeometryFilter","field_name":"geometry","config":{"type":"Polygon","coordinates":[[[174.852471,-41.135789],[174.852209,-41.133782],[174.851432,-41.131853],[174.85017,-41.130075],[174.848472,-41.128516],[174.846402,-41.127237],[174.844042,-41.126287],[174.84148,-41.125701],[174.838816,-41.125504],[174.836152,-41.125701],[174.83359,-41.126287],[174.83123,-41.127237],[174.82916,-41.128516],[174.827462,-41.130075],[174.8262,-41.131853],[174.825423,-41.133782],[174.825161,-41.135789],[174.825423,-41.137795],[174.8262,-41.139724],[174.827462,-41.141502],[174.82916,-41.14306],[174.83123,-41.144339],[174.83359,-41.145289],[174.836152,-41.145875],[174.838816,-41.146072],[174.84148,-41.145875],[174.844042,-41.145289],[174.846402,-41.144339],[174.848472,-41.14306],[174.85017,-41.141502],[174.851432,-41.139724],[174.852209,-41.137795],[174.852471,-41.135789]]]}},{"type":"OrFilter","config":[{"type":"AndFilter","config":[{"type":"StringInFilter","field_name":"item_type","config":["PSScene4Band"]}]},{"type":"AndFilter","config":[{"type":"StringInFilter","field_name":"item_type","config":["REOrthoTile"]}]},{"type":"AndFilter","config":[{"type":"StringInFilter","field_name":"item_type","config":["SkySatCollect"]}]}]},{"type":"OrFilter","config":[{"type":"DateRangeFilter","field_name":"acquired","config":{"gte":"2020-10-13T23:00:00.000Z","lte":"2020-10-26T23:59:59.999Z"}}]}]},"item_types":["REOrthoTile","PSScene4Band","SkySatCollect"]}' https://api.planet.com/data/v1/quick-search > porirua.2weeks.geojson

Returns porirua.2weeks.geojson.

Top level of return json:

jq 'keys'  porirua.2weeks.geojson     
[
  "_links",
  "features",
  "type"
]

Count features:

jq '.features | length'  porirua.2weeks.geojson                                                                                                         3 ↵  5949  11:46:38
7

Each feature has the following keys:

jq '.features[0]|keys'  porirua.2weeks.geojson                                                                                                            ✔  5954  11:48:00
[
  "_links",
  "_permissions",
  "geometry",
  "id",
  "properties",
  "type"
]

Digging into the keys, we can get the links to thumbnails, and info about the acquisition date and cloud cover:

jq '.features[0]._links'  porirua.2weeks.geojson
{
  "_self": "https://api.planet.com/data/v1/item-types/PSScene4Band/items/20201024_233324_42_106c",
  "assets": "https://api.planet.com/data/v1/item-types/PSScene4Band/items/20201024_233324_42_106c/assets/",
  "thumbnail": "https://tiles.planet.com/data/v1/item-types/PSScene4Band/items/20201024_233324_42_106c/thumb"
}

jq '.features[0].properties|keys'  porirua.2weeks.geojson 
[
  "acquired",
  "anomalous_pixels",
  "clear_confidence_percent",
  "clear_percent",
  "cloud_cover",
  "cloud_percent",
  "columns",
  "epsg_code",
  "ground_control",
  "gsd",
  "heavy_haze_percent",
  "instrument",
  "item_type",
  "light_haze_percent",
  "origin_x",
  "origin_y",
  "pixel_resolution",
  "provider",
  "published",
  "publishing_stage",
  "quality_category",
  "rows",
  "satellite_azimuth",
  "satellite_id",
  "shadow_percent",
  "snow_ice_percent",
  "strip_id",
  "sun_azimuth",
  "sun_elevation",
  "updated",
  "view_angle",
  "visible_confidence_percent",
  "visible_percent"
]

jq '.features[0].properties.cloud_cover'  porirua.2weeks.geojson
0.62

jq '.features[0].properties.cloud_percent'  porirua.2weeks.geojson
84

jq '.features[0].properties.acquired'  porirua.2weeks.geojson
"2020-10-24T23:33:24.425945Z"

jq '.features[0].properties'  porirua.2weeks.geojson
{
  "acquired": "2020-10-24T23:33:24.425945Z",
  "anomalous_pixels": 0,
  "clear_confidence_percent": 45,
  "clear_percent": 8,
  "cloud_cover": 0.62,
  "cloud_percent": 84,
  "columns": 9923,
  "epsg_code": 32760,
  "ground_control": false,
  "gsd": 4.1,
  "heavy_haze_percent": 0,
  "instrument": "PS2.SD",
  "item_type": "PSScene4Band",
  "light_haze_percent": 0,
  "origin_x": 310623,
  "origin_y": 5465139,
  "pixel_resolution": 3,
  "provider": "planetscope",
  "published": "2020-10-25T04:39:38Z",
  "publishing_stage": "finalized",
  "quality_category": "test",
  "rows": 7599,
  "satellite_azimuth": 261.8,
  "satellite_id": "106c",
  "shadow_percent": 0,
  "snow_ice_percent": 8,
  "strip_id": "3837886",
  "sun_azimuth": 16.4,
  "sun_elevation": 60.2,
  "updated": "2020-10-25T14:21:21Z",
  "view_angle": 5.1,
  "visible_confidence_percent": 62,
  "visible_percent": 16
}

Most of the fields we're after:

jq '.features[]|{acquired:.properties.acquired, thumbnail:._links.thumbnail, cloud_cover:.properties.cloud_cover, cloud_percent:.properties.cloud_percent}'  porirua.2weeks.geojson
{
  "acquired": "2020-10-24T23:33:24.425945Z",
  "thumbnail": "https://tiles.planet.com/data/v1/item-types/PSScene4Band/items/20201024_233324_42_106c/thumb",
  "cloud_cover": 0.62,
  "cloud_percent": 84
}
{
  "acquired": "2020-10-24T23:33:22.378076Z",
  "thumbnail": "https://tiles.planet.com/data/v1/item-types/PSScene4Band/items/20201024_233322_37_106c/thumb",
  "cloud_cover": 0.67,
  "cloud_percent": 85
}
{
  "acquired": "2020-10-24T00:36:42.867584Z",
  "thumbnail": "https://tiles.planet.com/data/v1/item-types/PSScene4Band/items/20201024_003642_0f02/thumb",
  "cloud_cover": 0.44,
  "cloud_percent": null
}
{
  "acquired": "2020-10-24T00:36:41.829494Z",
  "thumbnail": "https://tiles.planet.com/data/v1/item-types/PSScene4Band/items/20201024_003641_0f02/thumb",
  "cloud_cover": 0.43,
  "cloud_percent": null
}
{
  "acquired": "2020-10-21T22:00:46.673862Z",
  "thumbnail": "https://tiles.planet.com/data/v1/item-types/PSScene4Band/items/20201021_220046_1002/thumb",
  "cloud_cover": 0.13,
  "cloud_percent": 17
}
{
  "acquired": "2020-10-21T22:00:45.665132Z",
  "thumbnail": "https://tiles.planet.com/data/v1/item-types/PSScene4Band/items/20201021_220045_1002/thumb",
  "cloud_cover": 0.06,
  "cloud_percent": 7
}
{
  "acquired": "2020-10-19T21:30:12.604396Z",
  "thumbnail": "https://tiles.planet.com/data/v1/item-types/PSScene4Band/items/20201019_213012_60_2206/thumb",
  "cloud_cover": 0.09,
  "cloud_percent": null
}

We can then get those images using the thumbnail address and adding api_key and width.

Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment