I am looking to crop an ECW image based on latitude and longitude. I have the following code to do that but it doesn't work.

<gdalwarp -t_srs EPSG:27700 -te 51.50386 51.50391 -0.4333941 -0.4333865 image.ecw imagecrop.tif>

I get the following error.

Warning 1: -ts values have minx >= maxx. This will result in a horizontally flip ped image. Warning 1: -ts values have miny >= maxy. This will result in a vertically flippe d image. Creating output file that is -1297P x -1297L. ERROR 1: Attempt to create -1297x-1297 dataset is illegal,sizes must be larger t han zero.

How can I fix this?


Read https://www.gdal.org/gdalwarp.html carefully

-te xmin ymin xmax ymax:

set georeferenced extents of output file to be created (in target SRS by default, or in the SRS specified with -te_srs)

What is wrong that you have given xmin=51.50386 and xmax=-0.4333941. This should work better

-te 51.50386 -0.4333941 51.50391 -0.4333865

However, if you are close to London you have the coordinates in wrong order. GDAL wants them always as longitude-latitude or easting-northing order so the parameter would come

-te -0.4333941 51.50386 -0.4333865 51.50391

But then you should re-read the manual https://www.gdal.org/gdalwarp.html "(in target SRS by default, or in the SRS specified with -te_srs)". Your target is EPSG:27700 so either you must give the extents according to that or if you want to select the area by lon-lat coordinates you must tell that by adding the -te_srs parameter

-te_srs srs_def:

(GDAL >= 2.0) Specifies the SRS in which to interpret the coordinates given with -te. The srs_def may be any of the usual GDAL/OGR forms, complete WKT, PROJ.4, EPSG:n or a file containing the WKT. This must not be confused with -t_srs which is the target SRS of the output dataset. -te_srs is a convenience e.g. when knowing the output coordinates in a geodetic long/lat SRS, but still wanting a result in a projected coordinate system.

Add -te_srs epsg:4326 and it should finally work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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