Feature Class Z To ASCII (3D Analyst)
Summary
Exports 3D features to ASCII text files storing GENERATE, XYZ, or profile data.
Usage
-
The PROFILE format provides profile information for 3D line features that can be imported into specialized graphing applications. Each line feature in the source feature class will be written to a separate file whose name is suffixed with the line's unique ID. Each row in the profile table contains the distance from the starting position of the line to the vertex (D) followed by the elevation of that vertex.
0 z1 D1 z2 D2 z3 D3 z4
The XYZ format store x, y, and z coordinates as floating-point values, where each row represents a distinct point record.
x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4
Note:Point and multipoint features are written to the same file, whereas each polygon and polyline feature is written to a separate text file whose name is suffixed with the feature's ID. Each part of features with multiple parts gets written to a separate file and its file name will have its part number appended after the feature's ID.
The GENERATE format does not support header lines, but it stores all input features in one file.
- Point features are stored with their respective ID and XYZ coordinates, and the last line is denoted by the END keyword:
id1 x1 y1 z1 id2 x2 y2 z2 id3 x3 y3 z3 id4 x4 y4 z4 END
Note:Multipoint features that originate from the same record in the originating feature class will share the same ID.
- Line and polygon features are separated by the END keyword, and two successive END keywords indicate the end of the file:
id1 x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4 END id2 x1 y1 z1 x2 y2 z2 END END
Note:The first and last XYZ coordinates for polygon features are always identical.
- Point features are stored with their respective ID and XYZ coordinates, and the last line is denoted by the END keyword:
Syntax
Parameter | Explanation | Data 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 |
The name of the resulting ASCII file. If a line or polygon feature class is exported to XYZ format, the file name is used as a base name. Each feature will have a unique file output since the XYZ format only supports one line or polygon per file. Multipart features will also have each part written to a separate file. The file name will be appended with the OID of each feature, as well as any additional characters needed to make each file name unique. | String |
format (Optional) |
The format of the ASCII file being created.
| String |
delimiter (Optional) |
The field delimeter used in the text file.
| String |
decimal_format (Optional) |
The method used to determine the number of significant digits stored in the output files.
| 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.
| String |
Code Sample
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")
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)