GME

Geospatial Modelling Environment

import.asciigrid (Import Raster From ASCII Grid)

Imports an ASCII grid file to a binary raster format (GRID, TIFF, IMG)

Description

This tool imports an ASCII grid file to a binary raster format (Grid, GeoTIFF, or Imagine Image format). The ASCII raster file must conform to certain standards, although the tool does allow some flexibility in the specification of the header information.

ASCII raster files begin with 5 or 6 lines of header information that determine the extent and orientation of the raster. For example:

ncols 43200

nrows 18000

xllcorner -180

yllcorner -60

cellsize 0.0083333337679505

NODATA_value -9999

-9999 -9999 ...

The Nodata line is optional, although it is wise to specify it to prevent default values from being used that may conflict with your data. The header lines can also be specified with each line bracketed within <...>, e.g. . White space (spaces, tabs) on the header lines should not influence the ability of the tool to extract the header data.

To determine if your ASCII file meets the appropriate formatting criteria, you can open the ASCII grid file in a text editor (e.g. Notepad++) if it is small enough (no more than a few megabytes usually). For larger files the GME file.readlines command is an easy way of viewing the header. E.g.:

file.readlines(file="C:\data\climate.asc", start=1, end=6);

You must specify the appropriate output raster pixel type. The options are double precision (range: any real number), long integer (range: +/- 2.1 billion), short integer (range: +/- 32768), or byte (range: 0-255). You should be able to determine the appropriate pixel type from the metadata associated with the ASCII grid file. Failing that, you can inspect the file to attempt to determine the range. Again, the GME file.readlines command is useful for inspecting small portions of even very large files. E.g.:

file.readlines(file="C:\data\climate.asc", start=5000, end=5001);

Note that you will usually only want to inspect one line at a time using this command (each line contains a lot of data). If the output type is DOUBLE, then you must specify the output as a IMG format raster.

Ideally, you should select the smallest output pixel data type for your date (byte < short < long < double in terms of the number of bytes of storage space required to store a single value. Although double is the most flexible format in that it can store almost any number, it also requires several times more disk space than the other types.

The projection information for the data must also be provided. You need to reference an ESRI .prj file. You can either reference an prj file from a dataset you know to be in the same projection, or copy the appropriate prj file from the
C:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems

folder. It is useful to copy the file locally to the same folder as the grid files. See the Projection Definition File section for more details on working with and creating projection files.

Syntax

import.asciigrid(in, prj, out, type, [delimiter]);

inthe input ASCII grid file
prjthe file containing the projection data of the input raster
outthe output raster, including the extension in the case of an IMG or TIF formats
typethe output raster pixel data type (options: DOUBLE, LONG, SHORT, CHAR)
[delimiter]the delimiting character(s) - normally one of these keywords: SPACE (default), COMMA, TAB, SEMICOLON, or COLON (see full help documentation for further details)

Example

import.asciigrid(in="C:\data\climate.asc", prj="C:\data\WGS 1984.prj", out="C:\data\climate.img", type="LONG");


Messages

Please consider making a purchase to support the continued development of these tools  Read more...

Tips on how to use this interface efficiently  Read more...

Links

Open Source GIS

Copyright © 2001-2014 Hawthorne L. Beyer, Ph.D., Spatial Ecology LLC    Connect on LinkedIn