pystac-client
pystac-client copied to clipboard
Double encoding of intersects request ?
Addressing the resto issue - "pystac-client request with intersects fails against resto".
Apparently pystac_client sends intersects property with trailing double quotes i.e. :
from pystac_client import Client
client = Client.open("https://tamn.snapplanet.io")
collection = "S2"
geometry = '{"type": "Polygon", "coordinates": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]}'
search = client.search(method="GET", collections=[collection], intersects=geometry)
print(len(list(search.items_as_dicts())))
On resto side, the intersects property string retrieved format is the following:
intersects= "\"{\\\"type\\\": \\\"Polygon\\\", \\\"coordinates\\\": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]}\""
It looks like there is a double encoding of the string (i.e. trailing double quotes and slashes). The right encoding should be:
intersects= "{\"type\": \"Polygon\", \"coordinates\": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]}"
I was just about to file this against pystac_client, since I'm seeing the same behavior against PC.
The following code finds 2547 for POST, but never ends for GET.
from pystac_client import Client
collection="sentinel-2-l2a"
geometry = '{"type": "Polygon", "coordinates": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]}'
client = Client.open("https://planetarycomputer.microsoft.com/api/stac/v1")
search = client.search(method="POST", collections=[collection], intersects=geometry)
print(f"POST {len(list(search.items_as_dicts()))}")
search = client.search(method="GET", collections=[collection], intersects=geometry)
print("GET")
count = 0
for item in search.items_as_dicts():
count += 1
print(f"{count} ", end="")
Fixed by https://github.com/stac-utils/pystac-client/pull/362.