Skip to content

Commit

Permalink
Improve add_stac_layer to support pystac.Item (#944)
Browse files Browse the repository at this point in the history
Co-authored-by: Qiusheng Wu <[email protected]>
  • Loading branch information
giswqs and Qiusheng Wu authored Oct 30, 2024
1 parent 0b32f99 commit f0a22c5
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions leafmap/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,12 @@ def stac_tile(
if collection is not None and titiler_endpoint is None:
titiler_endpoint = "planetary-computer"

if isinstance(url, pystac.Item):
try:
url = url.self_href
except Exception as e:
print(e)

if url is not None:
kwargs["url"] = url
if collection is not None:
Expand Down Expand Up @@ -737,6 +743,12 @@ def stac_bounds(
if collection is not None and titiler_endpoint is None:
titiler_endpoint = "planetary-computer"

if isinstance(url, pystac.Item):
try:
url = url.self_href
except Exception as e:
print(e)

if url is not None:
kwargs["url"] = url
response = requests.get(url)
Expand Down Expand Up @@ -779,6 +791,13 @@ def stac_center(
Returns:
tuple: A tuple representing (longitude, latitude)
"""

if isinstance(url, pystac.Item):
try:
url = url.self_href
except Exception as e:
print(e)

bounds = stac_bounds(url, collection, item, titiler_endpoint, **kwargs)
center = ((bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2) # (lon, lat)
return center
Expand Down Expand Up @@ -809,6 +828,12 @@ def stac_bands(
if collection is not None and titiler_endpoint is None:
titiler_endpoint = "planetary-computer"

if isinstance(url, pystac.Item):
try:
url = url.self_href
except Exception as e:
print(e)

if url is not None:
kwargs["url"] = url
if collection is not None:
Expand Down Expand Up @@ -852,6 +877,12 @@ def stac_stats(
if collection is not None and titiler_endpoint is None:
titiler_endpoint = "planetary-computer"

if isinstance(url, pystac.Item):
try:
url = url.self_href
except Exception as e:
print(e)

if url is not None:
kwargs["url"] = url
if collection is not None:
Expand Down Expand Up @@ -933,6 +964,12 @@ def stac_info(
if collection is not None and titiler_endpoint is None:
titiler_endpoint = "planetary-computer"

if isinstance(url, pystac.Item):
try:
url = url.self_href
except Exception as e:
print(e)

if url is not None:
kwargs["url"] = url
if collection is not None:
Expand Down Expand Up @@ -978,6 +1015,12 @@ def stac_info_geojson(
if collection is not None and titiler_endpoint is None:
titiler_endpoint = "planetary-computer"

if isinstance(url, pystac.Item):
try:
url = url.self_href
except Exception as e:
print(e)

if url is not None:
kwargs["url"] = url
if collection is not None:
Expand Down Expand Up @@ -1023,6 +1066,12 @@ def stac_assets(
if collection is not None and titiler_endpoint is None:
titiler_endpoint = "planetary-computer"

if isinstance(url, pystac.Item):
try:
url = url.self_href
except Exception as e:
print(e)

if url is not None:
kwargs["url"] = url
if collection is not None:
Expand Down Expand Up @@ -1072,6 +1121,12 @@ def stac_pixel_value(
if collection is not None and titiler_endpoint is None:
titiler_endpoint = "planetary-computer"

if isinstance(url, pystac.Item):
try:
url = url.self_href
except Exception as e:
print(e)

if url is not None:
kwargs["url"] = url
if collection is not None:
Expand Down

0 comments on commit f0a22c5

Please sign in to comment.