0

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Dec 17, 2018 at 0:38
1
  • 1
    Do you have a spatial analyst license? You can perform an IsNull using your polygon as a mask (arcpy.env.Mask resources.arcgis.com/en/help/main/10.1/index.html#//…), calculate the statistics and if your minimum and maximum of the IsNull raster obtained by GetRasterProperties both equal 1 then you have all null. but first repair geometries on your input polygons, if your input polygons have self intersections or incorrect ring orientations then your overlay wont work properly. Commented Dec 17, 2018 at 0:53

1 Answer 1

1

Assuming that you are checking if you have a full raster coverage within the ROI polygon, 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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Dec 17, 2018 at 5:02
2
  • I only need to know if there is any rater coverage. Full coverage is not necessary. Commented Dec 17, 2018 at 5:54
  • Then overlaps is your friend if you use this approach. If you scroll down in that page you will see all the methods to define relationship between features, and you are interested in the polygon to polygon case Commented Dec 18, 2018 at 2:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.