0

Background:

I have two .tif files

  • band_06 (20m resolution, i.e pixel size 20,20)
  • lulc ("10"m resolution, pixel size 9.994 9.992)

and a .shp file

  • square

All files have the same CRS (EPSG:32632 - WGS 84 / UTM zone 32N).

Goal:

Both files should be transformed to a type that can be exported as a .csv file.

Problem: The cells of the rasters do not lineup as they should, in addition to a mismatch of total cells present in the attribute table.

Workflow:

band_06:

  • Import band_06
  • Resample to 10m
  • Clip raster by mask layer (square.shp)
  • Raster pixels to polygons

lulc:

  • Import lulc
  • Warp (reproject) to 10m
  • Clip raster by mask layer (square.shp)
  • Raster pixels to polygons

My suspicion is that warping lulc is causing the problem here, however I am not sure how to otherwise line the two files up such that the pixel cells are perfectly on top of one another.

How can I achieve the manipulation of the the imperfect lulc (with 9.994, 9.992 pixel size) to match the resampled band_06 (10, 10 pixel size) while also making sure that the end results after conversion from raster pixels to polygons is going to yield perfectly overlapping grid cells?

Image of problem:

The purple-gray overlay is the band_06 layer with increased transparency, with the underlying beige layer is representative of the lulc layer.

enter image description here

1
  • You probably don't really want your raster data as a CSV
    – Ian Turton
    Commented May 20 at 16:11

1 Answer 1

2

I think that the easiest method for making the pixels overlap is to warp both images to the same resolution by using the "target aligned pixels" option.

https://gdal.org/programs/gdalwarp.html#cmdoption-gdalwarp-tap

-tap

(target aligned pixels) align the coordinates of the extent of the output file to the values of the -tr, such that the aligned extent includes the minimum extent (edges lines/columns that are detected as blank, before actual warping, will be removed starting with GDAL 3.8). Alignment means that xmin / resx, ymin / resy, xmax / resx and ymax / resy are integer values.

Warping both images into same target extents https://gdal.org/programs/gdalwarp.html#cmdoption-gdalwarp-te and target resolution https://gdal.org/programs/gdalwarp.html#cmdoption-gdalwarp-tr is another alternative. If the images must have also the same number of rows and columns in addition to aligned pixels, use this option.

In QGIS "Warp (Reproject)" dialogue the -te and -tr options can be set with their own boxes. -tap is set from the "Additional command line parameters (optional)" box.

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.