Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"codeRepository": "https://github.com/eoap/mastering-app-package.git",
"dateCreated": "2022-09-01",
"datePublished": "2022-09-25",
"dateModified": "2024-11-07",
"dateModified": "2025-08-18",
"name": "Water Bodies Detection",
"version": "1.1.0",
"version": "1.1.1",
"description": "The Water Bodies Detection is an Application that uses the NDWI index and the Otsu threshold to detect water bodies using Sentinel-2 or Landsat-9 data",
"developmentStatus": "active",
"downloadUrl": "https://github.com/eoap/mastering-app-package/releases/tag/1.1.0",
"downloadUrl": "https://github.com/eoap/mastering-app-package/releases/tag/1.1.1",
"relatedLink": [
"https://eoap.github.io/mastering-app-package"
],
Expand Down
2 changes: 1 addition & 1 deletion water-bodies/command-line-tools/crop/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM docker.io/library/python:3.10-slim@sha256:80619a5316afae7045a3c13371b0ee670f39bac46ea1ed35081d2bf91d6c3dbd

RUN pip install --no-cache-dir rasterio click pystac loguru pyproj shapely && \
RUN pip install --no-cache-dir rasterio click pystac loguru pyproj shapely planetary_computer && \
python -c "import rasterio"

ADD app.py /app/app.py
Expand Down
16 changes: 11 additions & 5 deletions water-bodies/command-line-tools/crop/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@
from pyproj import Transformer
from shapely import box
from loguru import logger

import planetary_computer

def aoi2box(aoi):
"""Converts an area of interest expressed as a bounding box to a list of floats"""
return [float(c) for c in aoi.split(",")]

def sign_asset_href(asset):
"""Adjusts the asset href to be relative to the current working directory"""
signed_asset = planetary_computer.sign(asset) # asset is the pystac Asset object genetated from the STAC item
#logger.info(f"Signed asset href: {signed_asset.get_absolute_href()}")
return signed_asset

def get_asset(item, common_name):
"""Returns the asset of a STAC Item defined with its common band name"""
for _, asset in item.get_assets().items():

if not "data" in asset.to_dict()["roles"]:
continue

if 'https://planetarycomputer.microsoft.com/api/stac/v1' in item.get_self_href():
asset = sign_asset_href(asset)
eo_asset = pystac.extensions.eo.AssetEOExtension(asset)
if not eo_asset.bands:
continue
Expand Down Expand Up @@ -77,16 +84,15 @@ def crop(item_url, aoi, band, epsg):
raise ValueError(msg)

bbox = aoi2box(aoi)

with rasterio.open(asset.get_absolute_href()) as src:

transformer = Transformer.from_crs(epsg, src.crs, always_xy=True)

print(epsg, src.crs)
minx, miny = transformer.transform(bbox[0], bbox[1])
maxx, maxy = transformer.transform(bbox[2], bbox[3])

transformed_bbox = box(minx, miny, maxx, maxy)

logger.info(f"Transformed bounding box: {transformed_bbox}")
logger.info(f"Crop {asset.get_absolute_href()}")

out_image, out_transform = rasterio.mask.mask(
Expand Down