moving raster maps across UTM zone boundaries

Chris Rewerts rewerts at osiris.cso.uiuc.edu
Thu Apr 15 13:18:10 EDT 1993


flogden at hml.uiowa.edu (Fred Ogden) writes:

>Hello fellow GRASS users.

>	I've been fortunate in the past to have data sets well within UTM zones.
>Unfortunately, that happy period is at an end.  I am dealing with county soils
>and land use data for Oklahoma which is split between zones 14 and 15.  What I 
>want to do is bring the raster map for a county in zone 15, and patch it with
>a raster map in zone 14.  


[.....]
>Fred L. Ogden
>Iowa Institute of Hydraulic Research
>The University of Iowa
>Iowa City, IA 52242

>flogden at hml.uiowa.edu

I checked my archives, because I recalled dealing with this before.
Here is a shellscript that was kindly sent to me by Scott Wade some
time ago. I think it will help you with your task...

Chris Rewerts


---------------------------8<-------------------------------
#!/bin/sh

# UTM ZONE TRANSFORMATION SCRIPT FOR GRASS VECTOR DATA
#
# This Bourne shell script, for use in GRASS4.0, transforms GRASS
# vector data from one UTM zone to another.  This would typically be
# needed where a location straddles the boundary between two UTM zones.
# For the entire data set in the location to be sensible, one of the
# zones needs to be 'extended' to encompass all of the available data.
#
# All dig and dig_ascii vector data in the current mapset search path
# (not just the current mapset) can potentially be transformed.  All
# results are stored as binary dig layers in the current mapset.
# 
# The script is loosely based on a GRASS3 C-shell script written by Kenn
# Gardels, University of California, Berkeley.  His reference:  Department
# of the Army (1973), "Universal Transverse Mercator Grid Technical Manual",
# TM 5-241-8.
#
# This script was written in June 1992 by Scott Wade, Spatial Analysis and
# Systems Team, US Army Corps of Engineers Construction Engineering Research
# Laboratories [ wade at zorro.cecer.army.mil ].
#
# WARNING: This script has not been extensively tested.
# WARNING: The Clarke 1866 spheroid is assumed.


#######################################################################
# Determine if GRASS is being used

if [ ! "$GISBASE" ]
  then
  echo ""
  echo "ERROR:  must be in GRASS to use `basename $0`"
  echo ""
  exit
fi


#######################################################################
# Request needed information from user

echo ""
echo -n "Enter old UTM zone (zone to be converted FROM):  "
read OLDZONE
echo ""
if [ "$OLDZONE" -lt "1" -o "$OLDZONE" -gt "60" ]
  then
  echo "ERROR:  invalid UTM zone:  $OLDZONE"
  echo ""
  exit
fi

echo -n "Enter new UTM zone (zone to be converted TO):  "
read NEWZONE
echo ""
if [ "$NEWZONE" -lt "1" -o "$NEWZONE" -gt "60" ]
  then
  echo "ERROR:  invalid UTM zone:  $NEWZONE"
  echo ""
  exit
fi
if [ "$NEWZONE" -eq "$OLDZONE" ]
  then
  echo "New zone same as old zone; no tranformation performed."
  echo ""
  exit
fi

echo "Enter layer(s) to be converted from zone $OLDZONE to zone $NEWZONE,"
echo "separated by spaces."
echo ""
echo -n "> "
read THELAYERS
echo ""

if [ "$THELAYERS" = "" ]
  then
  exit
fi


# Beginning of loop

for LAYER in $THELAYERS
do

#######################################################################
# Search for the dig_ascii file in the current mapset search path.
# If not found, seaarch for the dig layer.  If neither are found,
# move on to the next named layer.
# The use of g.findfile and eval sets the variables $file and $mapset.

  eval `g.findfile element=dig_ascii file=$LAYER`

  if [ "$file" ]
    then
    DOIT=ASCII
  else
    eval `g.findfile element=dig file=$LAYER`

    if [ "$file" ]
      then
      DOIT=binary

