FAQs
View entire FAQ in full Up to table of contentsMap Output
How do I set line width in my maps?
How do I set line width in my maps?
You must set the symbol for the LAYER to be 'circle' and then you can set the symbol SIZE to be the width you want. A 'circle' symbol can be defined as:
SYMBOL NAME 'circle' TYPE ELLIPSE FILLED TRUE POINTS 1 1 END END
This FAQ applies to: MapServer 4.6, MapServer 4.8
Why do my JPEG input images not look right via MapServer?
I have a nice 24bit color jpeg image but when I add it as a raster layer in MapServer, the colors looks crappy! Why is that?
The default output format for MapServer is 8bit pseudo-colored PNG or GIF. Inherently there will be some color degredation in converting a 24bit image (16 million colors) image into 8bit (256 colors).
But in order to ensure fast rendering MapServer uses quite a simple method to do the transformation, converting pixels to the nearest color in a 175 color colorcube. This will usually result in blotchy color in a fairly smoothly varying image.
- Solutions include:
- Select 24bit output. This might be as easy as "IMAGETYPE JPEG" in your MAP section.
- Enable dithering (PROCESSING "DITHER=YES") to produce a better color appearance.
- Preprocess your image to 8bit before using it in MapServer with an external application like the GDAL rgb2pct.py script.
For more information review the Raster HOWTO document.
This FAQ applies to: MapServer 4.6, MapServer 4.8
Which image format should I use?
When generating maps to be displayed on websites, which image output format should I use?
Although Mapscript can generate the map in any desired image format it sufficient to only consider the three most prevalent ones: JPEG, PNG, and GIF.
JPEG is an image format that uses a lossy compression algorithm to reduce an image's file size and is mostly used when loss of detail through compression is either not noticeable or negligible, as in most photos. Maps on the other hand mainly consist of fine lines and areas solidly filled in one colour, which is something JPEG is not known for displaying very well. In addition, maps, unless they include some aerial or satellite imagery, generally only use very few different colours. JPEG with its 24bit colour depth capable of displaying around 16.7 million colours is simple not suitable for this purpose. GIF and PNG however use an indexed colour palette which can be optimized for any number (up to 256) of colours which makes them the perfect solution for icons, logos, charts or maps. The following comparison (generated file sizes only; not file generation duration) will therefore only include these two file formats:
GIF vs. PNG vs. PNG24 Generated Map File Sizes
| GIF | PNG | PNG24 | |
|---|---|---|---|
| Vector Data only | 59kb | 26kb | 69kb |
| Vector Data & Satellite Image coloured | 156kb | 182kb | 573kb |
| Vector Data & Satellite Image monochrome | 142kb | 134kb | 492kb |
(results based on an average 630x396 map with various colours, symbols, labels/annotations etc.)
Although GIF shows a quantitative as well as qualitative advantage over PNG when generating maps that contain full coloured remote sensing imagery, PNG is the clear quantitative winner in terms of generated file sizes for maps with or without additional monochrome imagery and should therefore been the preferred image format. If the mapping application however can also display fullcolour aerial or satellite imagery, the output file format can be changed dynamically to either GIF or even PNG24 to achieve the highest possible image quality.
This FAQ applies to: MapServer 4.6, MapServer 4.8
Why doesn't PIL (Python Imaging Library) open my PNGs?
Why doesn't PIL (Python Imaging Library) open my PNGs?
PIL does not support interlaced PNGs at this time (no timetable on when it actually will either). To be able to read PNGs in PIL, they must not be interlaced. Modify your OUTPUTFORAT with a FORMATOPTION like so:
OUTPUTFORMAT NAME png DRIVER "GD/PNG" MIMETYPE "image/png" IMAGEMODE RGB EXTENSION "png" FORMATOPTION "INTERLACE=OFF" END
This FAQ applies to: MapServer 4.0, MapServer 4.2, MapServer 4.4, MapServer 4.6, MapServer 4.8
Symbols Look Poor in JPEG Output
When I render my symbols to an 8bit output (PNG, GIF) they look fine, but in 24bit jpeg output they look very blocky and gross.
In order to render some classes of symbols properly in 24bit output, such as symbols from true type fonts, it is necessary to force rendering to occur in RGBA. This can be accomplished by including the "TRANSPARENCY ALPHA" line in the layer definition. Don't use this unnecessarily as there is a performance penalty.
This problem also affects PNG24 output or any RGB output format. 8bit (PC256) or RGBA output types are already ok.
This FAQ applies to: MapServer 4.6, MapServer 4.8
How do I add a copyright notice on the corner of my map?
You can use an inline feature, with the FEATURE object, to make a point on your map. Use the TEXT parameter of the FEATURE object for the actual text of the notice, and a LABEL object to style the notice.
Example Layer
LAYER
NAME copyright
STATUS ON
TYPE annotation
TRANSFORM ll #set the image origin to be lower left
FEATURE
POINTS
60 -10 #set the offset from lower left position in pixels
END
TEXT "© xyz company 2006" #this is your displaying text
END
CLASS
LABEL #defines the font, colors etc. of the text
FONT "sans"
TYPE TRUETYPE
SIZE 8
BUFFER 1
COLOR 0 0 0
BACKGROUNDCOLOR 255 255 255
FORCE TRUE
END
END
UNITS PIXELS #sets the units for the feature object
END
How do I have a polygon that has both a fill and an outline with a width?
How do I have a polygon that has both a fill and an outline with a width? Whenever I put both a color (fill) and an outlinecolor with a width on a polygon within a single STYLE, the outline width isn't respected.
For historical reasons, width has two meanings within the context of filling polygons and stroke widths for the outline. If a polygon is filled, then the width defines the width of the symbol inside the filled polygon. In this event, the outline width is disregarded, and it is always set to 1. To acheive the effect of both a fill and an outline width, you need to use two styles in your class.
STYLE # solid fill COLOR 255 0 0 END STYLE # thick outline (could use a circle symbol with size too) OUTLINECOLOR 0 0 0 WIDTH 3 ANTIALIAS TRUE END
This FAQ applies to: MapServer 4.8, MapServer 4.10
How can I create simple antialiased line features?
How can I create simple antialiased line features, without resorting to cartoline symbols?
The easiest way to produce antialiased lines is to:
- use a 24-bit output image type (IMAGEMODE RGB (or RGBA))
- set TRANSPARENCY ALPHA in the layer using antialiased lines
- set ANTIALIAS TRUE in the STYLE element of the CLASS with antialiased lines
The following mapfile snippets enable antialiased county borders:
...
IMAGETYPE png24
...
OUTPUTFORMAT
NAME png24
DRIVER "GD/PNG"
MIMETYPE "image/png"
IMAGEMODE RGB
EXTENSION "png"
END
...
LAYER
NAME counties
TYPE line
STATUS default
DATA "bdry_counln2"
TRANSPARENCY alpha
SYMBOLSCALE 5000000
CLASS
STYLE
WIDTH 3
COLOR 1 1 1
ANTIALIAS true
END
END
END
...
Note that the bdry_counln2 shapefile referenced in the counties layer is a line shapefile. A polygon shapefile could be substituted with roughly the same results, though owing to the nature of shapefiles each border would be rendered twice and the resulting output line would likely appear to be slightly thicker. Alternatively, one could use a polygon shapefile, set TYPE to POLYGON, and use OUTLINECOLOR in place of COLOR in the STYLE element.
Note that you can tweak the combination of STYLE->WIDTH and SYMBOLSCALE to modify line widths in your output images.
Apparently cartoline symbols can be used to achieve fancier effects.
This FAQ applies to: MapServer 4.8, MapServer 4.10