AW: [mapserver-users] "Low-resolution" raster image problem when usingOpenlayers

Arnd Wippermann arnd.wippermann at web.de
Wed Jun 29 10:15:09 PDT 2011


Hi Ken,
 
Quote : "Interestingly, if I use the 'mapserv' executable directly in the
browser instead of using OpenLayers API, the image also renders correctly."
 
There could be no difference (OpenLayers.Layer.WMS or .MapServer), because
with OpenLayers you only create an url for an image tag (<img src="url">).
The response have to be the same as from the browser directly.
 
The difference could only be a result from different requests or the same
request to different servers.
 
Arnd
 
  _____  

Von: kensei3000 [mailto:kensei3000 at yahoo.com] 
Gesendet: Mittwoch, 29. Juni 2011 09:56
An: Arnd Wippermann
Cc: users at openlayers.org
Betreff: Re: AW: [mapserver-users] "Low-resolution" raster image problem
when usingOpenlayers


Hi Arnd,


I checked the images properties of the tile images using ImageMagick.

tile_topleft_remote.png has image type "Palette" (8-bit)
tile_topleft_local.png has image type "TrueColor" (32-bit)

The results I got seem to correlate with your findings.
Indeed, it appears that the image rendering between my local pc and the
server are different.

The map files are exactly same since I sync them in both computers.     


The MapServer versions, however, are different. Here's what I got:

LOCAL:
MapServer version 6.0.0 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG SUPPORTS=PROJ
SUPPORTS=AGG SUPPORTS=CAIRO SUPPORTS=FREETYPE SUPPORTS=ICONV
SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER
SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI
SUPPORTS=THREADS SUPPORTS=GEOS INPUT=POSTGIS INPUT=OGR INPUT=GDAL
INPUT=SHAPEFILE


REMOTE:
MapServer version 5.6.1 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP
OUTPUT=SWF OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE
SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT
SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=FASTCGI
SUPPORTS=THREADS SUPPORTS=GEOS INPUT=EPPL7 INPUT=POSTGIS INPUT=OGR
INPUT=GDAL INPUT=SHAPEFILE


