I'm trying to calculate the number of certain raster cells within the individual buffers identified by the FID and I'm not sure what else I need to change in this code to make it run:
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
import os
import numpy as np
# overwrite existing datasets
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")
# Define workspace
arcpy.env.workspace = arcpy.GetParameterAsText(0)
in_features = arcpy.GetParameterAsText(1)
arcpy.MakeFeatureLayer_management(in_features, "lyr")
FIDS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,33, 34, 35, 36, 37, 38, 39, 40]
InputRaster = arcpy.GetParameterAsText(2)
arcpy.MakeRasterLayer_management(InputRaster, "rdlayer")
for item in FIDS:
fieldName = "FID"
FID_item = str(item)
EXP = '"FID" = ' + str(item)
print EXP
arcpy.AddMessage("Selecting from nest buffers where " + EXP)
arcpy.SelectLayerByAttribute_management("shp", "NEW_SELECTION", EXP)
result = int(arcpy.GetCount_management("lyr").getOutput(0))
print result
arcpy.AddMessage(str(result) + " nest buffers selected")
OutputTable = "suit_" + str(item)
ZonalStatisticsAsTable("shp","FID","rdlayer",OutputTable,"DATA","SUM")
This is what I get when I run it:
Traceback (most recent call last):
File "C:/Users/csetash/PycharmProjects/Covariates/SuitHab.py", line 22, in <module>
arcpy.MakeFeatureLayer_management(in_features, "lyr")
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 6043, in MakeFeatureLayer
raise e
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000735: Input Features: Value is required
Failed to execute (MakeFeatureLayer).
Process finished with exit code 1