print "the input list" for f in fcs: print f
import sys, string, os, win32com.client gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
import sys, string, os, arcgisscripting gp = arcgisscripting.create()
#BatchClipFCs.py # #Author # Dan Patterson # Dept of Geography and Environmental Studies # Carleton University, Ottawa, Canada # Dan_Patterson@carleton.ca # #Purpose # Batch clips feature classes (eg shapefiles) in a project # and writes them to a folder. # Many batch clip examples exist, this is compiled for demonstration # purpose for a class # #Properties (right-click on the tool and specify the following) #General # Name BatchClipFCs # Label Batch Clip Feature Classes # Desc Batch clip feature classes (eg shapefiles) and saves # them to a folder. # #Source BatchClipFCs.py # #Parameter list # Parameter Properties # Display Name Data type Type Direction MultiValue # argv[1] Feature(s) to clip Feature Layer Required Input Yes # argv[2] Polygon clip layer Feature Layer Required Input No # argv[3] Append to output String Optional Input No # filename # argv[4] Output folder Folder Required Input No #-------------------------------------------------------------------- #Import the standard modules # Get a list of feature classes (shapefiles) # Get the clip feature class # Get the optional text to append to the filename output filename # Get the output folder # Usage: BatchClipFCs <Input_Features> <ClipWith> <optional_text> <Output_Workspace> # --------------------------------------------------------------------------- # # Import system modules, Create the Geoprocessor object and # Load required toolboxes... # import sys, string, os, arcpy # # Script arguments... FCsToClip = arcpy.GetParameterAsText(0) #a list of features fcs = string.split(FCsToClip, ";") #split into a list # clipWith = arcpy.GetParameterAsText(1) #clip layer desc = arcpy.Describe(clipWith) clipWithType = desc.ShapeType # addToName = arcpy.GetParameterAsText(2) #optional text to append to output name if(addToName == "#"): addToName = "" # outputFolder = arcpy.GetParameterAsText(3) #a folder # arcpy.AddMessage("\n" + "Batch Clip Feature layers" + "\n" ) # if (clipWithType == "Polygon"): for fc in fcs: try: fc=fc.replace("'","") #check if a layers name has been changed desc = arcpy.Describe(fc) fcDataType = desc.DataType arcpy.AddMessage("Data type = " + fcDataType) if(fcDataType == "FeatureClass"): # Feature class on disk theName = str(os.path.split(fc)[1]) outFile = outputFolder + "\\" + theName + addToName + ".shp" else: # Feature layer FullName = desc.CatalogPath theName = (os.path.split(FullName)[1]).replace(".shp","") theName = str(fc).replace(" ","_") outFile = outputFolder + "\\" + theName + addToName + ".shp" arcpy.AddMessage("Output file from layer " + outFile) # arcpy.AddMessage("Clipping " + str(fcDataType) + ": " + fc + " Saving to: " + outFile + "\n") try: arcpy.Clip_analysis(fc, clipWith, outFile, "") except: arcpy.AddMessage("Could not clip " + fc + " with " + clipWith + " to " + outFile) except: arcpy.AddMessage("cannot describe" + fc) else: arcpy.AddMessage (clipWith + " is not a polygon layer, clipping terminated" ) #
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.