Skip to content

Conversation

@alecsandrei
Copy link

@alecsandrei alecsandrei commented Jul 29, 2025

Hello,

In tutorial 3, the bbox parameter is not correctly set for the WCS GetCoverage request:

# get parameters for grid
bbox2 = Study_area.bounds.values[0].tolist() # get bbox for the Western Mediterranean Sea study area 
crs2 = Study_area.crs.srs # get crs of the Study Area file

#Adding 2 decimal degrees to each side of the bbox

bbox2 = [bbox2[0]-2,bbox2[1]-2,bbox2[2]+2,bbox2[3]+2]
print(bbox2)
[-7.6, 33.07066846, 18.22312212, 46.42720294]
# GetCoverage request
response = wcs.getCoverage(identifier=[dataset],
                           bbox=bbox2,
                           format='image/tiff',
                           crs=crs2,
                           resx=0.00833333,resy=0.00833333,
                           timeout = 120
                           )
print(response.geturl())
with open(f'data/{dataset.replace(":","_")}.tif','wb') as outfile:
    outfile.write(response.read())
https://ows.emodnet-seabedhabitats.eu/geoserver/emodnet_open_maplibrary/wcs?version=2.0.1&request=GetCoverage&service=WCS&CoverageID=emodnet_open_maplibrary__mediseh_cora&crs=EPSG%3A4326&format=image%2Ftiff

A quick look at the response for DescribeCoverage reveals that the dataset is in EPSG 3857 and requires the X and Y axis labels to correctly define the bounding box.

https://ows.emodnet-seabedhabitats.eu/geoserver/emodnet_open_maplibrary/wcs?SERVICE=WCS&REQUEST=DescribeCoverage&VERSION=2.0.1&CoverageID=emodnet_open_maplibrary__mediseh_cora
<gml:Envelope srsName="http://www.opengis.net/def/crs/EPSG/0/3857" axisLabels="X Y" uomLabels="m m" srsDimension="2">

In this PR, I propose the following change for the snippets above:

# get parameters for grid
Study_area_3857 = Study_area.to_crs('EPSG:3857')
bbox2 = Study_area_3857.bounds.values[0].tolist() # get bbox for the Western Mediterranean Sea study area
crs2 = Study_area_3857.crs.srs

# Adding 2 decimal degrees to each side of the bbox

buffer = 111_000 * 2
subsets = [
    ('X', bbox2[0] - buffer, bbox2[2] + buffer),
    ('Y', bbox2[1] - buffer, bbox2[3] + buffer)
]
print(subsets)
[('X', -845389.1484423319, 2027949.6934754928), ('Y', 3951488.8573080758, 5753792.596194154)]
# GetCoverage request

response = wcs.getCoverage(identifier=[dataset],
                           format='image/tiff',
                           subsets=subsets,
                           timeout=120)
print(response.geturl())
with open(f'data/{dataset.replace(":","_")}.tif','wb') as outfile:
    outfile.write(response.read())
https://ows.emodnet-seabedhabitats.eu/geoserver/emodnet_open_maplibrary/wcs?version=2.0.1&request=GetCoverage&service=WCS&CoverageID=emodnet_open_maplibrary__mediseh_cora&format=image%2Ftiff&subset=X%28-845389.1484423319%2C2027949.6934754928%29&subset=Y%283951488.8573080758%2C5753792.596194154%29

Notice that the crs and resolution parameters are no longer required. Also, the printed link includes the bbox values.

This downloads the data using the right bounds.

image

@alecsandrei alecsandrei changed the title Unexpected behaviour in the WCS bbox parameter Fix unexpected behaviour in the WCS bbox parameter Jul 29, 2025
@bart-v bart-v added the bug Something isn't working label Aug 4, 2025
@bart-v bart-v requested a review from tim-collart August 4, 2025 16:28
@tim-collart tim-collart assigned M-Mks and unassigned tim-collart Oct 14, 2025
@tim-collart
Copy link
Contributor

Thanks @alecsandrei for flagging. @M-Mks , can you look into this proposed fix and merge it in?
Cheers,
Tim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants