[Mapserver-users] why does my raster layer turn my shapefile layer gray?

Chris Black cblack at CalAcademy.Org
Tue Mar 11 13:44:04 EST 2003


--------------040508010700000907040305
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Thanks, Ed and Dylan; my problem is solved.  I added the following to my 
map file:

OUTPUTFORMAT
  NAME png24bit
  DRIVER "GD/PNG"
  MIMETYPE "image/png"
  IMAGEMODE RGB
END

And this to my php script:

$map->selectOutputFormat('png24bit');

Performance is slower, naturally, now that the images have more than 
doubled in size.  I was *not* successful with adding 'PROCESSING 
"COLOR_MATCH_THRESHOLD=3"', as my 3.7 build isn't new enough (I pulled  
mapserver-3.7-win32-php4.3.0-gd2.zip 
<http://www2.dmsolutions.ca/mapserver/dl/mapserver-3.7-win32-php4.3.0-gd2.zip> 
from  http://www2.dmsolutions.ca/mapserver/dl/ ; it's dated 10-Feb-2003. 
 I don't want to get into the business of doing my own builds if I can 
help it (I'm on Windows; on *n*x I wouldn't mind so much), so I'll take 
the performance hit for now.

Thanks again.

-- Chris

Ed McNierney wrote:

>Chris -
>
>Today must be "I ran out of colors" Day <g>.
>
>This is the same issue Aaron Hunt posted under "TRANSPARENCY problem",
>and was discussed under "COLOR_MATCH_THRESHOLD" a few days ago.
>
>You're running out of colors in your 8-bit output image.  MapServer
>renders one layer at a time, starting from the beginning of your MAP
>file, and allocates new colors as needed by each layer.  After you've
>drawn enough layers to use 256 distinct colors, all subsequent layers
>are stuck with the 256 colors already defined, and MapServer chooses the
>closest fit.
>
>If you display just the "baylands" layer, you use up two colors - two
>shades of blue.  If you display just the "bayraster" layer, you get (I
>presume) 256 shades of gray.
>
>If you display the "bayraster" layer AND the "baylands" layer, the
>"bayraster" layer allocates 256 shades of gray, and there aren't any
>more palette colors available to create shades of blue - so the
>"baylands" layer is drawn using the shades of gray closest to those two
>shades of blue.  And that's not very close.
>
>Solution path #1 - Use the OUTPUTFORMAT block in 3.7 to create a 24-bit
>output image.  You will then get much larger map images, but you will no
>longer be constrained to the 256 colors in an 8-bit image.
>
>Solution path #2 - If you're using GDAL to read raster layers, see the
>mailing list for the COLOR_MATCH_THRESHOLD statement, which will cause
>MapServer to select a "close" match instead of an exact match when
>allocating colors for the raster layer.  This will result in an
>on-the-fly reduction in the number of colors used by your raster layer;
>instead of using up a different palette entry for every unique shade of
>gray, MapServer will consider a near match to be "close enough" and use
>that existing shade of gray.  This will mean that there are some palette
>colors still available when you get around to drawing the "baylands"
>layer.
>
>	- Ed
>
>Ed McNierney
>President and Chief Mapmaker
>TopoZone.com / Maps a la carte, Inc.
>73 Princeton Street, Suite 305
>North Chelmsford, MA  01863
>Phone: (978) 251-4242  Fax: (978) 251-1396
>ed at topozone.com
>
>
>-----Original Message-----
>From: Chris Black [mailto:cblack at CalAcademy.Org] 
>Sent: Monday, March 10, 2003 8:44 PM
>To: mapserver-users at lists.gis.umn.edu
>Subject: [Mapserver-users] why does my raster layer turn my shapefile
>layer gray?
>
>Hello all,
>
>I have a map with two layers: one is an ArcView grid file that is a 
>relief map of the SF Bay Area in various shades of gray.  The other is a
>
>shapefile that show the bay waters in two classes, shallow and deep.  If
>
>I display just the shapefile layer ("Baylands" in the mapfile below), 
>these two classes are two different shades of blue.  If I display the 
>raster layer ("bayraster") as well, the classes are changed to shades of
>
>gray.  Why does it happen, and how can I get my colors back?
>
>Much thanks for any help.
>
>-- Chris
>
>Mapserver version string:  "MapServer version 3.7 (development) 
>OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=PDF OUTPUT=SWF SUPPORTS=PROJ 
>SUPPORTS=TTF SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER
>
>SUPPORTS=GD2_RGB INPUT=EPPL7 INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE"
>
>I view the map with the url 
>"http://localhost/Scripts/mapserv.exe?map=C:/inetpub/wwwroot/mapserverap
>ps/IZG/testraster.map&mode=map"
>
>testraster.map:
>--------------- cut here ----------------------
># Note: Comments in a map file are preceeded by the pound (#) sign.
># When MapServer encounters the pound sign, it will ignore the
># rest of the line.  Unfortunately, you can't comment a whole block
># of code or text in MapServer.  So, you're stuck with adding pound
># signs for every line you wish to comment out.
>
>
>NAME CALCTYEX1
>EXTENT 467416 4085763 623532 4288980
>SIZE 350 300
>UNITS METERS
>SHAPEPATH "C:\inetpub\wwwroot\MapServerApps\IZG\data\"
>SYMBOLSET "C:\inetpub\wwwroot\MapServerApps\symbols\symbols.sym"
>
>
>
>LAYER
>    data "c:\inetpub\wwwroot\sfbay\data\EcoAtlas\grid\sfbayshr"
>    NAME "bayraster"
>    STATUS DEFAULT
>    TYPE RASTER
>    CLASS
>        NAME "Relief Map"
>    END # CLASS
>END # LAYER
>LAYER
>    NAME "Baylands"
>    DATA "vector\mbypsfby"
>    STATUS DEFAULT
>    TYPE POLYGON
>    CLASS
>        NAME "Deep Bay"
>        EXPRESSION ('[ENTITYID]' = 'A00000000000')
>        COLOR 51 51 255
>    END # CLASS
>    CLASS
>        NAME "Shallow Bay"
>        EXPRESSION ('[ENTITYID]' = 'A10000000000' OR '[ENTITYID]' = 
>'A10000000090' OR '[ENTITYID]' = 'B4ST00000000')
>        COLOR 102 102 204
>    END # CLASS
>END # LAYER
>END # FILE
>
>--------------- cut here ----------------------------
>I don't understand grid files very well, so here's the listing of the 
>grid directory and its children in case something is wrong there (though
>
>I don't think so, since the grid itself displays ok):
>-------- cut here -----------------
>C:/Inetpub/wwwroot/sfbay/data/EcoAtlas/grid:
>info
>sfbayshr
>sfbayshr.met
>sfbayshrw
>sfbr-sr-dbdesc.txt
>
>C:/Inetpub/wwwroot/sfbay/data/EcoAtlas/grid/info:
>arc.dir
>arc0000.dat
>arc0000.nit
>arc0001.dat
>arc0001.nit
>arc0002.dat
>arc0002.nit
>arc0002r.001
>
>C:/Inetpub/wwwroot/sfbay/data/EcoAtlas/grid/sfbayshr:
>dblbnd.adf
>hdr.adf
>log
>prj.adf
>sta.adf
>vat.adf
>w001001.adf
>w001001x.adf
>---------- cut here ----------------
>
>_______________________________________________
>Mapserver-users mailing list
>Mapserver-users at lists.gis.umn.edu
>http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>  
>


--------------040508010700000907040305
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <title></title>
</head>
<body>
Thanks, Ed and Dylan; my problem is solved. &nbsp;I added the following to my
map file:<br>
<br>
OUTPUTFORMAT<br>
&nbsp; NAME png24bit<br>
&nbsp; DRIVER "GD/PNG"<br>
&nbsp; MIMETYPE "image/png"<br>
&nbsp; IMAGEMODE RGB<br>
END<br>
<br>
And this to my php script:<br>
<br>
$map-&gt;selectOutputFormat('png24bit');<br>
<br>
Performance is slower, naturally, now that the images have more than doubled
in size. &nbsp;I was *not* successful with adding 'PROCESSING "COLOR_MATCH_THRESHOLD=3"',
as my 3.7 build isn't new enough (I pulled&nbsp; <a
 href="http://www2.dmsolutions.ca/mapserver/dl/mapserver-3.7-win32-php4.3.0-gd2.zip">mapserver-3.7-win32-php4.3.0-gd2.zip</a>
 from &nbsp;<a class="moz-txt-link-freetext" href="http://www2.dmsolutions.ca/mapserver/dl/">http://www2.dmsolutions.ca/mapserver/dl/</a> ; it's dated 10-Feb-2003.
&nbsp;I don't want to get into the business of doing my own builds if I can help
it (I'm on Windows; on *n*x I wouldn't mind so much), so I'll take the performance
hit for now.<br>
<br>
Thanks again.<br>
<br>
-- Chris<br>
<br>
Ed McNierney wrote:<br>
<blockquote type="cite"
 cite="mid13858AA1A74F30419F319ACB66A9D12201962E at mercator.topozone.com">
  <pre wrap="">Chris -

Today must be "I ran out of colors" Day &lt;g&gt;.

This is the same issue Aaron Hunt posted under "TRANSPARENCY problem",
and was discussed under "COLOR_MATCH_THRESHOLD" a few days ago.

You're running out of colors in your 8-bit output image.  MapServer
renders one layer at a time, starting from the beginning of your MAP
file, and allocates new colors as needed by each layer.  After you've
drawn enough layers to use 256 distinct colors, all subsequent layers
are stuck with the 256 colors already defined, and MapServer chooses the
closest fit.

If you display just the "baylands" layer, you use up two colors - two
shades of blue.  If you display just the "bayraster" layer, you get (I
presume) 256 shades of gray.

If you display the "bayraster" layer AND the "baylands" layer, the
"bayraster" layer allocates 256 shades of gray, and there aren't any
more palette colors available to create shades of blue - so the
"baylands" layer is drawn using the shades of gray closest to those two
shades of blue.  And that's not very close.

Solution path #1 - Use the OUTPUTFORMAT block in 3.7 to create a 24-bit
output image.  You will then get much larger map images, but you will no
longer be constrained to the 256 colors in an 8-bit image.

Solution path #2 - If you're using GDAL to read raster layers, see the
mailing list for the COLOR_MATCH_THRESHOLD statement, which will cause
MapServer to select a "close" match instead of an exact match when
allocating colors for the raster layer.  This will result in an
on-the-fly reduction in the number of colors used by your raster layer;
instead of using up a different palette entry for every unique shade of
gray, MapServer will consider a near match to be "close enough" and use
that existing shade of gray.  This will mean that there are some palette
colors still available when you get around to drawing the "baylands"
layer.

	- Ed

Ed McNierney
President and Chief Mapmaker
TopoZone.com / Maps a la carte, Inc.
73 Princeton Street, Suite 305
North Chelmsford, MA  01863
Phone: (978) 251-4242  Fax: (978) 251-1396
<a class="moz-txt-link-abbreviated" href="mailto:ed at topozone.com">ed at topozone.com</a>


-----Original Message-----
From: Chris Black [<a class="moz-txt-link-freetext" href="mailto:cblack at CalAcademy.Org">mailto:cblack at CalAcademy.Org</a>] 
Sent: Monday, March 10, 2003 8:44 PM
To: <a class="moz-txt-link-abbreviated" href="mailto:mapserver-users at lists.gis.umn.edu">mapserver-users at lists.gis.umn.edu</a>
Subject: [Mapserver-users] why does my raster layer turn my shapefile
layer gray?

Hello all,

I have a map with two layers: one is an ArcView grid file that is a 
relief map of the SF Bay Area in various shades of gray.  The other is a

shapefile that show the bay waters in two classes, shallow and deep.  If

I display just the shapefile layer ("Baylands" in the mapfile below), 
these two classes are two different shades of blue.  If I display the 
raster layer ("bayraster") as well, the classes are changed to shades of

gray.  Why does it happen, and how can I get my colors back?

Much thanks for any help.

-- Chris

Mapserver version string:  "MapServer version 3.7 (development) 
OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=PDF OUTPUT=SWF SUPPORTS=PROJ 
SUPPORTS=TTF SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER

SUPPORTS=GD2_RGB INPUT=EPPL7 INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE"

I view the map with the url 
<a class="moz-txt-link-rfc2396E" href="http://localhost/Scripts/mapserv.exe?map=C:/inetpub/wwwroot/mapserverapps/IZG/testraster.map&mode=map">"http://localhost/Scripts/mapserv.exe?map=C:/inetpub/wwwroot/mapserverap
ps/IZG/testraster.map&amp;mode=map"</a>

testraster.map:
--------------- cut here ----------------------
# Note: Comments in a map file are preceeded by the pound (#) sign.
# When MapServer encounters the pound sign, it will ignore the
# rest of the line.  Unfortunately, you can't comment a whole block
# of code or text in MapServer.  So, you're stuck with adding pound
# signs for every line you wish to comment out.


NAME CALCTYEX1
EXTENT 467416 4085763 623532 4288980
SIZE 350 300
UNITS METERS
SHAPEPATH "C:\inetpub\wwwroot\MapServerApps\IZG\data\"
SYMBOLSET "C:\inetpub\wwwroot\MapServerApps\symbols\symbols.sym"



LAYER
    data "c:\inetpub\wwwroot\sfbay\data\EcoAtlas\grid\sfbayshr"
    NAME "bayraster"
    STATUS DEFAULT
    TYPE RASTER
    CLASS
        NAME "Relief Map"
    END # CLASS
END # LAYER
LAYER
    NAME "Baylands"
    DATA "vector\mbypsfby"
    STATUS DEFAULT
    TYPE POLYGON
    CLASS
        NAME "Deep Bay"
        EXPRESSION ('[ENTITYID]' = 'A00000000000')
        COLOR 51 51 255
    END # CLASS
    CLASS
        NAME "Shallow Bay"
        EXPRESSION ('[ENTITYID]' = 'A10000000000' OR '[ENTITYID]' = 
'A10000000090' OR '[ENTITYID]' = 'B4ST00000000')
        COLOR 102 102 204
    END # CLASS
END # LAYER
END # FILE

--------------- cut here ----------------------------
I don't understand grid files very well, so here's the listing of the 
grid directory and its children in case something is wrong there (though

I don't think so, since the grid itself displays ok):
-------- cut here -----------------
C:/Inetpub/wwwroot/sfbay/data/EcoAtlas/grid:
info
sfbayshr
sfbayshr.met
sfbayshrw
sfbr-sr-dbdesc.txt

C:/Inetpub/wwwroot/sfbay/data/EcoAtlas/grid/info:
arc.dir
arc0000.dat
arc0000.nit
arc0001.dat
arc0001.nit
arc0002.dat
arc0002.nit
arc0002r.001

C:/Inetpub/wwwroot/sfbay/data/EcoAtlas/grid/sfbayshr:
dblbnd.adf
hdr.adf
log
prj.adf
sta.adf
vat.adf
w001001.adf
w001001x.adf
---------- cut here ----------------

_______________________________________________
Mapserver-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Mapserver-users at lists.gis.umn.edu">Mapserver-users at lists.gis.umn.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.gis.umn.edu/mailman/listinfo/mapserver-users">http://lists.gis.umn.edu/mailman/listinfo/mapserver-users</a>
  </pre>
</blockquote>
<br>
</body>
</html>

--------------040508010700000907040305--




More information about the mapserver-users mailing list