Zonal statistics - percentiles (reprise)

2413
17
12-20-2018 06:35 PM
AndriesPotgieter
New Contributor II

Brached from https://community.esri.com/thread/95403 

Hi Xander Bakker 

I have also run your multiple raster percentile code. It runs upto loading the created polygon file:

execfile(r'F:\\data\\UAV\\Lodging_model\\GeoDatabase\\raster_percentile.py')
Processing Raster 'after_raster'
- Processing polygon: 0
- ExtractByPolygon...
- saved raster as ras0pol0
- fill dict with Value x Count
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "F:\\data\\UAV\\Lodging_model\\GeoDatabase\\raster_percentile.py", line 171, in <module>
main()
File "F:\\data\\UAV\\Lodging_model\\GeoDatabase\\raster_percentile.py", line 67, in main
dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(outname, flds_ras)}
RuntimeError: cannot open 'ras0pol0'

here is the first part of the code:

import arcpy
import os

def main():
# settings
ras_ws = r"F:/data/UAV/Lodging_model/GeoDatabase/raster/" # input raster workspace
fc = r"F:/data/UAV/Lodging_model/GeoDatabase/Hermitage_Lodging_Grid.shp" # input polygons
tbl = r"F:/data/UAV/Lodging_model/GeoDatabase/raster/Zonal_Perc_A" # output related table

lst_perc = [2, 5, 10, 90, 95, 98] # list of percentiles to be calculated
fld_prefix = "Perc_"
fld_poloid = "POL_OID"
fld_rasname = "RasterName"

---------------------

not sure why it cant load the ras0pol0 ?  It opens in acrgis no p[roblem from the geodatabase...

cheers

adnries

0 Kudos
17 Replies
XanderBakker
Esri Esteemed Contributor

This error seems to be related to the previous one. Please check that the rasters are integer. If they are not, they will not have a VAT which is required in the process. Did you pre-process the rasters the same way as you did with the first one?

0 Kudos
AndriesPotgieter
New Contributor II

Dear Xander Bakker

Thanks for the advice. I have changed the code accordingly and it is working now.

Will keep you posted when it has finished.

regards

ap

XanderBakker
Esri Esteemed Contributor

Hi Andries Potgieter ,

When you post code in GeoNet, please use these instructions: Posting code with Syntax Highlighting on GeoNet  to avoid loosing the indentation which makes the code unreadable.

As far as I understand from the error message there is no Value Attribute Table (VAT) for the raster "c:\PROGRA~2\arcgis\DESKTO~1.5\bin\pol83" and for some reason this file in not readable. Without the data it will be difficult to trace what is going wrong. 

AndriesPotgieter
New Contributor II

Hi Xander Bakker

is it possible to provide the code line for creating 1 single shapefile or table for the resulting zonal statistics here?

thanks

andires

0 Kudos
XanderBakker
Esri Esteemed Contributor

When you want to combine the percentile values for multiple rasters into the same polygon featureclass, the process should be changed drastically, since each raster should yield its own percentile fields each with its own name. At this point it is easier to run the code for each raster, but change the output fields before the next run. This can be done altering the variable fld_prefix for each run.

AndriesPotgieter
New Contributor II

Hi Xander Bakker‌,

I have run the Zonal percentile code you wrote on my data for 2 rasters and a snippet of the results is attached as an image here FYI.

thanks again for your help in this.

much appreciated.

Andries 

Table of Zonal percentiles for two Rasters

0 Kudos
XanderBakker
Esri Esteemed Contributor

Glad to hear that it is working! Can you mark the post that answered your question as the correct answer?

AndriesPotgieter
New Contributor II

Dear Xander Bakker

I am trying to run the python script outside ArcGIS. It takes forever to run in ArcGIS so wanted to speed things up too.

I am getting the following error when executing the first line from command line terminal in windows:

A:\Andries_MainData\data\UAV\boxsite_2016_17\Data>C:\Python27\ArcGIS10.5\python.exe raster_percentile.py
Traceback (most recent call last):
File "raster_percentile.py", line 182, in <module>
main()
File "raster_percentile.py", line 23, in main
arcpy.CreateTable_management(tbl_ws, tbl_name)
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 17411, in CreateTable
raise e
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Table Location: Dataset A:/data/UAV/boxsite_2016_17/Data/Geodatabase.gdb does not exist or is not supported
Failed to execute (CreateTable).

Can you please advise what I am doing wrong?

I will upload the script also

regards

andries

0 Kudos