Opened 9 years ago

Closed 9 years ago

#5733 closed defect (invalid)

gdal_warp produce wrong (unequal) cell size

Reported by: miro Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: 1.11.1
Severity: normal Keywords:
Cc:

Description

When I clip raster to polygon shapefile (both in GDA94 Z56 - EPSG:28356) the result has unequal cell size like:

Example for big raster about 10000x10000 cells and 5x5m cell size:

Pixel Size = (4.999893471194129,-5.000074452387987)

Example with 75x75m pixels and significantly smaller clip areas - rectangles:

Pixel Size = (75.156717048047454,-75.009639323886461) Pixel Size = (75.096859834735284,-75.241627899123372)

It might seem like nothing but some tools needs exact square dimensions which makes in these cases clipped grids useless...

Change History (4)

comment:1 by Jukka Rahkonen, 9 years ago

It would be better to discuss about the problems in gdal-dev mailing list before creating tickets. Create a ticket if the conclusion from the discussion is that there is really a bug.

Gdalwarp as far as I know does not guarantee that it maintains the pixel size with the most simple command. However, it does have a -tr option http://www.gdal.org/gdalwarp.html. I suggest to have a try with it.

If the extents of the clipping polygon are not exactly (n * pixel size) it is impossible to keep both the exact clipping area and original pixel size. One or another must be adjusted and I suppose that in your case the fine tuning is made by slightly changing the pixel size.

in reply to:  1 comment:2 by miro, 9 years ago

Sorry, it is my first post here and I came from QGIS bug tracker where this way is I believe standard. Next time I will use mailing list first.

Anyway I believe when I am clipping grid it should always keep the same cell size by default - just reduce (or increase) the number of rows/columns based on if cells (or cell centres, not sure how warp solve this) are within clip area. I would have to test it a bit more but to me it looks like problem with precision than trying to fit cells to clipping area.

Replying to jratike80:

It would be better to discuss about the problems in gdal-dev mailing list before creating tickets. Create a ticket if the conclusion from the discussion is that there is really a bug.

Gdalwarp as far as I know does not guarantee that it maintains the pixel size with the most simple command. However, it does have a -tr option http://www.gdal.org/gdalwarp.html. I suggest to have a try with it.

If the extents of the clipping polygon are not exactly (n * pixel size) it is impossible to keep both the exact clipping area and original pixel size. One or another must be adjusted and I suppose that in your case the fine tuning is made by slightly changing the pixel size.

comment:3 by Jukka Rahkonen, 9 years ago

Well, on the other hand, if you give the area to clip as exact numbers as you do when you use gdalwarp with -te option, you would probably feel it is natural to get an exact clip. It is impossible to have defaults which can make everybody happy. Use -tr (possibly together with -tap) and you do not need to trust on defaults which are decided by someone else. You are the master and you'll have the full control.

You are right, it may also be a question about precision and it can be a bug. Make a test with some small image like 10 by 10 pixels with 50 m pixel size and see what happens if you clip the image from the middle of pixels.

comment:4 by Even Rouault, 9 years ago

Resolution: invalid
Status: newclosed

-crop_to_cutline is a shortcut for getting the extent of the cropping geometry and use it with -te option. As the raster size are integer, it is impossible to have strictly equals pixel width and height. One could still try to adjust a bit the extent to have square pixels, but looks like over complication. As said by Jukka, using -tr should do it.

Note: See TracTickets for help on using tickets.