ASCII To Raster (Conversion)

Summary

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

Legacy:

This is a deprecated tool. The Copy Raster tool can now be used to convert an ASCII file representing raster data to a raster dataset.

If you are using the browse button Browse text box on the Copy Raster tool, and the input file does not have an .asc extension, you can either rename the file to include that extension, or you can change the filter on the Input Raster dialog box from All Supported Types to Files. Renaming the file is the recommended option.

Usage

  • The input file is an ASCII-formatted text file.

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

    There are two variations of the structure of the ASCII file. One identifies the origin by the coordinates of the lower left corner of the lower left cell, the other as the center of the lower left cell.

    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.

      You can also use XLLCENTER and YLLCENTER to specify the origin by the coordinates of the center of the lower left cell.

    • CELLSIZE is the cell size of the raster.

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

    • Cell values should be delimited by spaces. No carriage returns are necessary at the end of each row in the ASCII file. The number of columns in the header is used to determine when a new row begins.

  • 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 ...
  • NODATA_VALUE is the value in the ASCII file that will be assigned to NoData cells in the output raster. This value is typically reserved for those cells with true values that are unknown. When the output raster is created, a system-generated NoData value will be used in place of NODATA_VALUE.

  • The number of cell values contained in the file must be equal to the number of rows multiplied by the number of columns; otherwise, an error will be returned.

  • The output data type can be either float or integer.

  • Once the output raster has been created, use the Define Projection tool to give it the appropriate coordinate system.

Parameters

LabelExplanationData Type
Input ASCII raster file

The input ASCII file to be converted.

File
Output raster

The output raster dataset to be created.

If the output raster will not be saved to a geodatabase, specify .tif for TIFF file format, .CRF for CRF file format, .img for ERDAS IMAGINE file format, or no extension for Esri Grid raster format.

Raster Dataset
Output data type
(Optional)

Specifies the data type of the output raster dataset.

  • IntegerAn integer raster dataset will be created.
  • FloatA floating-point raster dataset will be created.
String

arcpy.conversion.ASCIIToRaster(in_ascii_file, out_raster, {data_type})
NameExplanationData Type
in_ascii_file

The input ASCII file to be converted.

File
out_raster

The output raster dataset to be created.

If the output raster will not be saved to a geodatabase, specify .tif for TIFF file format, .CRF for CRF file format, .img for ERDAS IMAGINE file format, or no extension for Esri Grid raster format.

Raster Dataset
data_type
(Optional)

Specifies the data type of the output raster dataset.

  • INTEGERAn integer raster dataset will be created.
  • FLOATA floating-point raster dataset will be created.
String

Code sample

ASCIIToRaster example 1 (Python window)

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

import arcpy
arcpy.ASCIIToRaster_conversion("c:/data/elevation.asc", "c:/output/elevation", 
                               "INTEGER")
ASCIIToRaster example 2 (stand-alone script)

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

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

# Import system modules
import arcpy

# Set local variables
inASCII = "c:/data/elevation.asc"
outRaster = "c:/output/elevation02"
rasterType = "INTEGER"

# Execute ASCIIToRaster
arcpy.ASCIIToRaster_conversion(inASCII, outRaster, rasterType)

Licensing information

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

Related topics