The MapServer executable in the remote server is an older version (5.6.1)
than the one in my pc (6.0.0). I edited the map files and images in my local
pc, then synced them to the server, so there may be an incompatibility. I
checked the Mapserver Migration Guide
(http://mapserver.org/de/MIGRATION_GUIDE.html) and my guess was that the
default OUTPUTFORMAT specifications of both versions could be different. I
did not specify an explicit OUTPUTFORMAT in my map file.


I created another test. This time I explicitly defined the OUTPUTFORMAT with
the following lines added to the map file in the remote server:


 OUTPUTFORMAT

    NAME jpeg
    DRIVER "AGG/JPEG"
    MIMETYPE "image/jpeg"
    IMAGEMODE RGB
    EXTENSION "jpg"
  END

The result was that the output image generated by the remote server rendered
in TrueColor, similar to the output image in my local pc. Problem appears to
be fixed.


My guess right now is that the  IMAGEMODE parameter above was somehow set to
PC256 (i.e. 8-bit color palette) by default.


Interestingly, if I use the 'mapserv' executable directly in the browser
instead of using OpenLayers API, the image also renders correctly.
EXAMPLE: 
http://remotehost/cgi-bin/mapserv?map=/opt/maps/sandbox/mapserver_openlayers
_if/sample.map&mode=map



Above 'sample.map' did not have the OUTPUTFORMAT object explicitly defined. 


In another test I ran using the original 'sample.map' (i.e. no OUTPUTFORMAT
object), I edited the OpenLayers code in the remote server:


//sample.html


FROM:
    17             layer = new OpenLayers.Layer.MapServer("World Map", 

TO:
    17            layer = new OpenLayers.Layer.WMS("World Map", 



I used the generic 'WMS' layer instead of the 'MapServer' layer. And the
result was that the output image rendered correctly. I am not yet sure why. 


I might need to run additional tests to confirm my findings.


Thanks for your help in pointing out the discrepancies in the images and in
MapServer. :)

Ken
  

  _____  

From: Arnd Wippermann <arnd.wippermann at web.de>
To: 'kensei3000' <kensei3000 at yahoo.com>
Cc: users at openlayers.org
Sent: Wednesday, June 29, 2011 2:28 AM
Subject: AW: [mapserver-users] "Low-resolution" raster image problem when
usingOpenlayers


use some image viewer to get information of your images.
 
tile_topleft_remote.png is a 8bit image (256 color image), where only 45
colors used.
 
tile_topleft_local.png is a 24bit image (16,7 Mill. colors), where 13274
colors used.
 
The requests ask for map_imagetype=png. So it seems, that your mapfiles are
different, because the response of the servers delivers a different image
for the same imagetype. Or do you use different MapServer versions?
 
The problem has to be an issue with MapServer and not with OpenLayers.
 
Arnd
 
  _____  

Von: kensei3000 [mailto:kensei3000 at yahoo.com] 
Gesendet: Dienstag, 28. Juni 2011 04:32
An: Arnd Wippermann
Cc: users at openlayers.org
Betreff: Re: AW: [mapserver-users] "Low-resolution" raster image problem
when usingOpenlayers


Hi Arnd,


Thanks a lot for the tip. I copied the image url of the top-left most tile
for both local pc and remote server tests.
Here is what I got:


Local:
http://localhost/cgi-bin/mapserv?map=%2Fopt%2Fmaps%2Fsandbox%2Fmapserver_ope
nlayers_if%2Fsample.map&layers=sample_raster&mode=map&map_imagetype=png&mape
xt=-90+0+0+90&imgext=-90+0+0+90&map_size=256+256&imgx=128&imgy=128&imgxy=256
+256


Remote:
http://remotehost/cgi-bin/mapserv?map=%2Fopt%2Fmaps%2Fsandbox%2Fmapserver_op
enlayers_if%2Fsample.map&layers=sample_raster&mode=map&map_imagetype=png&map
ext=-180+-90+0+90&imgext=-180+-90+0+90&map_size=256+256&imgx=128&imgy=128&im
gxy=256+256


The only significant difference of the two urls appear to be the 'mapext'
and 'imgext' parameters. When I checked the resulting images after inputting
the urls in the browser, I noticed that the tile images had different sizes
and positions. I believe this was due to the said parameters. I tried
changing the 'mapext' and 'imagext' parameters of the server test url to
match that of the local test url, and indeed the size and position of the
remote server tile image changed. However, I am still unable to figure out
what causes the color distortion or "downsampling" of the image in the
remote server.


For further reference, I've attached the tile images I got using the above
urls.


Here is the openlayers code I used. It is the same for both local and remote
server tests except for the host in line 18. 


//sample.html


     1 <html xmlns="http://www.w3.org/1999/xhtml">
     2  <head>
     3    <style type="text/css">
     4        #map {
     5            width: 1024px;
     6            height: 768px;
     7            border: 1px solid black;
     8        }
     9    </style>
    10    <script
src="http://openlayers.org/dev/lib/OpenLayers.js"></script>
    11    <script type="text/javascript">
    12        <!--
    13        var map, layer;
    14 
    15        function init(){
    16            map = new OpenLayers.Map( 'map' );
    17            layer = new OpenLayers.Layer.MapServer("World Map", 
    18                    "http://localhost/cgi-bin/mapserv",
    19                    {map:
'/opt/maps/sandbox/mapserver_openlayers_if/sample.map', layers:
'sample_raster'});
    20            map.addLayer(layer);
    21            map.zoomToMaxExtent();
    22        }
    23        // -->
    24    </script>
    25  </head>
    26  <body onload="init()">
    27    <div id="map"></div>
    28  </body>
    29 </html>


And below is the common .map file I created with the help of the Quantum GIS
Mapserver Export tool.
The raster image has an associated World file (.wld) for georeferencing.


     1 # Map file created from QGIS project file
/var/maps/sandbox/mapserver_openlayers_if/sample.qgs
     2 # Edit this file to customize for your map interface
     3 # (Created with PyQgis MapServer Export plugin)
     4 MAP
     5  NAME "QGIS-MAP"
     6  # Map image size
     7  SIZE 8180 4930
     8  UNITS meters
     9 
    10  EXTENT -86.515507 -50.290979 88.076495 48.225271
    11  PROJECTION
    12    'proj=longlat'
    13    'ellps=WGS84'
    14    'towgs84=0,0,0,0,0,0,0'
    15    'no_defs'
    16  END
    17 
    18  # Background color for the map canvas -- change as desired
    19  IMAGECOLOR 255 255 255
    20  IMAGEQUALITY 95
    21  IMAGETYPE jpeg
    22 
    23  # Legend
    24  LEGEND
    25      IMAGECOLOR 255 255 255
    26    STATUS ON
    27    KEYSIZE 18 12
    28    LABEL
    29      TYPE BITMAP
    30      SIZE MEDIUM
    31      COLOR 0 0 89
    32    END
    33  END
    34 
    35  # Web interface definition. Only the template parameter
    36  # is required to display a map. See MapServer documentation
    37  WEB
    38    # Set IMAGEPATH to the path where MapServer should
    39    # write its output.
    40    IMAGEPATH '/tmp/'
    41 
    42    # Set IMAGEURL to the url that points to IMAGEPATH
    43    # as defined in your web server configuration
    44    IMAGEURL '/tmp/'
    45 
    46    #Scale range at which web interface will operate
    47    # Template and header/footer settings
    48    # Only the template parameter is required to display a map. See
MapServer documentation
    49    TEMPLATE 'fooOnlyForWMSGetFeatureInfo'
    50  END
    51 
    52  LAYER
    53    NAME 'sample_raster'
    54    TYPE RASTER
    55    DUMP true
    56    TEMPLATE fooOnlyForWMSGetFeatureInfo
    57  EXTENT -86.515507 -50.290979 88.076495 48.225271
    58    DATA 'sec_field.jpg'
    59    STATUS DEFAULT
    60    TRANSPARENCY 100
    61    PROJECTION
    62    'proj=longlat'
    63    'ellps=WGS84'
    64    'towgs84=0,0,0,0,0,0,0'
    65    'no_defs'
    66    END
    67  END
    68 
    69 END


Hope you could provide further assistance.


Ken



  _____  

From: Arnd Wippermann <arnd.wippermann at web.de>
To: 'kensei3000' <kensei3000 at yahoo.com>
Cc: users at openlayers.org
Sent: Tuesday, June 28, 2011 1:53 AM
Subject: AW: [mapserver-users] "Low-resolution" raster image problem when
usingOpenlayers


hi,
 
if you do a right click on a tile to get the context menu, you should be
able to copy the url (if the tiles of your server is the most top of the
visible layers). Compare the different urls. If you load them in your
browser you should get a response for a single tile from your server.
 
Perhaps that gives you an idea, what goes wrong.
 
Arnd

  _____  

Von: mapserver-users-bounces at lists.osgeo.org
[mailto:mapserver-users-bounces at lists.osgeo.org] Im Auftrag von kensei3000
Gesendet: Montag, 27. Juni 2011 05:37
An: mapserver-users at lists.osgeo.org
Betreff: [mapserver-users] "Low-resolution" raster image problem when
usingOpenlayers


Hi!

I am trying to use MapServer as a WMS layer in Openlayers. I setup the
MapServer in our server machine, using my own PC as the test client. I
created a simple .map file in our server that contains one raster image.
Using the mapserver tool 'mapserv' in a URL string, I was able to load the
output map with full resolution correctly in a browser (Google Chrome).
However, when I tried to load the map using a simple Openlayers script
(HMTL) which I created on our server (accessible via browser), the map image
appeared to have a much lower-resolution (i.e. 256-colors only) and was
pixelized. Also, I could see white lines representing the tile edges of the
map. 

I did another test. This time, I installed MapServer in my own PC. I created
a .map file similar to the one I used in our server, with the same raster
image. I created a similar Openlayers script (HTML) in my own PC, but this
time it would call the MapServer from my own PC. I loaded the script using a
browser and the image displayed correctly with full resolution. 

Does anyone have an idea what the problem could be?

I would appreciate any help in this matter.

Thanks in advance! :)  




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20110629/be565e08/attachment.htm>


More information about the MapServer-users mailing list