Raster to ASCII (Conversion)

Summary

Converts a raster dataset to an ASCII text file representing raster data.

Usage

  • The input raster dataset can be any valid raster dataset.

  • The structure of the ASCII file consists of header information containing a set of keywords, followed by cell values in row-major order.

    The format of the file in general is:

        NCOLS xxx
        NROWS xxx
        XLLCORNER xxx
        YLLCORNER xxx
        CELLSIZE xxx
        NODATA_VALUE xxx
        row 1
        row 2
        .
        .
        row n

    The definitions of the keywords are as follows:

    • NCOLS and NROWS are the number of columns and rows in the raster defined by the ASCII file.

    • XLLCORNER and YLLCORNER are the coordinates of the lower left corner of the lower left cell.

    • CELLSIZE is the cell size of the raster.

    • NODATA_VALUE is the value that is to represent NoData cells.

    • In the data stream of cell values, row 1 of the data is the top of the raster, row 2 is just under row 1, and so on.

  • An example of an ASCII raster file is:

        NCOLS 480
        NROWS 450
        XLLCORNER 378922
        YLLCORNER 4072345
        CELLSIZE 30
        NODATA_VALUE -32768
        43 2 45 7 3 56 2 5 23 65 34 6 32 54 57 34
        35 45 65 34 2 6 78 4 2 6 89 3 2 7 45 23 5 ...
  • The NODATA_VALUE is the value in the ASCII file that will represent cells that are NoData in the input raster. This value is normally reserved for those cells whose true value is unknown.

  • The end of each row of data from the raster is terminated with a carriage return character in the file.

  • Both integer and floating point rasters can be converted to an ASCII raster file.

  • This tool only writes the origin as the lower left corner of the lower left cell. The Copy Raster tool also supports the origin as the center of the lower left cell.

Parameters

LabelExplanationData Type
Input raster

The input raster dataset.

The raster can be integer or floating-point type.

Raster Layer
Output ASCII raster file

The output ASCII raster file.

File

arcpy.conversion.RasterToASCII(in_raster, out_ascii_file)
NameExplanationData Type
in_raster

The input raster dataset.

The raster can be integer or floating-point type.

Raster Layer
out_ascii_file

The output ASCII raster file.

File

Code sample

RasterToASCII example 1 (Python window)

Converts a raster dataset to an ASCII file representing raster data.

import arcpy
from arcpy import env
env.workspace = "c:/data"
arcpy.RasterToASCII_conversion("elevation", "c:/output/sa500.asc")
RasterToASCII example 2 (stand-alone script)

Converts a raster dataset to an ASCII file representing raster data.

# Name: RasterToASCII_Ex_02.py
# Description: Converts a raster dataset to an ASCII file representing 
#    raster data. 
# Requirements: None

# Import system modules
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

# Set local variables
inRaster = "elevation"
outASCII = "c:/output/elevation.asc"

# Execute RasterToASCII
arcpy.RasterToASCII_conversion(inRaster, outASCII)

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics