FR: add_stac_layer to accept a pystac.item.Item directly
robmarkcole opened this issue · 9 comments
Description
The API I am working with doesn't return a stac json file on a url, and I understand this is not a firm requirement.
This FR is to support passing apystac.item.Item
directly to add_stac_layer
Source code
assert type(item) == pystac.item.Item
m = leafmap.Map()
m.add_stac_layer(item, bands=["red", "green", "blue"], name="False color")
m
Current workaround
Dump item to local file, run a local server, point to url
item_file = "item.json"
with open(item_url, 'w') as f:
json.dump(item.to_dict(), f)
os.system(f"python -m http.server 8080 &") # Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
item_url = "http://0.0.0.0:8080/" + item_file
m = leafmap.Map()
m.add_stac_layer(item_url, bands=["red", "green", "blue"], name="False color")
m
Would this work for you?
assert type(item) == pystac.item.Item
url = item.self_href
m = leafmap.Map()
m.add_stac_layer(url, assets=["red", "green", "blue"], name="False color")
m
In my case that returns Client error '401 Unauthorized' for url
- not sure if that is specific to our api, but we are using presigned urls for the tifs themselves
It may be your own api problem. A standard pystac Item should have the self_href
attribute for retrieving the URL. Try the following example.
import leafmap
url = "https://earth-search.aws.element84.com/v1/"
collection = "sentinel-2-l2a"
time_range = "2020-12-01/2020-12-31"
bbox = [-122.2751, 47.5469, -121.9613, 47.7458]
result = leafmap.stac_search(
url=url,
max_items=10,
collections=[collection],
bbox=bbox,
datetime=time_range,
query={"eo:cloud_cover": {"lt": 10}},
sortby=[{"field": "properties.eo:cloud_cover", "direction": "asc"}],
)
item = result.get_all_items()[-1]
m = leafmap.Map()
m.add_stac_layer(item.self_href, assets=["nir", "red", "green"])
m
Thanks - I believe the issue is that url is not a pre signed url currently, so auth fails
Should we close this issue? Or is there anything leafmap should improve to support this?
I still think it would be great to support pystac.item.Item
as an arg, but if that is not going to happen we can close
Amazing speed on this, thanks!
My pleasure! Thank you for the suggestion.