gdal icon indicating copy to clipboard operation
gdal copied to clipboard

gdal_translate fails to clip raster with geolocation array

Open uclaros opened this issue 3 weeks ago • 1 comments

What is the bug?

When used on HDF-EOS5 raster data with geolocation array, gdal_translate cannot be used with -projwin coordinates in the geolocation crs.

Steps to reproduce the issue

  1. download sample hdf file from stac server: https://www.planet.com/data/stac/browser/tanager-core-imagery/agriculture/20250224_145149_32_4001/20250224_145149_32_4001.json?.asset=asset-basic_radiance_hdf5
  2. try to clip with gdal_translate
$ gdal_translate -projwin -63.7 -63.6 -22.2 -22.1 "HDF5:"""/home/uclaros/Downloads/20250224_145149_32_4001_basic_radiance.h5"""://HDFEOS/SWATHS/HYP/Data_Fields/sensor_to_ground_path_length" /tmp/gdal_translate.tif
Input file size is 607, 501
Warning 1: Computed -srcwin -64 -64 42 42 falls completely outside source raster extent. Pixels outside the source raster extent will be set to the NoData value (if defined), or zero.
0...10...20...30...40...50...60...70...80...90...100 - done.
  1. Explicitly setting -projwin_srs reports a warning
Warning 0: -projwin_srs ignored since the dataset has no projection.

Versions and provenance

On Debian testing, gdal packaged by the distro

$ gdalinfo --version
GDAL 3.12.0 "Chicoutimi", released 2025/11/03

Additional context

Using gdalwarp with -te instead of gdal_translate works as expected

$ gdalwarp -te -63.7 -22.2 -63.6 -22.1 "HDF5:"""/home/uclaros/Downloads/20250224_145149_32_4001_basic_radiance.h5"""://HDFEOS/SWATHS/HYP/Data_Fields/sensor_to_ground_path_length" /tmp/gdalwarp.tif
Creating output file that is 334P x 334L.
Processing sensor_to_ground_path_length [1/1] : 0...10...20...30...40...50...60...70...80...90...100 - done.

The geolocation srs in the metadata is wgs84:

$ gdalinfo "HDF5:"""/home/uclaros/Downloads/20250224_145149_32_4001_basic_radiance.h5"""://HDFEOS/SWATHS/HYP/Data_Fields/sensor_to_ground_path_length"
Driver: HDF5Image/HDF5 Dataset
Files: /home/uclaros/Downloads/20250224_145149_32_4001_basic_radiance.h5
Size is 607, 501
Metadata:
  HDFEOS_INFORMATION_HDFEOSVersion=HDFEOS_5.1.15
  HDFEOS_SWATHS_HYP_created_at=2025-07-12T14:33:52.984179+00:00
  HDFEOS_SWATHS_HYP_Geolocation_Fields_Planet_Ortho_Framing={"cols": 775, "epsg_code": 32720, "geotransform": [419490.0, 30.0, 0.0, 7556490.0, 0.0, -30.0], "rows": 663}
  HDFEOS_SWATHS_HYP_strip_id=20250224_145141_00_4001_strip
Image Structure Metadata:
  COMPRESSION=DEFLATE
Geolocation:
  GEOREFERENCING_CONVENTION=PIXEL_CENTER
  LINE_OFFSET=0
  LINE_STEP=1
  PIXEL_OFFSET=0
  PIXEL_STEP=1
  SRS=GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
  X_BAND=1
  X_DATASET=HDF5:"/home/uclaros/Downloads/20250224_145149_32_4001_basic_radiance.h5"://HDFEOS/SWATHS/HYP/Geolocation_Fields/Longitude
  Y_BAND=1
  Y_DATASET=HDF5:"/home/uclaros/Downloads/20250224_145149_32_4001_basic_radiance.h5"://HDFEOS/SWATHS/HYP/Geolocation_Fields/Latitude
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  501.0)
Upper Right (  607.0,    0.0)
Lower Right (  607.0,  501.0)
Center      (  303.5,  250.5)
Band 1 Block=76x63 Type=Float32, ColorInterp=Undefined
  Metadata:
    Unit=Meters

uclaros avatar Dec 02 '25 17:12 uclaros

When used on HDF-EOS5 raster data with geolocation array, gdal_translate cannot be used with -projwin coordinates in the geolocation crs.

This is expected. Using -projwin requires the dataset to have a geotransform/affine matrix. A geolocation array is not sufficient for that. You'd rather want to use gdalwarp -te that will use the geolocation array.

rouault avatar Dec 02 '25 17:12 rouault

closing as works as intended

rouault avatar Dec 15 '25 23:12 rouault