Hi, I am a GIS student, just starting out with python, and I am working on a project in which I want to create a custom script tool to clip a list of feature classes in a municipality to a single clip feature representing flood extent (FloodLevel). Can I create a list of the feature classes and then loop through the list to accomplish this? Here is what I am trying, though I cannot get the script to work at this point. I get an error that says: 'list' object is not callable. And I am not sure how to properly provide the output name for multiple features at once.
# Clip town features to a flood level polygon # Define input parameter for floodLevel polygon # Define infrastructure variables FloodLevel = arcpy.GetParameterAsText(0) FC1 = "Town_Boundary" FC2 = "Parcels_2010" FC3 = "Buildings_2009" FC4 = "Trails" FC5 = "Banff_Roads" FC6 = "Water_Main" FC7 = "Storm_Main" FC8 = "Hydrant" # Create list of feature classes and loop through the feature classes Features = [FC1, FC2, FC3, FC4, FC5, FC6, FC7, FC8] # Clip features in list to the FloodLevel polygon feature for items in Features(): arcpy.Clip_analysis(Features, FloodLevel, "Features_clip")
Any suggestions on how I could solve this scenario would be helpful!
Thanks,
Myla-Rae
(Curtis Price formatted code block 4/29/2015)
for item in Features: arcpy.Clip_analysis(item, FloodLevel, "Features_clip")
arcpy.env.workspace = r'G:\Some\Path\file.gdb' for item in Features: arcpy.Clip_analysis(item, FloodLevel, "Features_clip")
arcpy.env.workspace = r'G:\Some\Path\file.gdb' for item in Features: arcpy.Clip_analysis(item, FloodLevel, "Features_clip")
import arcgisscripting
import arcpy
gp = arcgisscripting.create(9.3)
gp.overwriteOutput = 1
# input hard-coded but you can make it a script tool parameter to make it an interactive input.
in_fc = r"X:\mohammadi\finalmunichGIS\munich.gdb\fc_parent1_" # this polygon feature class has several polygons.
fc_parent1_=[fc_parent1_1, fc_parent1_2, fc_parent1_3, fc_parent1_4, fc_parent1_5, fc_parent1_6, fc_parent1_7, fc_parent1_8
,fc_parent1_9,fc_parent1_10, fc_parent1_11, fc_parent1_12, fc_parent1_13, fc_parent1_14, fc_parent1_15, fc_parent1_16
, fc_parent1_17, fc_parent1_18, fc_parent1_19, fc_parent1_20]
rows = gp.SearchCursor(in_fc)
row = rows.Next()
while row:
feat = row.shape
ext = feat.extent
orig = str(ext.xmin) + " " + str(ext.ymin)
yaxis = str(ext.xmin) + " " + str(ext.ymin + 100.00)
opp_corner = str(ext.xmax) + " " + str(ext.ymax)
print orig, yaxis, opp_corner
out_fc = r"X:\mohammadi\finalmunichGIS\munich.gdb\clip" # + str(row.OBJECTID)
result = arcpy.clip_management("X:\mohammadi\finalmunichGIS\Testdaten-original data\munich_subset.tif", "650923.51 5297968.73 743103.51 5375868.73" ,
"X:\mohammadi\finalmunichGIS\munich.gdb\clip","#", "#", "NONE")
print(gp.GetMessages())
row = rows.Next()
del row, rows
# only import arcpy - don't use arcgisscripting/gp at 10.x
import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True ## 1
# in_fc is your polygon feature class
in_fc = r"X:\mohammadi\finalmunichGIS\clip0ffishnet9000\shapefilesoffc\fc_parent1"
# in_tif is your input
in_raster = "X:\mohammadi\finalmunichGIS\Testdaten-original data\munich_subset.tif"
# output location
outGDB = r"X:\mohammadi\finalmunichGIS\munich.gdb"
arcpy.MakeFeatureLayer_management(in_fc,lyrFC)
# get list of object ids
objIDs = []
objIDField = arcpy.Describe(lyrFC).OIDFieldName
Rows = arcpy.SearchCursor(lyrFC)
while Row in Rows:
objIDs.append(Row.getValue(objIDField))
del Row, Rows
# temp polygons
tmpFC = "in_memory/tmpPoly"
# one by one clip raster to polygons
arcpy.env.workspace= outGDB
for objID in objIDs:
where = "{0} = {1}".format(objIDField,objID)
arcpy.SelectLayerByAttributes_management(lyrFC,where)
arcpy.CopyFeatures_management(lyrFC,tmpFC)
ext = arcpy.Describe(tmpFC).Extent
extString = "{0} {1} {2} {3}".format(ext.XMin, ext.YMin, ext.XMax, ext.YMax)
out_raster = "clip{0}".format(objID)
arcpy.Clip_management(in_raster, extString, out_raster, tmpFC)
print arcpy.GetMessages(0)
arcpy.Delete_management(tmpFC)