0

I'm trying to get the zonal statistics output (mean), do some operations and add to my main archive the output value. I wrote this code, but it's not running, the error message is:

Traceback (most recent call last):
  File "Z:\04 - Temp\Charles\NDVI_tempo\NDVI_py3.tbx#Script3_NDVIpy3.py", line 21, in <module>
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Functions.py", line 6328, in ZonalStatistics
    ignore_nodata)
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Utils.py", line 53, in swapper
    result = wrapper(*args, **kwargs)
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Functions.py", line 6321, in Wrapper
    ignore_nodata)
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool
Failed to execute (Script3).

import arcpy
import os
import datetime
from arcpy import env
from arcpy.sa import *

#Declarar as variáveis

arcpy.env.workspace = 'Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL_PL'
fcs = arcpy.ListFeatureClasses()
rasters = arcpy.ListRasters("test*", "All")
fc = 'Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL_PL\\MA02ASEZ3S'
arcpy.CheckOutExtension("Spatial")

for tiff in rasters:
#Zonal statistics
    Zonaltif = ZonalStatistics(fc, ["ID_TALHAO"], tiff, "MEAN")
    Zonaltif.save('Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL_PL\\teste')
    Zonalper = Times (Zonaltif, 100)
    Zonalint = Int (Zonalper)
    RasterToPolygon_conversion (Zonalint, Zonalpoly, "SIMPLIFY", "VALUE")
    Intersect_analysis ([Zonalpoly, fc], 'Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL_PL\\teste\\intertif', "ALL", "", "")

What am I doing wrong?

  • A few suggestions that may help. You have spaces in your directory paths which can still cause problems in some functions. In your ZonalStatistics function the syntax for the zone field should not contain [ ]. I don't see where you have defined Zonalpoly that is used in the RasterToPolygon_conversion function. – Jacob F Sep 29 '17 at 15:28
  • Now the error is: ERROR 000865: Input raster or feature zone data: Z:\04 - Temp\Charles\NDVI_tempo\NAL_PL\MA02ASEZ3S does not exist. ERROR 001000: Zone field: Field ID_TALHAO does not exist Failed to execute (ZonalStatistics). Failed to execute (Script3). It's like it don't recognize the feature – Charlera Sep 29 '17 at 17:19
  • You also need to add the .shp extension to the feature MA02ASEZ3S. – Jacob F Oct 2 '17 at 14:48
0

Deleting spaces in output file directory worked in my case. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.