I have a grid of cells with different values: enter image description here

I would like to analyze a group of 5 cells to check if they have the same values (group S1 and S3 display same value for all cells, not S2). This analysis would be for each cell from which the following cells (spatially very close) would form a group if they share the same value.

I thought about doing it first by using a square grid from which I compare (with Python) the value of a cell at (i,j) position, with those at (i,j+1), (i,j+2) ... on same line, and at (i+1,j), (i+1,j+1) ... (i+2,j), (i+2,j+1) ... and so on, for other lines. However, the grid is not a square.

I am looking for an alternative by using Python or other methods. Is it possible to do it using the cell coordinates instead (neighborhood analysis)?

(the end of the study would be to plot a point in the middle of the square group)

  • Hi, this code may help gist.github.com/geoSpacer/10203189 there shows how to take grid rasters to numpy, so you can work thru them in rows and columns. Make sure to convert to numpy two 'copies': one will be your source, and the other the output. The source will keep the original values, the output should hold just True or False in its cells. Use a defined function to validate the surrounding cells (from 1 to 5) are all the same. Be sure to include a 'safe cell' function, so your calculations don't go further tnan the raster boundaries. Good luck!
    – Delonix R.
    Jul 5 '16 at 19:27

Assuming your groups (S1,s2 & s3) exist as polygons you could build a very simple model to iterate through them running the zonal stats to table tool, merge the output and this will give you the information you need to make a comparison.

You don't say how many of these you need to process so this approach may not be appropriate if you have millions to do?

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.