HowTo:  Use the arcpy.CreateUniqueName function with a tool that has the output name and output location parameters separated

相关信息
Article ID: 41267
Software:
ArcGIS - ArcEditor 10
ArcGIS - ArcInfo 10
ArcGIS - ArcView 10
ArcGIS for Desktop Advanced 10.1, 10.2
ArcGIS for Desktop Standard 10.1, 10.2
ArcGIS for Desktop Basic 10.1, 10.2
Platforms: N/A

问题描述
The arcpy.CreateUniqueName data function creates a unique output name by adding integers to the output name. This helps avoid errors or unintentionally overwriting existing datasets. The return format of the data function includes the full path name, and some geoprocessing tools require that an output location and an output name are specified in separate parameters. The Feature Class to Feature Class geoprocessing tool is one example of this. In these instances, the unique name must be used without the full path name, and this can be done with Python.
已邀请:

易智瑞技术支持

赞同来自:

解决方案
The following code example shows how to eliminate the full path name from the return value and pass it into a tool such as the Feature Class to Feature Class tool.



#import arcpy and the OS module
import arcpy, os
from arcpy import env

#set workspace parameter
ws = env.workspace = r"C:\Temp\scratch.gdb"

#set input/output variables
inFeatures = "Customers"
outOriginal = "CustomerLocations"

#create unique name
unique_name = arcpy.CreateUniqueName(outOriginal)

#grab the basename of the full path returned
outName = os.path.basename(unique_name)

#pass outName into Feature Class to Feature Class
arcpy.FeatureClassToFeatureClass_conversion(inFeatures, ws, outName)




其它相关参考
  1. CreateUniqueName (arcpy)
  2. Feature Class To Feature Class (Conversion)


创建及修改时间
Created: 6/10/2013

Last Modified: 8/8/2013
原文链接
http://support.esri.com/en/kno ... 41267

要回复问题请先登录注册