From c62753fc21b875d88624ddcb6cd932692d0ee47f Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Wed, 31 May 2023 15:38:23 +1200 Subject: [PATCH 1/2] :passport_control: Use sign_inplace modifier in pystac_client API call Using `pystac_client.Client.open(..., modifier=planetary_computer.sign_inplace` to handle the STAC Asset signing directly when accessing the Planetary Computer STAC API. Added some notes to the PySTAC-Client documentation as an extra reference. --- docs/object-detection-boxes.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/object-detection-boxes.md b/docs/object-detection-boxes.md index 5b34159..c14e434 100644 --- a/docs/object-detection-boxes.md +++ b/docs/object-detection-boxes.md @@ -133,7 +133,8 @@ cloud-native columnar ๐Ÿ€ค geospatial vector file format) over our study area. ```{code-cell} catalog = pystac_client.Client.open( - url="https://planetarycomputer.microsoft.com/api/stac/v1" + url="https://planetarycomputer.microsoft.com/api/stac/v1", + modifier=planetary_computer.sign_inplace, ) items = catalog.search( collections=["ms-buildings"], query={"msbuildings:region": {"eq": "Brunei"}} @@ -142,11 +143,18 @@ item = next(items.get_items()) item ``` -Next, we'll sign ๐Ÿ” the URL to the STAC Item Asset, and load โคต๏ธ the GeoParquet -file using {py:func}`geopandas.read_parquet`. +```{note} +Accessing the building footprint STAC Assets from Planetary Computer will +require signing ๐Ÿ” the URL. This can be done with a `modifier` function in the +{py:meth}`pystac_client.Client.open` call. See also 'Automatically modifying +results' under {doc}`PySTAC-Client Usage `). +``` + +Next, we'll load โคต๏ธ the GeoParquet file using +{py:func}`geopandas.read_parquet`. ```{code-cell} -asset = planetary_computer.sign(item.assets["data"]) +asset = item.assets["data"] geodataframe = gpd.read_parquet( path=asset.href, storage_options=asset.extra_fields["table:storage_options"] From ea881c0b305e111d427347816e2fbd75b02dff66 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Wed, 31 May 2023 15:54:20 +1200 Subject: [PATCH 2/2] :alien: Filter ms-buildings to those intersecting bbox area of interest The Microsoft Building footprint dataset was updated on 25 April 2023 to a Delta Lake storage format, which changed the schema and added an extra layer on top of the geoparquet files designed for faster bounding box based queries, see https://web.archive.org/web/20230315044820/https://planetarycomputer.microsoft.com/dataset/ms-buildings#Example-Notebook. The old method of filtering just by a `msbuildings:region` attribute now fails however, so need to add a bounding box region argument to the intersect parameter when performing the STAC API search. --- docs/object-detection-boxes.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/object-detection-boxes.md b/docs/object-detection-boxes.md index c14e434..cef4779 100644 --- a/docs/object-detection-boxes.md +++ b/docs/object-detection-boxes.md @@ -129,7 +129,8 @@ dataarray Now to pull in some building footprints ๐Ÿ›–. Let's make a STAC API query to get a [GeoParquet](https://github.com/opengeospatial/geoparquet) file (a -cloud-native columnar ๐Ÿ€ค geospatial vector file format) over our study area. +cloud-native columnar ๐Ÿ€ค geospatial vector file format) that intersects our +study area. ```{code-cell} catalog = pystac_client.Client.open( @@ -137,7 +138,9 @@ catalog = pystac_client.Client.open( modifier=planetary_computer.sign_inplace, ) items = catalog.search( - collections=["ms-buildings"], query={"msbuildings:region": {"eq": "Brunei"}} + collections=["ms-buildings"], + query={"msbuildings:region": {"eq": "Brunei"}}, + intersects=shapely.geometry.box(minx=114.94, miny=4.88, maxx=114.95, maxy=4.89), ) item = next(items.get_items()) item @@ -163,10 +166,11 @@ geodataframe ``` This {py:class}`geopandas.GeoDataFrame` contains building outlines across -Brunei ๐Ÿ‡ง๐Ÿ‡ณ. Let's do a spatial subset โœ‚๏ธ to just the Kampong Ayer study area -using {py:attr}`geopandas.GeoDataFrame.cx`, and reproject it using -{py:meth}`geopandas.GeoDataFrame.to_crs` to match the coordinate reference -system of the optical image. +Brunei ๐Ÿ‡ง๐Ÿ‡ณ that intersects and extends beyond our study area. Let's do a spatial +subset โœ‚๏ธ to just the Kampong Ayer study area using +{py:attr}`geopandas.GeoDataFrame.cx`, and reproject the polygon coordinates +using {py:meth}`geopandas.GeoDataFrame.to_crs` to match the coordinate +reference system of the optical image. ```{code-cell} _gdf_kpgayer = geodataframe.cx[114.94:114.95, 4.88:4.89]