AnsweredAssumed Answered

Output name to be the same as the input name (in a new folder) after processing

Question asked by ziziz on Sep 1, 2015
Latest reply on Sep 3, 2015 by ziziz

Hi,

 

I was following this simple example from ESRI (ArcGIS Desktop ):

 

import arcpy

from arcpy import env

import os

# The workspace environment needs to be set before ListFeatureClasses

# to identify which workspace the list will be based on

env.workspace = "c:/data"

out_workspace = "c:/data/results/"

clip_features = "c:/data/testarea/boundary.shp"

# Loop through a list of feature classes in the workspace

for fc in arcpy.ListFeatureClasses():

  # Set the output name to be the same as the input name, and

  # locate in the 'out_workspace' workspace

  #

  output = os.path.join(out_workspace, fc)

 

  # Clip each input feature class in the list

  #

  arcpy.Clip_analysis(fc, clip_features, output, 0.1)

 

 

 

I would like to run a very similar code with "Identity_analysis", however, I receive an error message when run my code, as it wants to create only one shapefile rather many with the same name(s)  as the input file(s). Here is the code. It generates only one file " identity_country.shp" and than gives me an error msg that the file already exist.

 

import arcpy

from arcpy import env

import os

 

dirpath = r'C:\reggie\stat\spatial'

arcpy.env.workspace = dirpath

#set local parameters

identity_feature = r'C:\reggie\stat\GIS_stats\country.shp'

out_workspace = r'C:\reggie\stat\spatial\identity_country'

for fc in arcpy.ListFeatureClasses("*"):

     output = os.path.join(out_workspace, fc)

     arcpy.Identity_analysis(fc, identity_feature, output, "ALL", "", "NO_RELATIONSHIPS")

Outcomes