Summary
Converts an ASCII file representing raster data to a raster dataset.
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 ...
-
The NODATA_VALUE is the value in the ASCII file that will be assigned to NoData cells in the output raster. This value is normally reserved for those cells whose true value is unknown. When the output raster is created, a system-generated NoData value will be used in place of the NODATA_VALUE. The NoData in raster datasets topic contains information on how to change the NoData value once the raster is created.
The number of cell values contained in the file must be equal to the number of rows times the number of columns, or 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.
Certain Raster storage environments may apply to this tool.
For the Pyramid environment settings, only the Build pyramids setting is honored. The remaining Pyramid environment settings are ignored. More control over the nature of the pyramids can be obtained in a subsequent step by using the Build Pyramids tool.
For the Raster statistics environment settings, only setting the Calculate Statistics parameter to None is supported (the other parameters are ignored). This is only for raster formats other than Esri Grid.
For the Compression environment settings, only the type of compression may be honored. This is only for raster formats other than Esri Grid.
Syntax
arcpy.conversion.ASCIIToRaster(in_ascii_file, out_raster, {data_type})
Parameter | Explanation | Data Type |
in_ascii_file | The input ASCII file to be converted. | File |
out_raster | The output raster dataset to be created. When not saving to a geodatabase, specify .tif for a TIFF file format, .CRF for CRF file format, .img for an ERDAS IMAGINE file format, or no extension for an Esri Grid raster format. | Raster Dataset |
data_type (Optional) | The data type of the output raster dataset.
| 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)
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes