1

I've trying to download an AOI from planet using this same example. Planet Example Link

My code is ditto. I keep getting this error.

KeyError: 'visual'.

I did activate the scene containing the subarea, number of times. My code if it helps.

subarea.geojson

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type":"Polygon",
        "coordinates":[
          [
             [
                -114.176423930378903,
                32.691933554346988
             ],
             [
                -114.176423930378903,
                32.685249521402788
             ],
             [
                -114.168019741897595,
                32.685249521402788
             ],
             [
                -114.168019741897595,
                32.691933554346988
             ],
             [
                -114.176423930378903,
                32.691933554346988
             ]
          ]
        ]
      }
    }
  ]
}

download_aoi.py

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

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

    # 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 = 'subarea.geojson', cropToCutline = True)

Error:Traceback (most recent call last): File "download_aoi.py", line 14, in download_url = result.json()[asset_type]['location'] KeyError: 'visual'

  • The result seems to have no "visual" key. Whats the output of print(result.text). – pLumo Apr 3 '18 at 6:38
  • Thanks for responding. Outputs: {} , completely blank. I can't understand the reason. Is the item_id in planet example wrong! – Simhadri Akaash Apr 3 '18 at 6:46
  • Maybe it's best to ask planet: If you have any trouble with this guide, let us know at support@planet.com. – pLumo Apr 3 '18 at 6:52
  • Hey, I used a different set of inputs, the output of result.text does contain location, and I get key error 'location'. result.text output here. docs.google.com/document/d/… – Simhadri Akaash Apr 3 '18 at 7:07
  • please edit the question with the new information and also add the new output. – pLumo Apr 3 '18 at 7:10

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.