0

I am trying to download a specific area of interest using planet API. I've activated the image containing my area, which seems successful. Then I'm downloading the tif file, which also gives a result, though not expected. My implementation is in python.

Here is my activation.py file

import os
import requests

item_id = "20161015_204133_1_0c0b"
item_type = "PSScene3Band"
asset_type = "visual"

PL_API_KEY='your key'

session = requests.Session()
session.auth = (PL_API_KEY, '')
# request an item
item = \
session.get(
("https://api.planet.com/data/v1/item-types/" +
"{}/items/{}/assets/").format(item_type, item_id))

# extract the activation url from the item for the desired asset
item_activation_url = item.json()[asset_type]["_links"]["activate"]

print("Activation URL: ",item_activation_url)

# request activation
response = session.post(item_activation_url)
print(response.status_code)

This is my response.

Activation URL: (removed api url) 204

And my area of interest file, subarea.geojson

{
      "type": "FeatureCollection",
      "features": [
        {
          "type": "Feature",
          "properties": {},
          "geometry": {
            "type":"Polygon",
            "coordinates":[
               [
                [
                  -121.92309379577637,
                  37.720983558420585
                ],
                [
                  -121.92190825939177,
                  37.71960024532617
                ],
                [
                  -121.92086756229399,
                  37.720139146443614
                ],
                [
                  -121.92214965820311,
                  37.72150547658797
                ],
                [
                  -121.92309379577637,
                  37.720983558420585
                ]
              ]

            ]
          }
        }
      ]
    }

Here is my download.py file

    from osgeo import gdal
    from requests.auth import HTTPBasicAuth
    import os
    import requests

    item_id = "20161015_204133_1_0c0b"
    item_type = "PSScene3Band"
    asset_type = "visual"
    item_url = 'https://api.planet.com/data/v1/item-types/{}/items/{}/assets'.format(item_type, item_id)

    PLANET_API_KEY= 'xxxxxxxx'
    # Request a new download URL
    result = requests.get(item_url, auth=HTTPBasicAuth(PLANET_API_KEY, ''))
    download_url = result.json()[asset_type]['location']

    vsicurl_url = '/vsicurl/' + download_url
    output_file = item_id + '_subarea.tif'

    # GDAL Warp crops the image by our AOI, and saves it
    gdal.Warp(output_file, vsicurl_url, dstSRS = 'EPSG:4326', cutlineDSName 
    = 'subarea2.geojson', cropToCutline = True)

Note: I did make sure the area of interest is present inside the subarea(refer item_id).

Result file here. My result Image .tif file

Im opening the file using qgis, I got nothing.

  • 1
    Running gdalinfo -hist for your image reveals that extent of the image is right but all the pixels have value 0 on all the bands. I believe that there is some problem in accessing the download_url or then there are no data in your area of interest. – user30184 Apr 2 '18 at 9:07
  • What happens when you download output_file to disk then run gdal.Warp on it? – user2856 Apr 2 '18 at 9:16
  • This is my output file. drive.google.com/open?id=1xY_klqeYSMn2HWkBv97cKyrWvMuuBuWs before gdal.Warp – Simhadri Akaash Apr 2 '18 at 9:39
  • Your subarea seems to be outside the source image (too much west and south). Gdalinfo reports the lower left corner of the source as 121d48' 3.85"W, 37d47'29.60"N. Your subarea is around 121.98 degrees W and 37.72 degrees N. Converting the minutes and seconds of gdalinfo report into decimal degrees will help with finding the error. – user30184 Apr 2 '18 at 11:08
  • Thank you very much. An additional help needed if you could, – Simhadri Akaash Apr 2 '18 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.