Making mapsheets

Overview of workflow:
Scan chart (JPG) -> convert to PPM -> convert to JHC -> georeference -> patch charts into box header sheets

Making the backdrop charts:
In the DFO data, a chart was scanned in four pieces, then linearly transformed to ground coordinates (rotate, scale, & shift). 
The scanned image is usually in JPG format, convert to PPM using xv (xv image.jpg).

Once loaded, right click in the image once to display the control window.  Click 'save' and choose 'PPM raw' as the format.  Be sure to click the 'Normal Size' option otherwise it saves whatever is in the viewing window.

The PPM image must be converted to JHC format using the command PCItoJHC:

	PCItoJHC -in infile.ppm -out mapname -ppm

This converts 24-bit RGB into three files with the following convention (mapname is taken from out flag in PCItoJHC command):
mapname.band1
mapname.band2
mapname.band3

where band 1 is Red channel, etc.  The ppm file can be viewed in ascii with the following command:

	od -c Tmp02.ppm | more
This makes an optical dump to stdout and prints header information containing X and Y dimensions, as well as data upper limit (255).


Coordinate Transformation
Once backdrop charts are in proper format, they must be georeferenced.  This is done using a simple linear transformation with two control points.
Transformation was done with two user-selected points (use intersecting gridlines on map sheet and query their x,y coordinates in the scanned image).

The control point coordinates are stored in a file with extension .geocoords, with the following format:

	2
	-66.8 45.06667 689 858
	-66.833333 45.06667 1230 1404

The first line is the number of points, the next two lines contains the coordinates for each control point inthe following order (long, lat, x, y).

Each band is run through the 'distortImage' command which produces a georeferenced file.  A script can be setup to do all three bands for each chart as in the following example:

	#AREA 4 ------------------------------
	distortImage \
	        -geo \
	        -coords Tmp04.geocoords \
	        -in Tmp04.band1 \
	        -out Tmp04.reg.band1 \
	        << eno10
	3.4
	3.4
	eno10

	distortImage \
	        -geo \
	        -coords Tmp04.geocoords \
	        -in Tmp04.band2 \
	        -out Tmp04.reg.band2 \
	        << eno11
	3.4
	3.4
	eno11
	
	distortImage \
	        -geo \
	        -coords Tmp04.geocoords \
	        -in Tmp04.band3 \
	        -out Tmp04.reg.band3 \
	        << eno12
	3.4
	3.4
	eno12
	
the input "3.4" is the metres per pixel of the output images (???).


Alternatively, if the background imagery is projected with an unrotated Mercator projection and you know the projection latitude 
of the imagery, you can use the chart2omg program.  This is most useful for TIFF files of nautical charts, which we often
use as a backdrop in imagery.  The command must be repeated for all three bands of the data.  The projection latitude is
specified with -plat, this value is usually explicitly written somewhere on the chart.
The same file type for coordinates can be used as explained in the distortImage example above.

chart2omg -in 777801.band1 -plat 68.5 -coords 777801.coords 
chart2omg -in 777801.band2 -plat 68.5 -coords 777801.coords 
chart2omg -in 777801.band3 -plat 68.5 -coords 777801.coords 


Patching
--------

Once charts are georeferenced, they can be patched together and trimmed to fit into each of the mapsheets in the DTM directory.  This is done throught the patchArea command which can be run through a script as follows:

	#
	cp ../DTM/Letang$1.sun_315 Letang$1.band1
	cp ../DTM/Letang$1.sun_315 Letang$1.band2
	cp ../DTM/Letang$1.sun_315 Letang$1.band3
	patchArea -prime -back 255 -ignore 255 -interp -out Letang$1.band1 -import Tmp0*.reg.band1
	patchArea -prime -back 255 -ignore 255 -interp -out Letang$1.band2 -import Tmp0*.reg.band2
	patchArea -prime -back 255 -ignore 255 -interp -out Letang$1.band3 -import Tmp0*.reg.band3

Helpful tip:  If you're patching in multiple charts (or pieces of charts, e.g. scanned a chart into 9 segments), don't use -ignore 255, otherwise the overlap & inevitable mismatch between charts looks nasty.  Without the -ignore switch, the charts simply overwrite each other.

the 'cp' commands copy the sun files into band files in order to give the band files the proper header structure (instead of using makeblank).  The patchArea command primes the band files which wipes out the sun data, and essentially determines which charts fit in the area and patches them in. 

The following is an 'ls' dump from the Chart directory after these steps.  Comments are added at the end of the line.

