Branched from: Re: Script Zonal statistics percentiles, using Float rasters
Hello,
I'm trying to do the exact same thing for 25, 50, and 75 percentiles. I have an integer DEM and a set of continuous polygons. Here is the error I'm getting:
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.3\Lib\percentiles.py", line 100, in <module>
pixval = GetPixelValueForPercentile(dct_per, perc_dec)
File "C:\Python27\ArcGIS10.3\Lib\percentiles.py", line 10, in GetPixelValueForPercentile
return pix_val
UnboundLocalError: local variable 'pix_val' referenced before assignment
I am not a python programmer, any insight is most appreciated. I've attached the script with the changes I made, which were only the list of percentiles (line 25) and the paths to my datasets. Ideally, if it's possible, I would like to run this on a float raster instead of an integer raster.
Much thanks,
Brian
Solved! Go to Solution.
As Dan Patterson states, most likely you have a polygon with a hole in it. The Nonetype point indicates the start of an inner ring. To avoid this you could use the code posted here:
https://community.esri.com/thread/95403#555075
Instead of using ExtractByPolygon it uses ExtractByMask.
You're not using the latest script posted in this thread. Line 4 should read.
pix_val = sorted(dctper.keys())[0]
... but is missing in your script.
To run this on float raster data, would require a different approach. Only integer rasters have an attribute table and this is used in the script to determine the percentiles. However, one could implement a procedure that takes an float raster as input, converts it to integer (applying a multiplication factor to reduce the loss of precision) and apply the factor in the results too.
What is the data range of the float raster you have?
The data range of the float raster is -26.9159 to 334.042.
What precision are you trying to obtain. Would in this case a multiplier by 10 be sufficient, the range would be changed at the end of the run to -26.9 to 334.0. You could test this manually by using the Raster Calculator (in Spatial Analyst Tools\Map Algebra) and use a formula like:
The script ran a lot longer now that I incorporated your prior suggestions. Now I am getting this at line 60.
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.3\Scripts\percentiles_edit.py", line 60, in <module>
x, y = pnt.X, pnt.Y
AttributeError: 'NoneType' object has no attribute 'X'
Failed to execute (Percentiles).
Failed at Thu Mar 03 13:35:22 2016 (Elapsed Time: 7 minutes 36 seconds)
Any thoughts?
Much thanks,
Brian
Hello Xander,
I like the idea of using a multiplier and converting to an integer raster as a work around, that will work fine for the float issue. I am still getting the error on line 60:
x, y = pnt.X, pnt.Y
AttributeError: 'NoneType' object has no attribute 'X'
This is happening after it has already processed a handful of polygons. I ran the check geometry and repair geometry tools to check for null geometries and the feature class seems fine. Any ideas of why it may be erring out?
Thanks,
Brian
do you have polygons with holes? a polygon with a hole will have a null separater between the inner and outer parts. This case will complicate the process... then try a multipart polygon with multiple holes and you are pushing towards a full implementation of geometry checks and processing.
As Dan Patterson states, most likely you have a polygon with a hole in it. The Nonetype point indicates the start of an inner ring. To avoid this you could use the code posted here:
https://community.esri.com/thread/95403#555075
Instead of using ExtractByPolygon it uses ExtractByMask.
Thank you guys both for your help and suggestions. I was able to get it to run overnight and used a 100x multiplier. This is great.
Sincerely,
Brian
Glad to hear that it worked. Did you use the code with ExtractByMask or ExtractByPolygon?