pystac-client icon indicating copy to clipboard operation
pystac-client copied to clipboard

Double encoding of intersects request ?

Open jjrom opened this issue 3 years ago • 1 comments

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]]]}"

jjrom avatar Oct 14 '22 06:10 jjrom

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="")

philvarner avatar Oct 14 '22 12:10 philvarner

Fixed by https://github.com/stac-utils/pystac-client/pull/362.

gadomski avatar Apr 03 '23 17:04 gadomski