[GIS] Error: Attempt to create 2×0 dataset is illegal,sizes must be larger than zero

gdalgdalwarpgeotiff-tiff

I have the following input file

gdalinfo SAVI_v2_T_0006_0006_savi.tif
Driver: GTiff/GeoTIFF
Files: SAVI_v2_T_0006_0006_savi.tif
Size is 4308, 208
Coordinate System is:
PROJCS["WGS 84 / UTM zone 32N",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",9],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AUTHORITY["EPSG","32632"]]
Origin = (742430.000000000000000,5870860.000000000000000)
Pixel Size = (15.000000000000000,-15.000000000000000)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (  742430.000, 5870860.000) ( 12d36'26.78"E, 52d55'57.16"N)
Lower Left  (  742430.000, 5867740.000) ( 12d36'18.40"E, 52d54'16.39"N)
Upper Right (  807050.000, 5870860.000) ( 13d33'57.69"E, 52d53'58.27"N)
Lower Right (  807050.000, 5867740.000) ( 13d33'47.10"E, 52d52'17.62"N)
Center      (  774740.000, 5869300.000) ( 13d 5' 8.33"E, 52d54'10.83"N)
Band 1 Block=4308x1 Type=Float32, ColorInterp=Gray
  NoData Value=1.175494351e-38

And I would like to decrease its size by 1024x. I specify the target resolution for gdalwarp to be 30720 = 15 (pixel size in meters) * 1024 as follows:

gdalwarp -tr 30720 30720 SAVI_v2_T_0006_0006_savi.tif out.tif

and get

ERROR 1: Attempt to create 2x0 dataset is illegal,sizes must be larger than zero.

I suppose that formally the above command is correct but

  • why those 208 pixels are squashed into 0 pixels instead of 1 pixel?
  • how to deal with this situation?
  • is there any other reliable way to reduce image size by an arbitrary scale factor?

Best Answer

I would use the -outsize option of gdal_translate http://www.gdal.org/gdal_translate.html.

-outsize xsize[%]|0 ysize[%]|0:

Set the size of the output file. Outsize is in pixels and lines unless '%' is attached in which case it is as a fraction of the input image size. Starting with GDAL 2.0, if one of the 2 values is set to 0, its value will be determined from the other one, while maintaining the aspect ratio of the source dataset.

gdal_translate -outsize 0.09765625% 0 SAVI_v2_T_0006_0006_savi.tif out.tif

Without trying I can't say if gdal_translate is willing to push your 208 pixels into 1 pixel if they actually can fill only 0.2 pixels. At least I would not call it as a bug if it emits a reasonable error message.

Related Question