0

I am trying to perform a batch clip using arcpy. I cannot seem to get the script to save where I want them to, with a specific name. I remove the "Ohio_" and rename them with "Summit_" what is in the directory ex. "Summit_CensusTracts".

Any input?

import arcpy
import os
from arcpy import env

arcpy.env.workspace = "H:/Python_GIS/Summit_County_Project/Shapefiles"
# Variables
fcInput = "H:/Python_GIS/Summit_County_Project/Shapefiles/Ohio_Counties.shp"
fcOutput = "H:/Python_GIS/Summit_County_Project/Shapefiles/Summit_County_Updates/Summit.shp"

# Expression
whereClause = "COUNTY_NAM = 'SUMMIT'"

# Select
arcpy.Select_analysis(fcInput, fcOutput, whereClause)


# Processing

outFolder = "H:/Python_GIS/Summit_County_Project/Shapefiles/Summit_County_Updates"
clipFeature = "H:/Python_GIS/Summit_County_Project/Shapefiles/Summit_County_Updates/Summit.shp"
shpList = ["Ohio_CensusTracts.shp", "Ohio_Cities.shp", "Ohio_Hydro.shp", "Ohio_Roads.shp"]

for root, dirs, files in os.walk(outFolder):
   for name in files:
      if name.startswith("Ohio_"):
         # shapefile name without extension
         shpName = os.path.splitext("Summit")[0]
         # absolute file path
         absFile = os.path.abspath(os.path.join(root,name))
         # output file path
         output_layer = outFolder
         # buffer
         arcpy.Clip_analysis(shpList, clipFeature, output_layer)
1

You have a number of errors in this script. Let's take a look at your clip function:

arcpy.Clip_analysis(shpList, clipFeature, output_layer)

You are adding a list of shapefile names in the first parameter. This should be a single feature layer or feature class. In the third parameter, you are adding an output folder path instead of explicitly defining the feature class to be created. See the Clip help page for details on the function parameters.

Additionally, it appears as if you are running a select, yet fail to use the selected features fcOutput later in the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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