How to embed a CASI Image into Mapserver


0. Assumtions 

[userdirk@stress cgi-bin]$ ./mapserv -v
MapServer version 3.6.0 OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP SUPPORTS=TTF INPUT=TIFF INPUT=EPPL7 INPUT=JPEG INPUT=POSTGIS INPUT=SHAPEFILE

1. Source Imagery Dataset

Number of CASI Images in Set: 18
Flight Number: 01_235
Polygon: P_2054
Date: 08/12/01
Time: 10:46 - 11:31
Location: Swansea
Resolution: 1 metre
Number of Bands: 14
Geometric Correction: Level II
Format: Erdas Imagine (.img)
Notes: Level II correction using gps and ins data only

Wave Bands:
Band 1: 440 - 450
Band2 : 465 - 475
Band 3: 485 - 495
Band 4: 545 - 555
Band 5: 665 -675
Band 6: 680 - 685
Band 7: 695 - 705
Band 8: 705 - 715
Band 9: 715 - 725
Band 10: 745 - 755
Band 11: 760 - 765
Band 12: 775 - 785
Band 13: 855 - 865
Band 14: 870 - 890

EXAMPLE FILE:
File: /..../geo5217a.img
Dims: 2266 x 4909 x 14 [BSQ]
Size: [Unsigned Int] 318,533,056 bytes.
File Type  : ERDAS 8.X
Sensor Type: Unknown
Byte Order : Host (Intel)
Projection : Transverse Mercator
  Datum    : Ord. Survey G. Britain 1936
  X Pixel  : 1.00000 Meters
  Y Pixel  : 1.00000 Meters
Wavelength : None
Upper Left Corner: 1,1
Description: ERDAS 8.x (.img) File
Imported into ENVI [Tue Jul 30 13:44:38 2002]

2. Displaying and Processing the dataset

I displayed the images in ENVI Version 3.5 October 8, 2001:
  1. File -> Open External File -> IP SOftware -> ERDAS 8.x (.img)

  2. In order to get a 'close to true color' image in RGB I found following Band
    Combination most usefull:


Creating a Band Subset Image with ENVI

Since ENVI processes it's own native image format much faster I created a subset image with the
3 layers mentioned obove.

  1. Display: File -> Save Image As -> Image File

  2. Choosen options:
    Spatial Subset -> Image : define an area  for the new image

    Output Filetype: ENVI

Creating a Spatial Subset Image with ENVI

For experimenting with mapserver I created a spatial subset  from the ENVI image.
Mapserver 3.6 doesn't support RGB GeoTiff Images, so I went for a .bmp picture.

  1. Display: File -> Save Image As -> Image File

  2. Choosen options:

    Spatial Subset -> Image : define an area  for the new image [e.g. 1000 x 1000]

    Spatial Subset -> Map :
    (write down all spatial informations (Upper Left, Lower Right, Date, Projection)

    Output Filetype: TIFF

Errors

Unfortunately ENVI created a broken .tif image without displaying an error message. Mapserver never displayed this corrupted file and we received no error message
as well.
By displaying the .tif Image in Imagemagick, the following error occured:

"
[userdirk@stress data] display subset_1000_1000_white.tif

display: unknown field with tag 34736 (0x87b0) ignored. (subset_1000_1000_white.tif) [No such file or directory].

"

I got arround this error, by resaving the ENVI .tiff image as a .tif image in imagemagick .


all black values (0) are suddenly NULL values, which causes trouble when the image is display with "offset 0" in mapserver
)

Possible Errors in Mapserver

It's hard to debugg mapserver apps. My experience are:

What Image output format should be used?

It really depends on what you want to display. 

generally:
  1. .GIF : I have no experience with .gif images, since the GD Library doesn't support this format anymore. Because of that you can't even use .gif symbology in your mapserver application. By the way: the Mapserver 3.5 tutorial dataset used to (?) include .gif symbology - so make sure the .gifs are transformed into .png and the symbology imagetype is changed.

  2. .PNG : .png is probably the best overall solution for online maps. Text and geometrical objects (lines, points, polygons) are rendered very well and clear. PNG maps are easy to read and the human eye can easily distinct between colors and different objects.

  3. .JPEG : Since JPEG is a great way to compress 'photo like' images, they are usefull for raster images in a mapserver application (e.g. satelliteimages ). On the other hand, they add noise and unsharpen text (e.g. on labels) and straight boundaries of objects.

EXAMPLES: 

Filesize and optical perception advantage of .PNG at simple spatial objects
PNG outperforms in quality and filesize

Mapserver 3.6 JPEG output
26853 byte

Mapserver 3.6 PNG output
9449 byte

Filesize advantage of .JPG at 'foto like images' and complex structures
JPEG offers good results at a reseanable filesize


Mapserver 3.6 JPEG output
53.901 Kbyte



Mapserver 3.6 PNG output
 132.259 Kbyte

Deleting temporary files, using crontab in LINUX RedHat


  1. create a little shellscript (e.g. killtemp.sh )

  2. put the following 2 lines in killtemp.sh

    #!/bin/sh
    find /var/www/html/URGENT/temp/ -name '*.*' -type f -cmin +60 -exec rm -f - '{}' ';'


    #!/bin/sh
    - tells LINUX to use

    find /var/www/html/temp/ -name '*.*' -type f -cmin +60 -exec rm -f - '{}' ';'
    tells LINUX to search the temporary folder for files older than 60 min


  3. edit your crontab:
    crontab -e

  4. insert the following line, to execute killtemp.sh every 15min :

    0,15,30,49 * * * * /home/user/./killtemp.sh %
    ~
    .
    .
    .
    ~
    ~
    ~
    ~
    "/tmp/crontab.20542" 1L, 50C

  5. make your script executeable