Examples of PlanetScope data Import

The examples below include the examples of both Simple and Native search so that you can compare their interfaces even though both would usually not be used in the same workflow. Similar applies for the examples of Order products and of Order using query. To execute the requests you need to create an OAuth client as is explained here. It is named oauth in these examples.

PlanetScope data import

The examples below use the PSScene itemType with the 8-band analytic_8b_sr_udm2 bundle. If you're interested in PlanetScope data before 2018, use a 4-band bundle (analytic_sr_udm2 or analytic_udm2) instead. Additionally, note that different item types and bundles aren't compatible, so you cannot mix them in the same BYOC collection.

For PlanetScope simple search, provider must be set to "PLANET". We suggest to set the data.itemType to "PSScene" (read about the options here.).

url = "https://services.sentinel-hub.com/api/v1/dataimport/search"
query = {
"provider": "PLANET",
"bounds": {
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
15.825815,
46.714048
],
[
15.813988,
46.707248
],
[
15.832682,
46.703062
],
[
15.839931,
46.711694
],
[
15.835353,
46.716664
],
[
15.825815,
46.714048
]
]
]
}
},
"data": [
{
"itemType": "PSScene",
"productBundle": "analytic_8b_sr_udm2",
"dataFilter": {
"timeRange": {
"from": "2022-04-25T00:00:00.000Z",
"to": "2022-04-30T00:00:00.000Z"
},
"maxCloudCoverage": 30,
"nativeFilter": {
"type": "StringInFilter",
"field_name": "quality_category",
"config": [
"standard"
]
}
}
}
]
}
response = oauth.post(url, json=query)
response.raise_for_status()
results = response.json()

To get product ids:

item_ids = [feature["id"] for feature in results["features"]]

This native search is equivalent to the above simple search. Note the added Planet-specific filters PermissionFilter and AssetFilter.

url = "https://services.sentinel-hub.com/api/v1/dataimport/nativesearch"
payload = {
"provider": "PLANET",
"item_types": [
"PSScene"
],
"filter": {
"type": "AndFilter",
"config": [
{
"type": "GeometryFilter",
"field_name": "geometry",
"config": {
"type": "Polygon",
"coordinates": [
[
[
15.825815,
46.714048
],
[
15.813988,
46.707248
],
[
15.832682,
46.703062
],
[
15.839931,
46.711694
],
[
15.835353,
46.716664
],
[
15.825815,
46.714048
]
]
]
}
},
{
"type": "DateRangeFilter",
"field_name": "acquired",
"config": {
"gte": "2022-04-25T00:00:00.000Z",
"lte": "2022-04-30T00:00:00.000Z"
}
},
{
"type": "RangeFilter",
"field_name": "cloud_cover",
"config": {
"lte": 0.3
}
},
{
"type": "StringInFilter",
"field_name": "quality_category",
"config": [
"standard"
]
},
{
"type" : "PermissionFilter",
"config" : [ "assets:download" ]
},
{
"type" : "AssetFilter",
"config" : [ "ortho_analytic_8b_sr" ]
}
]
}
}
response = oauth.post(url, json=payload)
response.raise_for_status()
results = response.json()

To get product ids:

item_ids = [feature["id"] for feature in results["features"]]

Thumbnail

After searching for data, you can check the thumbnail of each item by entering the item id into the url of the thumbnail request:

item_id = '20220428_085447_69_245d'
# or get it from search results: item_id = item_ids[0]
url = f"https://services.sentinel-hub.com/api/v1/dataimport/collections/PLANET_SCOPE/products/{item_id}/thumbnail"
response = oauth.get(url)

The thumbnail can be displayed in Python using:

import io
from PIL import Image
image_bytes = io.BytesIO(response.content)
Image.open(image_bytes)

Order

For these demonstrational examples, you do not need to set the input.planetApiKey, as long as you do not modify the input objects of the data orders. To order PlanetScope data, provider must be set to "PLANET" and data.itemType to "PSScene".

Order products

To order the import of the products, which we got as a result of search and are stored in the variable item_ids:

url = "https://services.sentinel-hub.com/api/v1/dataimport/orders"
payload = {
"name": "planet products",
# collectionId is optional. Remove it to create a new collection.
"collectionId": "<your Planet collectionId>",
"input": {
"provider": "PLANET",
"planetApiKey": "", # Insert your Planet api key
"bounds": {
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
15.825815,
46.714048
],
[
15.813988,
46.707248
],
[
15.832682,
46.703062
],
[
15.839931,
46.711694
],
[
15.835353,
46.716664
],
[
15.825815,
46.714048
]
]
]
}
},
"data": [
{
"itemType": "PSScene",
"productBundle": "analytic_8b_sr_udm2",
"harmonizeTo": "NONE",
"itemIds": item_ids
}
]
}
}
response = oauth.post(url, json=payload)
response.raise_for_status()
results = response.json()

