TransWikia.com

Checking for raster coverage within polygon feature class using ArcPy?

Geographic Information Systems Asked by Ian Yau on February 9, 2021

I’m writing a Python toolbox and would like to build in a check for raster data within the user-supplied area of interest. This piece of code works most of the time:

if (str(arcpy.GetRasterProperties_management(chsaoi, "ALLNODATA")) == "1"):
    arcpy.AddWarning("No raster coverage in input OID {}.".format(row[1]))

But when the polygon is very large, this check seems to fail. Even when the entire input feature class has raster coverage, the “ALLNODATA” check returns ‘0’.

Can someone help me come up with a better way to do this?

One Answer

So, you are checking if you have a full raster coverage within the ROI polygon, right?

I reckon your best bet is to use geometries:

img = arcpy.Raster(path_to_img)
raster_coverage = img.extent

if not raster_coverage.contains(ROI_polygon):
    arcpy.AddWarning("No raster coverage in input ROI")

You can perform other checks if you prefer, like ROI.within(raster_extent). you can find a full list here.

However this will not work for areas within the image that have nodata values. For that you may want to polygonize your raster and then perform this check. It may be slightly slower at the beginning, but it is still worth if you have a lot of ROIs to check. Should also be more reliable than playing with pixel values.

Answered by Alessio Arena on February 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP