----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Content-Lines: 44

> From: rewerts@ecn.purdue.edu (Chris C Rewerts)
 
> 
> I am building vector maps from dlg data that is in 2 UTM zones.
> This will be part of a new mapbase we are putting together.
> 
> What (if anything) do I need to do to accomodate multiple UTM zones?
> 
> The main question: can maps from more than one UTM zone be used in
> the same mapbase, or will I need to separate them into mapbases for
> each zone? 
> 
> If they can exist and be used in the same mapbase, what will be the 
> trick to setting the default window coordinates? (When all the maps
> were in the same zone, I read the headers to find the coordinates of
> the extreme north, south, east and west edges...)
> 
 

You can't put maps from two zones into a single location, and expect anything
to work correctly.  But you can convert the maps in one zone into the other
by extending the zone east or west.  To briefly summarize UTM zones, they
have a central meridian, with a value of 500,000 meters east.  Distances
east and west of this zone are expressed as values ranging from about 200,000 
to 800,000, depending on your latitude.  The zones are defined as 6 degrees
wide, which means they're narrower (in meters on the ground) the higher
the latitude.  There is nothing to say you can't make a zone, say 8 degrees
wide, if you can live with the increased distortion at the edges.  

So, what you want to do is to extend your zone to cover the maps in the other
zone, figure out a transformation to convert coordinates in zone n + 1 to zone
n, and apply it to your vector files.  This transformation is well defined
for near-boundary areas.  

I wrote a little shell script a while back to do this.  It follows below.  It
is a GRASS 3 script, meaning the command names have to be changed to protect
the guilty.  It works on ASCII vector files, since I come from the
school that says why use C when you have awk (OK,OK, I don't program in
C).  Painful as it is, it works.

If you make it smarter, and or find anything wrong, please let me know.  I may
have to do this again someday...

-kenn gardels
----------
X-Sun-Data-Type: cshell-script
X-Sun-Data-Name: shift_dig
X-Sun-Content-Lines: 125

#!/bin/csh -f
# script to force ascii dig files from one zone into an adjacent zone
# works OK for areas not more than one degree from zone boundary or 
# more than 100km N/S
# Based on "Universal Transverse Mercator Grid Technical Manual TM 5-241-8
#    Dept of the Army, April 1973
# ken gardels  (gardels@ced.berkeley.edu)
# WARNING - this is not foolproof


#  variable convention - capital letters for values in original zone
#      lower case for new zone
#      one, two, three correspond to south, central, north E and N values


# Step 1  Get zone info and an origin point for transformation
#	in the center of area (user defined)

echo -n "Original zone for file: "
set Z = $<
echo -n "New zone for conversion: "
set z = $<

echo "Type in the UTM values of a known point, within the original zone,"
echo  "near the zone boundary and approximately mid-way north/south in"
echo "the study area."
echo -n "Control point - north: "
set Ntwo = $<
echo -n "Control point - east: "
set Etwo = $<

# make two more points 100,000m north and south
@ Ethree = $Etwo
@ Eone = $Etwo
@ Nthree = $Ntwo + 100000
@ None = $Ntwo - 100000

# Step 2  Convert the three points into lat/long, then into UTM in new zone

echo -n "defining transformation...please wait..."
set two = `Mu2ll e=${Etwo} n=${Ntwo} z=$Z s=clark66 |xargs Mll2u s=clark66 z=$z`
set three = `Mu2ll e=${Ethree} n=${Nthree} z=$Z s=clark66 |xargs Mll2u s=clark66 z=$z`
set one = `Mu2ll e=${Eone} n=${None} z=$Z s=clark66 |xargs Mll2u s=clark66 z=$z`

# parse Mll2u output into discrete variables, without labels

