planetlabs / notebooks

interactive notebooks from Planet Engineering
https://developers.planet.com/
Apache License 2.0
618 stars 302 forks source link

Problem Running visualize_imagery_over_time and API key not work for tiles API #245

Open ivanSantos16 opened 1 year ago

ivanSantos16 commented 1 year ago

Hi,

First of all, thanks a lot for this amazing job. I was trying to use one of your notebooks but without success. Running Visualize Imagery Over Time Notebook was very tricky.


First Problem:

asyncio_problem


To solve the problem I just remove the await expression (but this removes the asynchronous request operation and this is not what you expect)

async with Session() as sess:
    cl = DataClient(sess)
    items = cl.search(name='imagery_over_time',search_filter=combined_filter, item_types=item_types)
    item_list = [i async for i in items]

Second Problem:

The URL generated from your get_tile_urls function is not proper. When we do requests to that URL we receive HTML 400 Code meaning the server cannot or will not process the request due to something that is perceived to be a client error (for example, malformed request syntax, invalid request message framing, or deceptive request routing). links_not_proper


I fixed the function to have a proper URL this way:

def get_tile_urls(lon, lat, item_list, limit=5, zoom=15,):
    """Get webtile urls for given coordinates, zoom, and matching filters.
    Args:
        lat: latitude float
        lon: longitude float
        zoom: zoom level int (usually between 1 and 15)
        limit: max number of ids to return
    Returns:
        tiles: json response and links to view tiles
    """
    item_list = item_list[:limit]
    tile = mercantile.tile(lon, lat, zoom)
    tile_url_template = 'https://tiles0.planet.com/data/v1/{item_type}/{item_id}/{z}/{x}/{y}.png?api_key={api_key}'
    # return [tile_url_template.format(item_type=item_types, item_id=i, x=tile.x, y=tile.y, z=zoom, api_key=API_KEY) for i in item_list]
    return [tile_url_template.format(item_type=item_types[0], item_id=i['id'], x=tile.x, y=tile.y, z=zoom, api_key=API_KEY) for i in item_list]

Third Problem:

Fixing the problem I receive No Permission response: with_proper_links

Seems that my Trial API key only works for API orders.

strixcuriosus commented 2 weeks ago

Thanks for the feedback @ivanSantos16 It's well past time to re-vamp some timelapse demos.