r.in.arc.p

Greg Koerper greg at dubious.cor2.epa.gov
Thu Jan 13 19:59:39 EST 1994


Here's a simple perl script for converting existing ARC ascii grid data into
GRASS raster format.  It could be called from an aml for further efficiency. 

#!/usr/local/bin/perl	[change this as necessary for your site]

# r.in.arc.p [-N] input output
# converts an ascii ARC grid layer to a GRASS raster 
#	-N prevents conversion of null data values to 0 (default:  convert to 0)

require "getopts.pl";
&Getopts ('N');

# set parameters by default or argument

$zero = $opt_N ? 0 : 1;

print "reading ARC header, writing GRASS header\n";

$file = shift (@ARGV);
open (ARC, $file);
open (GRASS, "> $file.$$");
$raster = shift (@ARGV);

for ($i = 0; $i < 6; $i++) {
	$_ = <ARC>;
	($dummy, $value[$i]) = split (' ');
	}

($cols, $rows, $west, $south, $res, $null) = @value;
$east = $west + ($cols * $res);
$north = $south + ($rows * $res);

print "writing data values . . .\n";
print GRASS "north:\t$north\nsouth:\t$south\neast:\t$east\nwest:\t$west\n";
print GRASS "rows:\t$rows\ncols:\t$cols\n";

while (<ARC>) {
	if ($zero) {
		s/$null/0/g;
		}
	print GRASS;
	}
close ARC;
close GRASS;

print "reading GRASS ascii into raster format . . .\n";
system "r.in.ascii $file.$$ o=$raster";
# system "rm $file.$$";
print "done\n";
 
******************************************************************************
Greg Koerper                            Internet: greg at heart.cor.epa.gov
ManTech Environmental Technology, Inc.  
US EPA Environmental Research Lab	voice:	(503) 754-4490
200 SW 35th St., JSB                    fax:    (503) 754-4338
Corvallis, OR   97333     
******************************************************************************



More information about the grass-user mailing list