Select to view content in your preferred language

"Focal Statistics" - getting all original values in neighborhood per point as numpy array

510
2
08-16-2022 12:25 PM
MichaelArens
Emerging Contributor

Hello! I got a classified raster and for every point in that raster im trying to get all the classvalues of the points within a circular neighborhood. "Focal Statistics" seems to be efficient at getting these values and creating statistics out of them, I'm however only interested in getting the original values. Is there  a way to get these ? I already tried "extract circle", however iterating over every point in a raster, extracting the raster and than converting the raster into a numpy array each time takes too much time to be a viable option.

Additional Info:

Focal_Statistics:

https://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/how-focal-statistics-works.h....

I found that in the arcpy.sa.function.py file where focal statistics is defined, it basically only gives metadata to the generic apply() function, that uses a built-in "Focal" function.

 

 

result = arcpy.sa.Apply(in_raster, "Focal", args)

 

 

Args containing all the parameters like rasterm radius what kind of neighborhood should be used. I couldn't find any more information of the generic "Focal" function and all the links online seems to direct to "FocalStatistics". It seems the Focal function is defined somewhere that can't be accessed directly. Does anyone have more information on that ?

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

The focal function will only return a statistic for the desired neighbour, not all the data within.  Extract by circle would be the way to go , but would require scripting if you have many points.

What does your map look like?  If you have circular buffers around the points to represent "zones", perhaps the zonal tools might more to you useage.

Zonal Statistics (Spatial Analyst)—ArcGIS Pro | Documentation

Zonal histogram, statistics or statistics as table will allow for data summary on a zone (aka buffered point).


... sort of retired...
0 Kudos
MichaelArens
Emerging Contributor

Thank you for your reply. I did some programming in python where I used the cell size and the X/Y Min/Max Raster Information to iterate through all points in the raster and perform "ExtractByCircle" on them. This with the RasterToNumpyArray however takes ~2 Seconds per point, in a 15000x15000 Raster this would take about 14 years, so this isn't a viable option unfortunately. 

The Zonal tool might be helpful in a different part of my project, unfortunately  for this use case I need to get all the values of the points around a point irrespective of the zone they might be a part of.

0 Kudos