Feature Class Z To ASCII (3D Analyst)

Summary

Exports 3D features to ASCII text files in XYZ, GENERATE, or profile format.

Usage

Syntax

FeatureClassZToASCII_3d (in_feature_class, output_location, out_file, {format}, {delimiter}, {decimal_format}, {digits_after_decimal}, {decimal_separator})
ParameterExplanationData Type
in_feature_class

The 3D point, multipoint, polyline, or polygon feature class that will be exported to an ASCII file.

Feature Layer
output_location

The folder that output files will be written to.

Folder
out_file

Specifies the output file name.

When exporting a feature class containing lines or polygons to XYZ format, the file name is used as a template. This is because the XYZ format's simplicity only supports one line or polygon per file. The restriction actually reaches to the part level, so if a feature has multiple parts, each part will be written to a separate file. The files will be given the prefix and suffix specified in the dialog box along with the OID of each feature, as well as any additional characters needed to make each file name unique.

File; Folder
format
(Optional)

The format of the ASCII file being created.

  • GENERATE—Creates output in GENERATE format.
  • XYZ—Creates output in XYZ format. One file will be created for each line or polygon in the input feature.
  • PROFILE—Creates output in PROFILE format. This is only available for line features.
String
delimiter
(Optional)

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
(Optional)

Specifies the method used to determine the number of significant digits stored in the output files.

  • AUTOMATICThe number of significant digits needed to preserve the available precision, while removing unnecessary trailing zeros, is automatically determined.
  • FIXEDThe number of significant digits is defined in the Digits after Decimal parameter.
String
digits_after_decimal
(Optional)

Used when the Decimal Notation is set to FIXED. This determines how many digits after the decimal are written for floating-point values written to the output files.

Long
decimal_separator
(Optional)

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

Code Sample

FeatureClassZToASCII example 1 (Python window)

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 example 2 (stand-alone script)

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)

Environments

Related Topics

Licensing Information

ArcView: Requires 3D Analyst
ArcEditor: Requires 3D Analyst
ArcInfo: Requires 3D Analyst

6/10/2013