[GRASSLIST:1948] Re: Conversion of ER Mapper data

Rod Paterson rpaterso at vic.bigpond.net.au
Mon Jun 11 21:20:58 EDT 2001


-----Original Message-----
From: Rich Shepard <rshepard at appl-ecosys.com>
To: B. Byars <Bruce_Byars at baylor.edu>
Cc: grasslist at baylor.edu <grasslist at baylor.edu>
Date: Tuesday, 12 June 2001 06:34
Subject: [GRASSLIST:1946] Re: Conversion of ER Mapper data


>On Mon, 11 Jun 2001, B. Byars wrote:
>
>> Write your ermapper files out as raw satellite data (by band).  GRASS will
>> work directly with the band data.
>
>Bruce,
>
>  Can I do this from the data files? The maps are geologic maps of a portion
>of Nevada and they're downloading as I write, in ERmapper format.
>
>  I don't have/have access to ERmapper to do any manipulations with them.
>
>Thanks,
>
>Rich
>


Rich,
        Appended is an old Email containing some shell scripts that I wrote to
allow the import/export of rasters between grass and ermapper. They were written
for grass4.1.3 and the Unix version of ERMapper so your files should have a byte
order of MSBfirst in the ERMapper header. If not then you could use 'dd' in the
scripts to reorder bytes depending on whether you're dealing with integers or
not.
The scripts need updating for Grass5 to handle reals and null values etc

       The import script simply writes out a grass raster header file in cellhd
and links the original ERMapper file to the cell directory. ERMapper images must
be single band only.

   good luck
   Rod Paterson
   Email: rpaterso at bigpond.net.au

OLD EMAIL WITH SHELLSCRIPTS:

It is unnecessary to convert to ascii to take a single band of a byte or integer
ERMapper image into Grass.You simply need to have each band as a separate image
and then run the shell script attached.
However because you are wanting to change the cell resolution also, the problem
becomes a little more complicated.
The following steps will achieve the required result.

Set up an algorithm to display the MSS band area of interest in ERMapper.

In ERMAPPER use the Algorithm Mode 'output to dataset' and select 'output to
dataset options' in the main IMAGES menu.Click on 'Set Defaults'.

Examine the number of image lines and pixels which will be output by default.
If you require a square pixel recalculate the number of lines and pixels
for this area which would give the required cell size and enter them in
the 'Cells Across','Cells Down' fields.Select 'Output Data Type' to be
'Unsigned 8 bit Integer' or 'Signed 16 bit Integer' , Grass can handle either
format.The former is appropriate in this case.Select an 'Output Path Name'
for the new image and then hit 'GO' on the main menu.

The default resampling for the new cell size is nearest neighbour, OR if you
tick the 'Smooth Resampling' box in the algorithm window you will get bilinear
resampling.

Once you have produced your new image you are ready to take it into Grass.
To do this go into Grass select the appropriate MapSet and run the attached
shell script.
This script will build a Grass header file for your new image in cellhd
by examining the ERMapper header and extracting the parts required.It then
links the ERMapper image into your cell directory so that you don't have to
have two copies on your disk.

