ASCII to Raster output to 1-bit or 8-bit rasters?

1284
10
05-20-2011 01:28 PM
DaveVerbyla
New Contributor III
I have some large ascii rasters output from models that are essentially 0 or 1 pixel values.
For example:
NCOLS 2
NROWS 2
XLLCORNER 0
YLLCORNER 0
CELLSIZE 1000
NODATA_VALUE 0
1 0
0 1

The ASCII to Raster tool outputs to a 32-bit signed integer raster, when really these values can be represented by a 1-bit raster.  Seems like an inefficient way to go!  Is there some other ASCII to Raster tool (in GDAL?, Python Imaging Library?) that is more efficient in importing ASCII data into rasters?
0 Kudos
10 Replies
EricRice
Esri Regular Contributor
Dave,

Are you outputting to Esri GRID format?  GRID's are always 32 bit.  We read ascii files as raster datasets these days, so the ASCII to Raster tool isn't really necessary.  You should be able to just add the ascii file to ArcMap and maybe have to calculate stats on it.

These links might be useful.
Technical specifications for raster dataset formats
Supported raster dataset file formats

Eric
0 Kudos
DaveVerbyla
New Contributor III
No, it seems very inefficient to output to a 32-bit raster as a data type when
8-bit is common and models typically output 1-bit (sea ice/no sea ice) or
4-bit (0=unvegetated, 1=broadleaf forest, 2= conifer forest, 3=shrub) etc.
This can be done using ENVI and output to tif raster format. 
I'm  hoping ESRI improves the ASCII to Raster tool soon!

With hundreds of ASCII files, I'm looking for an efficient method using arcpy,
GDAL, Python Imaging Library, etc. to output to 1-bit, 4-bit, 8-bit rasters.
0 Kudos
Luke_Pinner
MVP Regular Contributor
If you have (or install) gdal, try the gdal_translate utility: http://www.gdal.org/gdal_translate.html. It doesn't export to 1 or 4 bit, 8 bit is the smallest.

gdal_translate --ot Byte src_dataset dst_dataset
0 Kudos
SteveLynch
Esri Regular Contributor
The "ASCII" raster format is a supported raster format. Which means that if the file has a .asc extension it can be used directly.

Which means that you can use the CopyRaster tool to change and set the output bit depth.

Steve
0 Kudos
DaveVerbyla
New Contributor III
I created a test ASCII file (testraster.asc) containing the following:
NCOLS 2
NROWS 2
XLLCORNER 0
YLLCORNER 0
CELLSIZE 1000
NODATA_VALUE 0
1 0
0 1

When i tried to add testraster.asc to Arcmap, it does not read this as an ascii raster:
"Name of the field is invalid [NCOLS 2]
0 Kudos
SteveLynch
Esri Regular Contributor
It must be greater than 2 by 2

Please try it with a 3x3 or larger raster

Steve
0 Kudos
DaveVerbyla
New Contributor III
Same problem with testraster.asc:
NCOLS 5
NROWS 5
XLLCORNER 0
YLLCORNER 0
CELLSIZE 1000
NODATA_VALUE 0
1 0 0 1 1
0 1 1 1 1

Error-->Name of field is invalid [NCOLS 5]
Where is there documentation showing you can directly read ASCII rasters in ArcGIS10?
0 Kudos
DaveVerbyla
New Contributor III
The problem with directly reading is that results in a 32-bit signed integer grid
which is really inefficient since this information could be stored as a 1-bit raster:
NCOLS 5
NROWS 5
XLLCORNER 0
YLLCORNER 0
CELLSIZE 1000
NODATA_VALUE 0
1 0 0 1 1
0 1 1 1 1
0 1 1 1 1
0 1 1 1 1
0 1 1 1 1
0 Kudos
SteveLynch
Esri Regular Contributor
Please have a look at the links that Eric provided earlier in this thread for a reference as to where it is documented.

If you cannot add the 5x5 file then please contact Esri Support.

-Steve
0 Kudos