要素类 Z 转 ASCII (3D Analyst)

摘要

以 XYZ、GENERATE 或专用标准格式将 3D 要素导出到 ASCII 文本文件。

用法

语法

FeatureClassZToASCII_3d (in_feature_class, output_location, out_file, {format}, {delimiter}, {decimal_format}, {digits_after_decimal}, {decimal_separator})
参数说明数据类型
in_feature_class

导出到 ASCII 文件的 3D 点、多点、折线 (polyline) 或面要素类。

Feature Layer
output_location

将在其中写入输出文件的文件夹。

Folder
out_file

指定输出文件的名称。

将包含线或面的要素类导出为 XYZ 格式时,会将该文件名用作模板。这是因为 XYZ 格式非常简单,仅支持每个文件中包含一条线或一个面。此限制实际上已经涉及到组成部分级别,因此如果要素由多个部分组成,则每个部分将被写入到单独的文件。文件将被赋予在对话框中指定的前缀和后缀,文件中的每个要素均带有 OID,并且必要时文件名中还会附加额外字符以使每个文件名唯一。

File; Folder
format
(可选)

要创建的 ASCII 文件的格式。

  • GENERATE - 以 GENERATE 格式创建输出。
  • XYZ - 以 XYZ 格式创建输出。将针对输入要素中的每条线或每个面创建一个文件。
  • PROFILE - 以 PROFILE 格式创建输出。这仅可用于线要素。
String
delimiter
(可选)

The field delimeter used in the text file.

  • SPACEA space will be used to delimit field values. This is the default.
  • COMMAA comma will be used to delimit field values. This option is not applicable if the decimal separator is also a comma.
String
decimal_format
(可选)

指定用于确定输出文件中存储的有效数字位数的方法。

  • AUTOMATIC在移除多余的后补零时,自动确定保留可用精度所需的有效数字位数。
  • FIXED有效数字位数在小数点后的位数参数中定义。
String
digits_after_decimal
(可选)

十进制记数法设置为 FIXED 时使用此参数。此参数确定写入到输出文件的浮点值在小数之后写入的位数。

Long
decimal_separator
(可选)

The decimal character used in the text file to differentiate the integer of a number from its fractional part.

  • DECIMAL_POINTA point is used as the decimal character. This is the default.
  • DECIMAL_COMMAA comma is used as the decimal character.
String

代码示例

FeatureClassZToASCII 示例 1(Python 窗口)

The following sample demonstrates the use of this tool in the Python window:

import arcpy
from arcpy import env

arcpy.CheckOutExtension("3D")
env.workspace = "C:/data"
arcpy.FeatureClassZToASCII_3d("LidarPts.shp", "", "ASCII_LidarPts.txt",
                            "GENERATE", "COMMA", "FIXED", 6, "DECIMAL_POINT")
FeatureClassZToASCII 示例 2(独立脚本)

The following sample demonstrates the use of this tool in a stand-alone Python script:

'''****************************************************************************
Name: FeatureClassZToASCII Example
Description: This script demonstrates how to use the
             FeatureClassZToASCII tool to create generate files for all
             z-aware point features in a given workspace.
****************************************************************************'''
import arcpy
import exceptions, sys, traceback
from arcpy import env

try:
    # Obtain a license for the ArcGIS 3D Analyst extension
    arcpy.CheckOutExtension('3D')
    # Set environment settings
    env.workspace = 'C:/data'
    # List all points in the target workspace
    fcList = arcpy.ListFeatureClasses("*", "POINT")
    if fcList:
        # Set Local Variables
        outFolder = "C:/output"
        outFormat = "GENERATE"
        delimeter = "SPACE"
        decimal = "FIXED"
        digits = 3
        dec_sep = "DECIMAL_POINT"
        for fc in fcList:    
            # Use Describe method to evaluate whether the feature class is z-aware
            desc = arcpy.Describe(fc)
            if desc.hasZ == True:
                # Define the output file name by replacing '.shp' with _ascii.txt
                outName = fc.replace('.shp', '') + "_ascii.txt"
                #Execute FeatureClassZToASCII_3d
                arcpy.FeatureClassZToASCII_3d(fc, outFolder, outName, outFormat, delimeter, decimal, digits, dec_sep)
    else:
        print "There are no feature classes in the " + env.workspace + " directory."


except arcpy.ExecuteError:
    print arcpy.GetMessages()
except:
    # Get the traceback object
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    # Concatenate error information into message string
    pymsg = 'PYTHON ERRORS:\nTraceback info:\n{0}\nError Info:\n{1}'\
          .format(tbinfo, str(sys.exc_info()[1]))
    msgs = 'ArcPy ERRORS:\n {0}\n'.format(arcpy.GetMessages(2))
    # Return python error messages for script tool or Python Window
    arcpy.AddError(pymsg)
    arcpy.AddError(msgs)

环境

相关主题

许可信息

ArcView: 需要 3D Analyst
ArcEditor: 需要 3D Analyst
ArcInfo: 需要 3D Analyst

7/10/2012