#### Start Import Shell Script ####
-------------cut here
#!/bin/sh
#
# This shell script will create a GRASS cellhd file from an ER Mapper .ers
# file.
# This shell script program shows
# how easy it is to copy from ER Mapper's ASCII format header files in to the
# GRASS header format.
#
if [ "$#" -ne "2" ]
then
echo "Use full path to ERMapper image from within a GRASS shell"
echo "Do not include the .ers extension"
echo "Usage: import_ermapper_to_grass <file> $LOCATION/cellhd/<file>"
exit 1
fi
ln -s $1 $LOCATION/cell/$2
ERS=$1.ers
GRASS=$LOCATION/cellhd/$2
echo > $GRASS "# GRASS $GRASS cellhd file created from ER Mapper $ERS file"
tr < $ERS '[a-z]' '[A-Z]' | awk -F= '
BEGIN {
        offsetx = 0.0;
        offsety = 0.0;
        xdim = 0.0;
        ydim = 0.0;
        regx = 0.0;
        regy = 0.0;
        nrows = 0;
        ncols = 0;
        bytorder = 0;
        form = 0;
}
/PROJECTION/               { proj = $2 }
/REGISTRATIONCELLX/        { offsetx = $2 }
/REGISTRATIONCELLY/        { offsety = $2 }
/METERSX/ || /EASTINGS/    { regx = $2 }
/METERSY/ || /NORTHINGS/   { regy = $2 }
/XDIMENSION/               { xdim = $2 }
/YDIMENSION/               { ydim = $2 }
/NROFLINES/                { nrows = $2 }
/NROFCELLSPERLINE/         { ncols = $2 }
/NROFBANDS/                { nbands = $2 }
/UNSIGNED8BITINTEGER/      { form = 0 }
/UNSIGNED16BITINTEGER/     { form = 1 }
/UNSIGNED32BITINTEGER/     { form = 2 }
/IEEE[48]BYTEREAL/         { print "ERROR - FLOAT NOT SUPPORTED BY GRASS" }
/ SIGNED8BITINTEGER/       { print "ERROR - SIGNED INTS NOT SUPPORTED BY
GRASS" }
/HEADEROFFSET/             { print "ERROR - HEADEROFFSET NOT SUPPORTED BY
GRASS - USE OUTPUT TO DATASET" }
/BYTEORDER/                { bytorder = $2 }
END {
            if (bytorder == LSBFIRST) print "ERROR - LSB byteorder NOT SUPPORTED
BY GRASS";
            if (nbands > 1) print "ERROR - GRASS ONLY SUPPORTS ONE BAND - USE
OUTPUT TO DATASET";
            if (substr(proj,1,7) ~ /\"*TM*/) print "proj:            1";
                 else print "proj:        UNKNOWN" ;
            if (substr(proj,1,7) ~ /\"*TM*/) zone = (substr(proj,8,2));
                 else zone = 1;
        printf("zone:            %s\n", zone);
        printf("north:           %f\n", regy + (offsety * ydim));
        printf("south:           %f\n", regy - ((nrows-offsety) * ydim));
        printf("east:            %f\n", regx + ((ncols-offsetx) * xdim));
        printf("west:            %f\n", regx - (offsetx * xdim));
        printf("cols:            %d\n", ncols);
        printf("rows:            %d\n", nrows);
        printf("e-w resol:       %f\n", xdim);
        printf("n-s resol:       %f\n", ydim);
        printf("format:          %d\n", form);
        printf("compressed:      0")
}
' >> $GRASS
-------------------------------------cut  here
#### END Import Shell Script ####

The script should be placed in your path ie./usr/local/bin
and executed with two file name arguments.
The first is the "absolute path" to the ERMapper image and the second is
the name for the GRASS cell file
Please note I have not tried to use this script with LAT LONG datasets
so you might experience some problems here but it works well with UTM.

I have also included a script to take GRASS rasters to ERMapper which
you might also find useful.

#### Start Export Shell Script ####
-------------cut here
#!/bin/sh
#
# This shell script will create a .ERS file from a GRASS4.1 image header file
# (cellhd directory) and link the cell image to the .ERS file location.
#

if [ "$#" -ne "2" ]
then
echo "Usage: export_grass_to_ermapper $LOCATION/cellhd/<file>
$GISDBASE/$LOCATION_NAME/<file>"
exit 1
fi
GRASS=$LOCATION/cellhd/$1
ERS=$GISDBASE/$LOCATION_NAME/$2.ers
echo > $ERS "# ER Mapper $ERS file created from $GRASS file."
tr -d < $GRASS [:] | tr [a-z] [A-Z] | awk '
BEGIN {
        proj = 0;
        comp = 0;
        zone = 0;
        xdim = 0.0;
        ydim = 0.0;
        regx = 0.0;
        regy = 0.0;
        nbands = 1;
        ncols = 0;
        nrows = 0;
        nbits = 0;

}
/PROJ/                  { proj = $2 }
/ZONE/                  { zone = $2 }
/NORTH/                 { regy = $2 }
/WEST/                  { regx = $2 }
/COLS/                  { ncols = $2 }
/ROWS/                  { nrows = $2 }
/E-W/                   { xdim = $3 }
/N-S/                   { ydim = $3 }
/FORMAT/                { nbits = $2 }
/COMPRESSED/            { comp = $2 }
END {
print
printf("DatasetHeader Begin\n");
printf("\tVersion       = \"4.1\"\n");
printf("\tDataSetType   = ERStorage\n");
printf("\tDataType      = Raster\n");
printf("\tByteOrder     = MSBfirst\n");
printf("\tCoordinateSpace Begin\n");
printf("\tDatum = \"AGD66\"\n");
printf("\t%s%s%d%s\n","Projection       = ","\"TMAMG",zone,"\"");
printf("\tCoordinateType = EN\n");
printf("\tUnits = \"Meters\"\n");
printf("\tRotation      = 0:0:0.0\n");
printf("\tCoordinateSpace End\n");
printf("RasterInfo Begin\n");
        if(nbits=="0")
printf("\tCellType      = Unsigned8BitInteger\n");
        else
        if(nbits=="1")
printf("\tCellType      = Unsigned16BitInteger\n");
        else
        if(nbits=="2")
printf("\tCellType      = Unsigned32BitInteger\n");
printf("\tNullCellValue = 0\n");
printf("\tCellInfo Begin\n");
printf("\t\tXdimension = %f\n",xdim+0);
printf("\t\tYdimension = %f\n",ydim+0);
printf("\tCellInfo End\n");
printf("\tNrOfLines = %d\n",nrows+0);
printf("\tNrOfCellsPerLine = %d\n",ncols+0);
printf("\tRegistrationCoord Begin\n");
printf("\tEastings  = %d\n",regx+0);
printf("\tNorthings = %d\n",regy+0);
printf("\tRegistrationCoord End\n");
printf("\tNrOfBands = %d\n",nbands+0);
printf("\tRasterInfo End\n");
printf("DatasetHeader End\n");
}
' >> $ERS
ln -s $LOCATION/cell/$1 $GISDBASE/$LOCATION_NAME/$1
r.compress -u $1
-------------------------------------cut  here
#### END Export Shell Script ####

Note:ERMapper requires that the GRASS raster be uncompressed
     before it can read it.Therefore the above script runs
     r.compress on the cell file as its final task.This has
     some implications for management of disk storage space
     as some high resolution (small cell dimension) files can
     become very large.

     Both scripts expect to be run from within GRASS as
     they rely on the GRASS environment variables.


        Good Luck
        Rod Paterson




More information about the grass-user mailing list