3

I am working on a Landsat analysis script using GRASS GIS.

For that, I need to focus on a certain area based on raster "landscape" using r. mask raster="landscape" cat=$foo and then run r.reclass on raster "ndvi". I have realized that the two rasters are not perfectly aligned, as this close up image shows. pixels not alligned

I thought that GRASS would take care of this during import!

Can someone tell me how to correct this, and how I can prevent this from occurring?

3

I'll try to answer even though this was a few years ago.

I suspect that the two rasters are misaligned because the GRASS region was slightly different when you imported the NDVI and LANDSCAPE rasters. I've run into the same issue with many of my rasters, especially when I've imported them during different sessions.

Corrrecting Misalignment

First set and save a permanent region with g.region -s res=30 raster=yourraster save=file\name. You can set the region however like, whether that is with bounds, vector/raster maps, specifying 2D resolution, etc.

This image shows the landclass raster map to which I set the region and the centroids of the cells:

enter image description here

Here is another landclass raster that was imported while the region was set slightly differently. You can probably see how the cell centroids of the first image don't line up.

enter image description here

Then resample all of your rasters with r.resample. I believe this uses a nearest neighbor approximation. For my integer rasters, all of the stats and remain the same between the misaligned and aligned raster. It should do the same for floating point rasters. If there is a concern, maybe multiply the floating point to an integer with r.mapcalc prior to resampling.

Now the resampled landclass raster lines up with the cell centroids from the original raster map.

enter image description here

Prevention

Just make sure to remember what region setting you are using. If possible, save a default region in PERMANENT or save the region to a file.

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.