#######################################################################
# If needed, convert old zone binary dig data to old zone dig_ascii file

      v.out.ascii input=$LAYER output=$LAYER.old

    else
      DOIT=n
      echo ""
      echo "ERROR:  layer $LAYER"
      echo "Neither dig nor dig_ascii file found in current mapset search path."
      echo ""
    fi

  fi

  if [ "$DOIT" = "ASCII" -o "$DOIT" = "binary" ]
    then
    echo ""
    echo -n "Converting $DOIT $LAYER to binary $LAYER.shift ..."


#######################################################################
# Convert old zone UTM ASCII data to old zone lat/long ASCII data.
# Lat/long is used as a 'data standard' for the transformation.
# The old-zone data is exported to lat/long, then later imported 
# back into UTM using the new zone.

    if [ "$DOIT" = "binary" ]
      then
      m.u2ll -r spheroid=clark66 zone=$OLDZONE input=$LOCATION/dig_ascii/$LAYER.old output=$LOCATION/dig_ascii/$LAYER.ll
    else
      m.u2ll -r spheroid=clark66 zone=$OLDZONE input=$LOCATION/dig_ascii/$LAYER output=$LOCATION/dig_ascii/$LAYER.ll
    fi

    if [ $? -ne 0 ]
      then
      echo ""
      echo "Problem using m.u2ll for layer $LAYER"
      echo ""
      exit
    fi

    echo -n "..."

# remove unneeded file

    if [ -f "$LOCATION/dig_ascii/$LAYER.old" ]
      then
      rm $LOCATION/dig_ascii/$LAYER.old
    fi
    echo -n "..."

#######################################################################
# Convert old zone lat/long ASCII data to new zone UTM dig_ascii data.
# The lat/long data is imported back into UTM using the new zone, so
# this is where the zone transformation occurs for the vector data.

    m.ll2u -rz spheroid=clark66 zone=$NEWZONE input=$LOCATION/dig_ascii/$LAYER.ll output=$LOCATION/dig_ascii/$LAYER.shift

    if [ $? -ne 0 ]
      then
      echo ""
      echo "Problem using m.ll2u for layer $LAYER"
      echo ""
      exit
   fi


    echo -n "..."

# remove unneeded file

    if [ -f "$LOCATION/dig_ascii/$LAYER.ll" ]
      then
      rm $LOCATION/dig_ascii/$LAYER.ll
    fi
    echo -n "..."



#######################################################################
# Convert new zone UTM dig_ascii data to new zone binary dig data

    v.in.ascii input=$LAYER.shift output=$LAYER.shift

    if [ $? -ne 0 ]
      then
      echo ""
      echo "Problem using v.in.ascii for layer $LAYER.shift"
      echo ""
      exit
    fi


    echo -n "..."

# remove unneeded file

    if [ -f "$LOCATION/dig_ascii/$LAYER.shift" ]
      then
      rm $LOCATION/dig_ascii/$LAYER.shift
    fi
    echo -n "..."


#######################################################################
# Convert dig_att data to new zone

# The old dig_att file is rearranged using AWK so that the GRASS commands
# m.u2ll and m.ll2u will work properly and still preserve all the needed
# data in the file.  AWK is used again to rearrange the results into the
# correct dig_att form.  The variable $mapset is set by g.findfile and
# eval earlier in the script.

    if [ -f "$LOCATION/../$mapset/dig_att/$LAYER" ]
      then
      cat $LOCATION/../$mapset/dig_att/$LAYER | awk '{ printf "%14s %14s %11s %1s\n", $2, $3, $4, $1 }' | m.u2ll sph=clark66 zone=$OLDZONE | m.ll2u -z sph=clark66 zone=$NEWZONE | awk '{ printf "%1s %14s %14s %11s\n", $4, $1, $2, $3 }' > $LOCATION/dig_att/$LAYER.shift
    else
      echo ""
      echo "WARNING:  no attribute data for $LAYER"
      echo ""
    fi


#######################################################################
# Copy dig_cats data to new name

  if [ -f "$LOCATION/../$mapset/dig_cats/$LAYER" ]
    then
    if [ ! -d "$LOCATION/dig_cats" ]
      then
      mkdir $LOCATION/dig_cats
    fi
    cp $LOCATION/../$mapset/dig_cats/$LAYER $LOCATION/dig_cats/$LAYER.shift
  fi


#######################################################################
# Run v.support for the newly transformed data layer

    v.support -r map=$LAYER.shift option=build

  fi

done





More information about the grass-user mailing list