1

Consider the following raster with two categories and a DEM (numeric raster), I'd like to compute the elevation difference along the border (closest pixel) of those two categories, it doesn't matter on which side of the border the result is stored. I've checked r.neighbors but it's not category-aware. It's of little matter what it does in corners, where there are two closest pixels.

I'd like to keep it in GRASS (maybe python) because I'm making lots of spatial stats through rgrass7. enter image description here

2

You could make a new raster that is only the red category using r.mapcalc. Grow it by one cell using r.grow. Fill the growth region using one of several algorithm (r.mfilter?). There is now a one cell border overlap between the new raster and the pink cells in the original. Subtract the two using r.mapcalc.

I think the above steps should get you what you want. There may be more efficient ways, or even a single command that does what you want. I'd ask on the GRASS list which seems to have more eyeballs than the GRASS topic on this site.

  • Only now I could work on your answer, with little modifications, I got what I was looking for; instead of r.grow I decided to use r.buffer which retains only the added cell, then, instead of r.mfilter I found r.neighbors would get me those buffered cells filled with those neighboring them, skipping the nulls – Elio Diaz Feb 14 '18 at 19:02
2

To get the inner and outer border of a raster polygon map, you can use r.neighbors along with the range method:

# North Carolina sample dataset
g.region raster=geology_30m -p
r.neighbors input=geology_30m output=geology_30m_boundary method=range

This you could then use as a mask and continue with the further statistical analysis.

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.