set etwo = `echo $two[1] | sed 's/e=//'`
set ntwo = `echo $two[2] | sed 's/n=//'`
set ethree = `echo $three[1] | sed 's/e=//'`
set nthree = `echo $three[2] | sed 's/n=//'`
set eone = `echo $one[1] | sed 's/e=//'`
set none = `echo $one[2] | sed 's/n=//'`
echo done.

echo -n "File(s) to convert: "
set files = $<
foreach f ($files )
# make a backup to be sure
/bin/cp $f $f.$Z
echo converting $f...
# first convert all vertices
awk '\
BEGIN { Etwo = '${Etwo}' ; Ntwo = '${Ntwo}' ;\
	etwo = '${etwo}' ; ntwo = '${ntwo}' ;\
	gone = ('${nthree}' - '${none}') / 2 ; \
	gtwo = ('${nthree}' - ( 2 * '${ntwo}' ) + '${none}') / 2 ;\
	hone = ('${ethree}' - '${eone}') / 2 ; \
	htwo = ('${ethree}' - ( 2 * '${etwo}' ) + '${eone}') / 2     }\
\
/^[A-Z]/ {print;next}\
/^   / { e = .00001 * ( $2 - Etwo ) ; n = .00001 * ( $1 - Ntwo ) ;\
	east = etwo + (gone * e) + (hone * n) - (htwo * ((e * e) - (n * n))) + (2 * gtwo * n * e ) ;\
	north = ntwo + (gone * n) - (hone * e) - (gtwo * ((e * e) - (n * n))) - (2 * htwo * n * e ) ;\
	printf "  %11.2f  %11.2f\n", north, east ;\
	next}   ' $f > $f.$z 

# now go and painfully set the digit file edges to match min/max
#  of vertex values
echo setting file boundaries...
set east = `grep "^   " $f.$z | sort -n +1 | tail -1 | cut -c18-26`
echo east = $east
set west = `grep "^   " $f.$z | sort -n +1 | head -1 | cut -c18-26`
echo west = $west
set north = `grep "^   " $f.$z | sort -n | tail -1 | cut -c4-13`
echo north = $north
set south = `grep "^   " $f.$z | sort -n | head -1 | cut -c4-13`
echo south = $south

#ex $f.$z << EOF
ex - $f.$z << EOF
/ZONE/s/$Z/$z/
/WEST EDGE/s/ [0-9].*/ $west/
/EAST EDGE/s/ [0-9].*/ $east/
/NORTH EDGE/s/ [0-9].*/ $north/
/SOUTH EDGE/s/ [0-9].*/ $south/
wq
EOF

/bin/mv $f.$z $f

#  Step 4  Convert the attribute file using the same factors
echo converting attribute file...
if ( -d ../dig_att ) then
	/bin/cp ../dig_att/$f ../dig_att/$f.$Z
	awk '\
	BEGIN { Etwo = '${Etwo}' ; Ntwo = '${Ntwo}' ;\
		etwo = '${etwo}' ; ntwo = '${ntwo}' ;\
		gone = ('${nthree}' - '${none}') / 2 ; \
		gtwo = ('${nthree}' - ( 2 * '${ntwo}' ) + '${none}') / 2 ;\
		hone = ('${ethree}' - '${eone}') / 2 ; \
		htwo = ('${ethree}' - ( 2 * '${etwo}' ) + '${eone}') / 2     }\
\
	{ e = .00001 * ( $2 - Etwo ) ; n = .00001 * ( $3 - Ntwo ) ;\
		east = etwo + (gone * e) + (hone * n) - (htwo * ((e * e) - (n * n))) + (2 * gtwo * n * e ) ;\
		north = ntwo + (gone * n) - (hone * e) - (gtwo * ((e * e) - (n * n))) - (2 * htwo * n * e ) ;\
		printf "%s %14.7f %14.6f     %d\n", $1, east, north, $4 ;\
		next}   ' ../dig_att/$f > ../dig_att/$f.$z

	/bin/mv ../dig_att/$f.$z ../dig_att/$f
endif

echo $f done.
end

echo All done\!

