dav22b

Python Script: loop through selected features and and copy to geodatabase

Discussion created by dav22b on Apr 13, 2014
Latest reply on Apr 22, 2014 by dav22b
I am working with surface types that I derived from LIDAR data. These surface types are in one feature class (polygon) -
associated with the feature class is a column called "grid_code"; the grid_code column has values from 0 to 145. These are elevation values and will be selected out to classify three surface types (ground surface, shrubs and trees).

I want to write a script that selects each surface type and creates a feature class for each of them. My output would have three
feature classes: ground, shrub and tree.

Here is the code I am working with but I am getting errors:

Thanks!



import arcpy, os

aWS = r"C:\Thesis_Research\GIS\Prov_classification.gdb"

arcpy.env.workspace = aWS

arcpy.env.overwriteOutput = True

try:
  
    # Create query statements for each land cover type
    LIDAR_tree = '"grid_code" > \'3\''
    LIDAR_shrub = '"grid_code" = \'2\' OR "grid_code" = \'3\''
    LIDAR_ground = '"grid_code" <= \'1\''

    aListLIDAR = [LIDAR_tree, LIDAR_shrub, LIDAR_ground]
   
    for item in aListLIDAR:
       
        arcpy.MakeFeatureLayer_management("P303_LIDAR_Poly", P303_layerL)

        arcpy.SelectLayerByAttribute_management(P303_layerL, "NEW_SELECTION", aListLIDAR)
       
        arcpy.CopyFeatures_management(P303_layerL, "P303_" + str(item))

    del aListLIDAR
    del item
    del P303_layerL

   
except:
   
    # Code to run when an error occured
    print "An ERROR Occured!"
    print "\n" + arcpy.GetMessages()

else:
   
    # Message when there was no error
    print "\nNo Error occurred"
   
# Script end message
print "\nEnd of the script!"

Outcomes