Skip to content

Commit

Permalink
👽 Handle ms-buildings 20230425 update in Object Detection tutorial (#106
Browse files Browse the repository at this point in the history
)

* 🛂 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.

* 👽 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.
  • Loading branch information
weiji14 committed May 31, 2023
1 parent 34e7ad3 commit a1b1ff2
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions docs/object-detection-boxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,35 @@ 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(
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"}}
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
```

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 <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"]
Expand All @@ -155,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]
Expand Down

0 comments on commit a1b1ff2

Please sign in to comment.