2

I want to crop a large GeoTIFF on the edge of the bbox which is given in latitude and longitude:

bbox = (26.8040970,46.5625741,26.6225059,46.2075912)

When I use the following code:

from osgeo import gdal, osr

root = '/var/www/html/py/'

bbox = (26.8040970,46.5625741,26.6225059,46.2075912)
gdal.Translate(root+'cut_tiff/output_crop_raster.tif', root+'tiff/phh2o.tif', projWin = bbox)

I have the following error:

ERROR 1: Error: Computed -srcwin 2095 1815 -182 355 has negative width and/or height.

When displaying the information:

gdal.Info

Driver: GTiff/GeoTIFF
Files: /var/www/html/py/tiff/phh2o.tif
Size is 5032, 4997
Coordinate System is:
GEOGCS["WGS 84",
     DATE["WGS_1984",
         SPHEROID["WGS 84",6378137,298.257223563,
             AUTHORITY["EPSG","7030"]],
         AUTHORITY["EPSG","6326"]],
     GET["Greenwich",0],
     UNIT["degree",0.0174532925199433],
     AUTHORITY["EPSG","4326"]]
Origin = (24.708252026038561,48.378145004703761)
Pixel Size = (0.000999947922878,-0.001000009407526)
Metadata:
   AREA_OR_POINT=Area
   TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
   TIFFTAG_XRESOLUTION=72
   TIFFTAG_YRESOLUTION=72
Image Structure Metadata:
   COMPRESSION=DEFLATE
   INTERLEAVE=BAND
Corner Coordinates:
Upper Left ( 24.7082520, 48.3781450) ( 24d42'29.71"E, 48d22'41.32"N)
Lower Left ( 24.7082520, 43.3810980) ( 24d42'29.71"E, 43d22'51.95"N)
Upper Right ( 29.7399900, 48.3781450) ( 29d44'23.96"E, 48d22'41.32"N)
Lower Right ( 29.7399900, 43.3810980) ( 29d44'23.96"E, 43d22'51.95"N)
Center ( 27.2241210, 45.8796215) ( 27d13'26.84"E, 45d52'46.64"N)
Band 1 Block=256x256 Type=Int16, ColorInterp=Gray

How can I solve this error?

1 Answer 1

4

I think that the order for projwin wants to be: upper left x, upper left y, lower right x, lower right y; so you will want:

bbox = (26.6225059,46.5625741,26.8040970,46.2075912)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.