# Grid cells group analysis?

I have a grid of cells with different values:

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! Jul 5 '16 at 19:27