Please help me

427
4
05-13-2014 01:22 AM
AbdelrazekElnashar
New Contributor II
Please help me, when trying to run this code as a tool

# -*- coding: utf-8 -*-
import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("spatial")
QC = arcpy.GetParameterAsText(0)
NDVI = arcpy.GetParameterAsText(1)
GoodNDVI = arcpy.GetParameterAsText(2)
GoodNDVI = (QC==0)*(NDVI>2000)*NDVI
GoodNDVI.save(GoodNDVI + ".tif")

This�??mmessage�??aappears

Traceback (most recent call last):
  File "E:\ArcPy_Toolbox\MODIS\Scripts\GoodNDVI.py", line 12, in <module>
    GoodNDVI.save(GoodNDVI + ".tif")
AttributeError: 'unicode' object has no attribute 'save'
Failed to execute (GoodNDVI).
0 Kudos
4 Replies
JasonScheirer
Regular Contributor II
You need to convert the strings you get in GetParameterAsText into Raster objects.

# -*- coding: utf-8 -*-
import arcpy

from arcpy.sa import *
arcpy.CheckOutExtension("spatial")

QC = arcpy.Raster(arcpy.GetParameterAsText(0))
NDVI = arcpy.Raster(arcpy.GetParameterAsText(1))
GoodNDVI = arcpy.GetParameterAsText(2)

GoodNDVI_raster = (QC==0)*(NDVI>2000)*NDVI
GoodNDVI_raster.save(GoodNDVI + ".tif")
0 Kudos
AbdelrazekElnashar
New Contributor II
You need to convert the strings you get in GetParameterAsText into Raster objects.

# -*- coding: utf-8 -*-
import arcpy

from arcpy.sa import *
arcpy.CheckOutExtension("spatial")

QC = arcpy.Raster(arcpy.GetParameterAsText(0))
NDVI = arcpy.Raster(arcpy.GetParameterAsText(1))
GoodNDVI = arcpy.GetParameterAsText(2)

GoodNDVI_raster = (QC==0)*(NDVI>2000)*NDVI
GoodNDVI_raster.save(GoodNDVI + ".tif")


Thank �??you, Excellent
0 Kudos
AbdelrazekElnashar
New Contributor II
when run this script as a tool:-

# -*- coding: utf-8 -*-
import arcpy
import os
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("spatial")
InputPath = arcpy.GetParameterAsText(0)
OutputPath = arcpy.GetParameterAsText(1)
OutputFolderName = arcpy.GetParameterAsText(2)
FeatureZone = arcpy.GetParameterAsText(3)
ZoneField = arcpy.GetParameterAsText(4)
arcpy.CreateFolder_management(OutputPath, OutputFolderName)
arcpy.env.workspace = InputPath
listDatasets = arcpy.ListDatasets()
for Datasets in listDatasets:
    Set_Null = Datasets
    Zonal_Statistices = OutputPath + "\\" + OutputFolderName + "\\" + Set_Null + ".dbf"
    arcpy.gp.ZonalStatisticsAsTable_sa(FeatureZone, ZoneField, Set_Null, Zonal_Statistices, "True", "ALL")

This message appears:-

Traceback (most recent call last):
  File "E:\ArcPy_Toolbox\MODIS\Scripts\ZonalStatisticsAsTable.py", line 24, in <module>
    arcpy.gp.ZonalStatisticsAsTable_sa(FeatureZone, ZoneField, Set_Null, Zonal_Statistices, "True", "ALL")
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: ERROR 999999: Error executing function.
Create output table failed
Failed to execute (ZonalStatisticsAsTable)

Actually�?? I want the name of the table (.dbf) is the same name of input raster in the loop
0 Kudos
AbdelrazekElnashar
New Contributor II
when run this script as a tool:-

# -*- coding: utf-8 -*-
import arcpy
import os
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("spatial")
InputPath = arcpy.GetParameterAsText(0)
OutputPath = arcpy.GetParameterAsText(1)
OutputFolderName = arcpy.GetParameterAsText(2)
FeatureZone = arcpy.GetParameterAsText(3)
ZoneField = arcpy.GetParameterAsText(4)
arcpy.CreateFolder_management(OutputPath, OutputFolderName)
arcpy.env.workspace = InputPath
listDatasets = arcpy.ListDatasets()
for Datasets in listDatasets:
Set_Null = Datasets
Zonal_Statistices = OutputPath + "\\" + OutputFolderName + "\\" + Set_Null + ".dbf"
arcpy.gp.ZonalStatisticsAsTable_sa(FeatureZone, ZoneField, Set_Null, Zonal_Statistices, "True", "ALL")

This message appears:-

Traceback (most recent call last):
File "E:\ArcPy_Toolbox\MODIS\Scripts\ZonalStatisticsAsTable.py", line 24, in <module>
arcpy.gp.ZonalStatisticsAsTable_sa(FeatureZone, ZoneField, Set_Null, Zonal_Statistices, "True", "ALL")
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: ERROR 999999: Error executing function.
Create output table failed
Failed to execute (ZonalStatisticsAsTable)

Actually�?? I want the name of the table (.dbf) is the same name of input raster in the loop
0 Kudos