import arcpy
# Set workspace for listing
arcpy.env.workspace = r"T:\chastain\PrgGIS\World"
# Get a list of all feature classes
fcs = arcpy.ListFeatureClasses("*")
# Loop through the list
for fc in fcs:
#print names
print("These feature classes are in the World folder", fc)
Output = fc + "Buff"
arcpy.Buffer_analysis(fc, Output, "100 Meters")
ERROR 000670: output Output Feature Class is same as input Input Features
Failed to execute (Buffer).
Put a couple print statements in before you call Buffer to see what the values of fc and Output are.
it looks like this:
import arcpy
# Set workspace for listing
arcpy.env.workspace = r"T:\chastain\PrgGIS\World"
# Get a list of all feature classes
fcs = arcpy.ListFeatureClasses("*")
# Loop through the list
for fc in fcs:
#print names
print("These feature classes are in the World folder", fc)
These feature classes are in the World folder Cities.shp
These feature classes are in the World folder Country.shp
These feature classes are in the World folder Lakes.shp
These feature classes are in the World folder Rivers.shp
I don't help people who work with shape files. You should use os.path — Common pathname manipulations — Python 3.8.2 documentation to split the shape file name from the extension, add the suffix to the name, and then rejoin the name and extension.
currently you're trying to add "buff" to something with a .shp extension I guess?
for fc in fcs:
output_path = fc[:-4] + "_buff"
with the '[:-4]
the error is
arcgisscripting.ExecuteError: ERROR 000210: Cannot create output T:\chastain\PrgGIS\World\CitiesBuff.shp
Failed to execute (Buffer).
sorry I forgot the .shp extension.
for fc in fcs:
output_path = fc[:-4] + "_buff.shp"
or as Joshua says:
for fc in fcs:
output_path = os.path.join(fc[:4], "buff.shp")
or even better as Joshua says, save it as a feature class.
the program is supposed to get the names, print them, buffer them and then to a new output. so it looks like it is stopping on the buffer end. So now I have changed the Output and it looks like it is trying to work.
Output = r"C:\Users\johnny.monds\Desktop\Test" +fc[:-4] + "_Buff.shp"
arcpy.Buffer_analysis(fc, Output, "100 Meters")
These feature classes are in the World folder Cities.shp
These feature classes are in the World folder Country.shp
Traceback (most recent call last):
File "<string>", line 12, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\analysis.py", line 1101, in Buffer
raise e
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\analysis.py", line 1098, in Buffer
retval = convertArcObjectToPythonObject(gp.Buffer_analysis(*gp_fixargs((in_features, out_feature_class, buffer_distance_or_field, line_side, line_end_type, dissolve_option, dissolve_field, method), True)))
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset Country.shp does not exist or is not supported
Failed to execute (Buffer).
of course, I should have noticed this.
fcs is just a list of the string names of the feature classes/shapefiles in that workspace.
simply join the workspace path to fc in fcs to give a full filepath
for fc in fcs:
fc_path = os.path.join(arcpy.env.workspace, fc)
Ok first, I want to THANK YOU. You have been a gigantic help. Second, I have to revisit this tomorrow. Third, I think I am having an issue with the size of the shapefile and buffer because it is giving me a general error, and my internet has slowed somewhat, I don't know why. Fourth, I want to thank you for your patience, I am a new learner and some of the small stuff escapes me. Thank you