Order using query

Another way to order data is using search query, in this case using the query from above:

url = "https://services.sentinel-hub.com/api/v1/dataimport/orders"
query['input']['planetApiKey'] = "" # Insert your Planet api key
query['data'][0]["harmonizeTo"] = "NONE"
payload = {
"name": "some name",
# collectionId is optional. Remove it to create a new collection.
"collectionId": "<your Planet collectionId>",
"input": query
}
response = oauth.post(url, json=payload)
response.raise_for_status()
order = response.json()

To extract the order id from the response:

order_id = order['id']

To extract the cost in square kilometers:

sqkm = order['sqkm']

Confirm the order

Confirming the order will subtract the ordered area in km2 from your quota. To initiate import, confirm the order:

url = f"https://services.sentinel-hub.com/api/v1/dataimport/orders/{order_id}/confirm"
response = oauth.post(url)
response.raise_for_status()

Get order information

url = f"https://services.sentinel-hub.com/api/v1/dataimport/orders/{order_id}"
response = oauth.get(url)
response.raise_for_status()
order = response.json()

To extract the order status:

status = order['status']

To extract the BYOC collection ID:

collection_id = order['collectionId']

List all your orders

url = "https://services.sentinel-hub.com/api/v1/dataimport/orders"
response = oauth.get(url)
response.raise_for_status()
response.json()

Subscribe

Subscribing to PlanetScope data is similar to ordering using a search query, again starting with the query from simple search.

url = "https://services.sentinel-hub.com/api/v1/dataimport/subscriptions"
query['planetApiKey'] = "" # Insert your Planet api key
query['data'][0]["harmonizeTo"] = "NONE"
payload = {
"name": "my subscription",
# collectionId is optional. Remove it to create a new collection.
"collectionId": "<your Planet collectionId>",
"input": query
}
response = oauth.post(url, json=payload)
response.raise_for_status()
subscription = response.json()

To extract the subscription id from the response:

subscription_id = subscription['id']

To extract the area in square kilometers:

sqkm = subscription['sqkm']

Confirm the subscription

Confirming the subscription will subtract the subscribed area in km2 from your quota. To initiate import, confirm the subscription:

url = f"https://services.sentinel-hub.com/api/v1/dataimport/subscriptions/{subscription_id}/confirm"
response = oauth.post(url)
response.raise_for_status()

Get subscription information

url = f"https://services.sentinel-hub.com/api/v1/dataimport/subscriptions/{subscription_id}"
response = oauth.get(url)
response.raise_for_status()
subscription = response.json()

To extract the subscription status:

status = subscription['status']

To extract the BYOC collection ID:

collection_id = subscription['collectionId']

List subscription deliveries

To list deliveries created so far for the subscription:

url = f"https://services.sentinel-hub.com/api/v1/dataimport/subscriptions/{subscription_id}/deliveries"
response = oauth.get(url)
response.raise_for_status()
deliveries = response.json()

List all your subscriptions

url = "https://services.sentinel-hub.com/api/v1/dataimport/subscriptions"
response = oauth.get(url)
response.raise_for_status()
response.json()

Access PlanetScope data in a BYOC collection and process a truecolor image

This is a normal Process API request that uses a BYOC collectionId that can be fetched from the get order information request.

response = oauth.post('https://services.sentinel-hub.com/api/v1/process',
headers={"Authorization" : "Bearer <your_access_token>"},
json={
'input': {
"bounds": {
"properties": {
"crs": "http://www.opengis.net/def/crs/EPSG/0/32633"
},
"bbox": [562218,5174019,564201,5172501]
},
"data": [{
"type": "byoc-<collectionId>",
"dataFilter": {
"timeRange": {
"from": "2022-04-25T00:00:00.000Z",
"to": "2022-04-28T00:00:00.000Z"
}
}
}
]
},
"output": {
"width": 512,
"height": 512
},
"evalscript": """
//VERSION=3
function setup() {
return {
input: [{"bands": ["Red", "Green", "Blue", "dataMask"]}],
output: { bands: 4}
};
}
var f = 10000;
function evaluatePixel(sample) {
return [sample.Red/f*2.5, sample.Green/f*2.5, sample.Blue/f*2.5, sample.dataMask];
}
"""
}
)