Hi,
I'm using a raster dataset and I'm trying to determine a value for land use adjacency as used by Stathakis & Tsilimigkas (2014) (Measuring the compactness of European medium-sized cities by spatial metrics based on fused data sets. International Journal of Image and Data Fusion, 6(1), 42-64. doi:10.1080/19479832.2014.941018)
This involves counting the number of adjacent cells that have a value different to the centre cell. The attached image illustrates this concept.
It needs to return a new raster dataset where the value of each cell equals this count.
Can anyone suggest a method for doing this in ArcMap 10?
Thank you!
EDIT:
Dan, you're an absolute legend! Amazing dedication and perseverance to assist a total stranger on the other side of the world. Thank you so much for all your effort on this!
Just to update, the main issues experienced had much to do with a combination of differences in arcmap 10.3's and ArcGIS Pro's arcpy, and some major changes in numpy that is used by python 2.7 and python 3.6. Dan worked through them and ended up producing the Toolbox/Script I've attached to this edited post. As a final tip, make sure you run the script in a blank dataframe. You will need to manually set the projection of the final output.
That's right: for each cell, I need a count of the number of surrounding cells that have a different value to the core (excluding cells with no data).
For the sample you require... do you a raster that includes the input data and another that includes the solved data for that area? If so, what grid size do you require?
Mark, I don't need any specific cell size. The sample you sent is sufficient, I can make my array from it.
Tonight...
something to amuse you in the interim.... based on your example
input array
[[1 1 1 2 2]
[1 2 2 2 2]
[1 2 2 2 2]
[1 2 2 2 2]]
strided array...
[[[[1 1 1]
[1 2 2]
[1 2 2]]
[[1 1 2]
[2 2 2]
[2 2 2]]
[[1 2 2]
[2 2 2]
[2 2 2]]]
[[[1 2 2]
[1 2 2]
[1 2 2]]
[[2 2 2]
[2 2 2]
[2 2 2]]
[[2 2 2]
[2 2 2]
[2 2 2]]]]
sub array
[[1 1 1]
[1 2 2]
[1 2 2]] ... number different than 2 ... 5
sub array
[[1 1 2]
[2 2 2]
[2 2 2]] ... number different than 2 ... 2
sub array
[[1 2 2]
[2 2 2]
[2 2 2]] ... number different than 2 ... 1
sub array
[[1 2 2]
[1 2 2]
[1 2 2]] ... number different than 2 ... 3
sub array
[[2 2 2]
[2 2 2]
[2 2 2]] ... number different than 2 ... 0
sub array
[[2 2 2]
[2 2 2]
[2 2 2]] ... number different than 2 ... 0
Yep, that's exactly what I'm looking for.
I had to trim off a lot of nodata area to get to the crux of the data… a couple of visuals.
I trimmed, ran the 'algorithm', made a fishnet so you could see cell outlines, and zoomed into a random area for you to have a look at. I then converted the 'result' to a point file so that I could use labelling as well. So if the colors aren't great, you dan check a cell value against the number.
The first image is the original values.
The second is the number of cells around the original cell that are different.
Check the logic.
EDIT See images in a subsequent thread
Thank you very much for this Dan, very clearly explained!
Unless I'm missing something, I'm not sure if this is quite doing it though? Two issues I can see:
Mark
Mark... forget the other images.
Sorry for the delay (holidays.. sort of)
So, nulls have been removed as being a different value around the focal cell... wasn't sure about that one.
That affects the results.
A newly clipped sample and result... have a gander
Now the result... notice that most of the areas are classes as 0 difference which is to be expected, now that null values are removed from consideration.
That's the ticket, perfect!
Many thanks Dan! The question now of course is... how did you do it?
Just got back, so I am putting it into a useable script form in a toolbox, but I only use PRO, so you will be the tester of whether saving a toolbox to an ArcMap version actually works... so ArcMap 10.????? after the dot would help
Hi Dan,
I'm not in the office today so not certain... I think it is 10.3 but will need to confirm.
Many thanks again!