-rw-rw-rw-    1 jhc      omg      2294294 Dec 19 14:57 Tmp01.jpg  # Conversion of jpg to ppm of scanned charts
-rw-rw-rw-    1 jhc      omg      6675204 Dec 19 14:57 Tmp01.ppm 
-rw-rw-rw-    1 jhc      omg      2072964 Dec 19 14:57 Tmp02.jpg
-rw-rw-rw-    1 jhc      omg      6675204 Dec 19 14:57 Tmp02.ppm
-rw-rw-rw-    1 jhc      omg       876869 Dec 19 14:57 Tmp03.jpg
-rw-rw-rw-    1 jhc      omg      6675180 Dec 19 14:57 Tmp03.ppm
-rw-rw-rw-    1 jhc      omg      1436146 Dec 19 14:57 Tmp04.jpg
-rw-rw-rw-    1 jhc      omg      6675204 Dec 19 14:58 Tmp04.ppm
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 11:18 Tmp02.band3  # Conversion of ppm to JHC format.
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 11:18 Tmp02.band2
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 11:18 Tmp02.band1
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 11:21 Tmp03.band3
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 11:21 Tmp03.band2
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 11:21 Tmp03.band1
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 11:21 Tmp01.band3
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 11:21 Tmp01.band2
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 11:21 Tmp01.band1
-rw-rw-rw-    1 jhc      omg           55 Dec 20 11:59 Tmp01.geocoords  # Coordinate transformation. 
-rw-rw-rw-    1 jhc      omg      4580620 Dec 20 12:02 Tmp01.reg.band1
-rw-rw-rw-    1 jhc      omg           56 Dec 20 12:17 Tmp02.geocoords
-rw-rw-rw-    1 jhc      omg      4458050 Dec 20 12:19 Tmp02.reg.band1
-rw-rw-rw-    1 jhc      omg           55 Dec 20 12:20 Tmp03.geocoords
-rw-rw-rw-    1 jhc      omg      4420717 Dec 20 12:22 Tmp03.reg.band1
-rw-rw-rw-    1 jhc      omg      4580620 Dec 20 12:27 Tmp01.reg.band2
-rw-rw-rw-    1 jhc      omg      4580620 Dec 20 12:28 Tmp01.reg.band3
-rw-rw-rw-    1 jhc      omg      4458050 Dec 20 12:30 Tmp02.reg.band2
-rwxrwxrwx    1 jhc      omg          402 Dec 20 12:31 patchsheet*
-rw-rw-rw-    1 jhc      omg      4458050 Dec 20 12:31 Tmp02.reg.band3 
-rw-rw-rw-    1 jhc      omg      4420717 Dec 20 12:33 Tmp03.reg.band2
-rw-rw-rw-    1 jhc      omg      4420717 Dec 20 12:34 Tmp03.reg.band3
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 12:38 Tmp04.band3
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 12:38 Tmp04.band2
-rw-rw-rw-    1 jhc      omg      2226064 Dec 20 12:38 Tmp04.band1
-rw-rw-rw-    1 jhc      omg           60 Dec 20 12:40 Tmp04.geocoords
-rwxrwxrwx    1 jhc      omg         1641 Dec 20 12:43 regall*
-rwxrwxrwx    1 jhc      omg          496 Dec 20 12:43 patchall*
-rwxrwxrwx    1 jhc      omg           19 Dec 20 12:43 temp*
-rw-rw-rw-    1 jhc      omg      4530834 Dec 20 12:45 Tmp04.reg.band1
-rw-rw-rw-    1 jhc      omg      4530834 Dec 20 12:47 Tmp04.reg.band2
-rw-rw-rw-    1 jhc      omg      4530834 Dec 20 12:48 Tmp04.reg.band3
-rw-rw-rw-    1 jhc      omg      4001024 Dec 20 13:01 Letang0.band1  # output from patchArea
-rw-rw-rw-    1 jhc      omg      4001024 Dec 20 13:14 Letang0.band2
-rw-rw-rw-    1 jhc      omg      4001024 Dec 20 13:26 Letang0.band3
-rw-rw-rw-    1 jhc      omg      4001024 Dec 20 13:43 Letang1.band1
-rw-rw-rw-    1 jhc      omg      4001024 Dec 20 14:01 Letang1.band2
-rw-rw-rw-    1 jhc      omg      4001024 Dec 20 14:16 Letang1.band3
-rw-rw-rw-    1 jhc      omg      4001024 Dec 20 14:27 Letang2.band1
-rw-rw-rw-    1 jhc      omg      4001024 Dec 20 14:49 Letang2.band2
-rw-rw-rw-    1 jhc      omg      4001024 Dec 20 15:00 Letang2.band3
-rw-r--r--    1 jhc      omg      4001024 Dec 20 15:11 Letang3.band1
-rw-r--r--    1 jhc      omg      4001024 Dec 20 15:22 Letang3.band2
-rw-r--r--    1 jhc      omg      4001024 Dec 20 15:38 Letang3.band3
-rw-r--r--    1 jhc      omg      4001024 Dec 20 15:55 Letang4.band1
-rw-r--r--    1 jhc      omg      4001024 Dec 20 16:11 Letang4.band2
-rw-r--r--    1 jhc      omg      4001024 Dec 20 16:19 Letang4.band3
-rw-r--r--    1 jhc      omg      4001024 Dec 20 16:29 Letang5.band1
-rw-r--r--    1 jhc      omg      4001024 Dec 20 16:40 Letang5.band2
-rw-r--r--    1 jhc      omg      4001024 Dec 20 16:50 Letang5.band3
-rw-r--r--    1 jhc      omg      4001024 Dec 20 16:58 Letang6.band1
-rw-r--r--    1 jhc      omg      4001024 Dec 20 17:06 Letang6.band2
-rw-r--r--    1 jhc      omg      4557235 Dec 20 17:16 overview.band2
-rw-r--r--    1 jhc      omg      4557235 Dec 20 17:16 overview.band1
-rw-r--r--    1 jhc      omg      4001024 Dec 20 17:16 Letang6.band3
-rw-r--r--    1 jhc      omg      4557235 Dec 20 17:16 overview.band3


Last modified: February 21st, 2001