0

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
1
  • In your script tool interface, what data type have you chosen for the in_features parameter?
    – GISGe
    Commented Nov 9, 2015 at 7:37

1 Answer 1

1

Input in Select Layer by Attribute must be a feature layer or a table view. The input cannot be a feature class or table. Make Feature Layer

Your input is "shp" which may be a feature class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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