Calculating the edge pixels within a fishnet

I have a raster with three land cover classes.

For a fishnet grid cell, I want to calculate how many pixels (in %) are "edge pixels" (pixels from different land classes that touch). E.g., if the fishnet grid only contains 1 land cover class, the edge pixels % is 0%. If there two or more classes and many edge/boundary pixels, then the amount of edge pixels is above 0%.

How can I do this in ArcGIS Pro?

When I search online for a tool, it returns Edge detection for deep learning which is overkill.

• Are you using the Spatial Analyst extension? What have you tried besides a web search?
– PolyGeo
Aug 9, 2022 at 21:50

It depends on your understanding of edge pixel. Picture below shows output of focal statistics (2 by 2 cells, Range) and vector boundary line. Note that cells where FS raster equal 0 are transparent:

You might try statistics of 3 by 3:

More appealing to me is this:

• derive internal boundary lines (raster to polygon polygon to line, delete features with LEFT_FID=-1)
• buffer them by 0.5*cell_width
• divide buffer area by cell size

Here is another approach, use the tool Focal Stats and set the statistics type to VARIETY, this counts the number of pixel classes in the 3x3 neighbourhood.

So the input land cover raster could be something like this:

The result is this, anything greater than 1 must be a pixel adjacent to one or more other classes.

This approach not only identifies edge pixels but the value gives an indication to how many land class there are that are adjacent.

You could write a python script (e.g. using rasterio) that makes a new raster that classifies your land cover pixels as "edge" or not, and then it would only be a matter of counting "edge" pixels within a fishnet cell.

``````import rasterio
import numpy

landcover_dataset = rasterio.open(yourInputFilePath)

def IsEdge(band,r,c):
#Make a function that looks at pixels adjacent to the pixel at (r, c) in band and returns True if it's an edge pixel, else False

edge_band = numpy.empty((#same size as input))
for r, row in enumerate(landcover_band):
for c, column in enumerate(landcover_band):
if IsEdge(landcover_band, r, c):
edge_band[r][c] = 0
else:
edge_band[r][c] = 0

with rasterio.open(yourOutputFilepath, #same profile as input) as new_dataset:
new_dataset.write(new_band)
``````