Closed scottyhq closed 2 years ago
We use requests under the hood, so something like this should get you what you want w/o too much effort:
import requests
params = {
"collections": ["cop-dem-glo-30"],
"bbox": [88.214, 27.927, 88.302, 28.034],
}
response = requests.get("https://planetarycomputer.microsoft.com/api/stac/v1", params=params)
print(response.url)
# https://planetarycomputer.microsoft.com/api/stac/v1?collections=cop-dem-glo-30&bbox=88.214&bbox=27.927&bbox=88.302&bbox=28.034
Thanks @gadomski ! That certainly works with a small modification (bbox=','.join([str(x) for x in bbox]
)
Maybe I'm the only one, but I think it would be nice to access the formatted URL directly from the search object using search.get_parameters()
behind the scenes. It's useful to share with others and potentially see other defaults that are being submitted (like 'limit': 100
). Since search.url
is already spoken for, maybe search.request
?
Shouldn't be a hard add -- I've converted this issue into a feature request.
One thing to note is that not all API requests are sent via GET -- e.g. when I updated your example to actually retrieve items, it used POST. Whatever method name we use for this feature, it should document the fact that the returned URL may not be exactly what is actually sent to the server by the ItemSearch.
Maybe I've overlooked something, but scanning through examples, code and docs, I don't see an easy way to print an encoded search url from Python:
Something like this doesn't quite work b/c of lists and parentheses
I was trying to do this to work with GDAL's STAC reader without saving to a local JSON...