Skip to content

Commit

Permalink
fix: fix gdal flushing and add description tag to vrt (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thuhaa authored Mar 7, 2024
1 parent feb7093 commit 4ce1f36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ services:
# See https://github.com/developmentseed/titiler/discussions/387
#platform: linux/amd64
# enable `image` if you would like to use Docker image from Github package
# image: ghcr.io/undp-data/titiler-aks:v0.0.2
image: ghcr.io/undp-data/cogserver:latest
# enable `build` if you would like to build Docker image from source code
image: undpgeohub.azurecr.io/cogserver-debug
# image: undpgeohub.azurecr.io/cogserver-debug
build:
context: .

Expand All @@ -19,11 +19,11 @@ services:
# env_file:
# - gdal_rio.env
ports:
- 8000:80
# environment:
- "8000:8000"
environment:
# # Application
# - HOST=0.0.0.0
# - PORT=8000
- HOST=0.0.0.0
- PORT=8000



25 changes: 8 additions & 17 deletions src/cogserver/extensions/vrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ async def create_vrt_from_urls(
srcNoData = " ".join(srcNoData)
options = gdal.BuildVRTOptions(
separate=True,
bandList=list(range(1, len(urls) + 1)),
xRes=xRes,
yRes=yRes,
resampleAlg=resamplingAlg,
Expand All @@ -51,7 +50,8 @@ async def create_vrt_from_urls(
)

with tempfile.NamedTemporaryFile() as temp:
gdal.BuildVRT(temp.name, urls, options=options)
ds = gdal.BuildVRT(temp.name, urls, options=options)
ds = None
with open(temp.name, "r") as file:
file_text = ET.fromstring(file.read())
available_bands = file_text.findall("VRTRasterBand")
Expand All @@ -70,6 +70,12 @@ async def create_vrt_from_urls(
metadata_dict = {}
pattern = r"(.*?)=(.*)"

# non-case sensitive description pattern
description_pattern = r"(?i)description=(.*)"

description_matches = re.findall(description_pattern, dataset_metadata)
if description_matches:
ET.SubElement(source_band, "Description").text = description_matches[0]
matches = re.findall(pattern, dataset_metadata)
for match in matches:
metadata_dict[match[0].strip()] = match[1].strip()
Expand Down Expand Up @@ -124,21 +130,6 @@ async def create_vrt(
yRes: Optional[float] = Query(None,
description="Y resolution. Applicable only when `resolution` is `user`")
):
"""
Create a VRT from multiple COGs supplied as URLs
Args:
urls (List[str]): List of URLs
srcNoData (List[str], optional): Set nodata values for input bands (different values can be supplied for each band). If the option is not specified, the intrinsic nodata settings on the source datasets will be used (if they exist). The value set by this option is written in the NODATA element of each ComplexSource element. Use a value of None to ignore intrinsic nodata settings on the source datasets. Defaults to None.
vrtNoData (List[str], optional): Set nodata values at the VRT band level (different values can be supplied for each band). If the option is not specified, intrinsic nodata settings on the first dataset will be used (if they exist). The value set by this option is written in the NoDataValue element of each VRTRasterBand element. Use a value of None to ignore intrinsic nodata settings on the source datasets. Defaults to None.
resamplingAlg (Literal["nearest", "bilinear", "cubic", "cubicspline", "lanczos", "average", "mode"], optional): Resampling algorithm. Defaults to "nearest".
resolution (Literal["highest", "lowest", "average", "user"], optional): Resolution to use for the resulting VRT. Defaults to "average".
xRes (Optional[float], optional): X resolution. Defaults to None.
yRes (Optional[float], optional): Y resolution. Defaults to None.
Returns:
Response: VRT XML
"""
if len(urls) < 1:
return Response("Please provide at least two URLs", status_code=400)

Expand Down

0 comments on commit 4ce1f36

Please sign in to comment.