QGIS Rasterization – How to Align Rasterized Point Vector to Existing Raster in QGIS

qgisrasterrasterization

I have a point shapefile, with no associated .prj file, that I have to rasterize. Each point should be transformed into a pixel of 30×30 size aligned to the pixels of a Landsat image (the point file contains accuracy assessment points for a land cover semi-automated classification).

I don't know the original coordinate system but I'm reasonably sure of which one it is. The steps I took are:
1) tried saving the shp with different coordinate system, compared the results, and decided which might be the most likely one (because in the other cases the land cover classes assigned to the points would be mostly wrong).
2) saved the shp in that coordinate system, then converted into EPSG:32632 (same as the landsat images)
3) used gdal rasterize (from Qgis' Processing Toolbox) to rasterize the points. I set "output resolution in map units per pixel" as 30 x 30 m.

4) what I obtained are misaligned pixels like this:
raster misalignment

The green pixel is the result of rasterization, the yellow point is the original point.

I tried redoing the whole procedure saving the original shp in different coordinate systems, but no luck.
I also tried the plugin rasmover to manually align the raster, but then it occurred to me that I don't know for sure how the raster should be aligned (i mean, I guess it should be aligned to the pixel it overlaps the most, but how can I be certain?). Moreover , if I use rasmover, many of the original points end up falling outside of the pixel that is supposed to contain them, because they are located near the edge.

So the questions are, what might be causing this problem? Is it related to the original georeferencing of the two files? And is there a way to fix this problem by using QGis, or by setting gdal_rasterize so that it will align the raster correctly? I've seen answers to similar problems related to ArcGis and GRASS but not specifically QGIS.

Best Answer

In the Metadata Layer Properties of your raster base, copy the equivalent of this information:

Layer Extent (layer original source projection)
354971.3488602247089148,4414903.3223166307434440 : 479272.4038835020037368,4473428.4023900907486677

and put in this format:

-te 354971.3488602247089148 4414903.3223166307434440 479272.4038835020037368 4473428.4023900907486677

In your Rasterize Dialog, select your "Attribute field" and "output file" and afterward, click in the icon pencil to edit the gdal_rasterize command. See my example in the next image:

enter image description here

Click in OK to get the rasterized points perfectly aligned with the base raster (see next image):

enter image description here

Related Question