MapServer SVG HOWTO - Version 4.5

Abstract

This document describes the procedures for implementing W3C compliant Scalable Vector Graphics (SVG) through the use of MapServer v4.5 (and later).

Last Updated: 2005-03-04

Revision History


Table of Contents

Introduction
Links to SVG-Related Information
Feature Types and SVG Support Status
Annotation Layers
Circle Layers
Line Layers
Point Layers
Polygon Layers
Raster Layers
Text Features
WMS Layers
Setting up a Mapfile for SVG Output
Testing your SVG Output
goSVG
Definition
Support for Specific goSVG Elements
Setting up a Mapfile for goSVG Output
Testing your goSVG Output
Sample goSVG File Produced by MapServer
About This Document
Revision History
Copyright Information
Disclaimer
Feedback

SVG (or Scalable Vector Graphics) is a standardized XML language for describing 2D graphics via vector graphics, text and raster graphics. As of version 4.5, MapServer can output SVG v1.1 maps. The following documentation is based on the World Wide Web Consortium's (W3C) Scalable Vector Graphics (SVG) 1.1 Specification.

This document assumes that you are already familiar with certain aspects of MapServer:

  • MapServer application development and setting up .map files.

The following items describe how line layers are handled by MapServer for SVG output:

  • Lines are converted to SVG 'polyline' elements.

  • The STYLE object's WIDTH parameter is used for SYMBOL 0 for line thickness.

  • The STYLE object's SIZE parameter is used for other symbols for line thickness.

  • All lines are drawn without symbols - only line thickness changes.

  • If a style uses a symbol and this symbol has a dashed style, it will be transformed into an SVG 'stroke-dasharray' element.

The following items describe how polygon layers are handled by MapServer for SVG output:

The following items describe how text features are handled by MapServer for SVG output:

  • The easiest way to test your SVG mapfile is to use MapServer CGI. For example, you might enter the following URL in a browser:

              http://127.0.0.1/cgi-bin/mapserv.exe?map=my/path/to/my-svg.map&mode=map&layers=layer1 layer2
            

  • You can also use PHP/Mapscript to test your SVG mapfile. Your php file might look like the following:

        <?php
    
          dl("php_mapscript_45.dll");
    
          $oMap = ms_newmapObj("my/path/to/my-svg.map");
    
          $img = $oMap->draw();
    
          header("Content-type: image/svg+xml");
    
          $url = $img->saveImage("");
    
        ?>      
            

An SVG file should be created in your IMAGEPATH directory. If you open the SVG file in a text editor you can see that it is an XML file. Below is a sample SVG file of a point layer with labels:

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat.dtd">
        <svg version="1.1" width="400" height="300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

        <!-- START LAYER popplace -->
        <ellipse cx="252" cy="130" rx="3" ry="3" fill="#000000"  />
        <ellipse cx="37" cy="227" rx="3" ry="3" fill="#000000"  />
        <ellipse cx="127" cy="239" rx="3" ry="3" fill="#000000"  />
        <ellipse cx="255" cy="282" rx="3" ry="3" fill="#000000"  />
        <polygon fill="#000000"   stroke-width="1"  points=" 267,263 270,263 271,260 272,263 275,263 273,265 274,268 271,266 268,268 269,265"/>
        <ellipse cx="288" cy="247" rx="3" ry="3" fill="#000000"  />
        <ellipse cx="313" cy="243" rx="3" ry="3" fill="#000000"  />
        <ellipse cx="328" cy="233" rx="3" ry="3" fill="#000000"  />
        <ellipse cx="331" cy="245" rx="3" ry="3" fill="#000000"  />
        <ellipse cx="366" cy="196" rx="3" ry="3" fill="#000000"  />
        <ellipse cx="161" cy="246" rx="3" ry="3" fill="#000000"  />
        <ellipse cx="92" cy="208" rx="3" ry="3" fill="#000000"  />
        <ellipse cx="40" cy="125" rx="3" ry="3" fill="#000000"  />
        <ellipse cx="108" cy="146" rx="3" ry="3" fill="#000000"  />
        <text  x="40" y="143" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Yellowknife</text>
        <text  x="43" y="121" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Whitehorse</text>
        <text  x="34" y="205" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Edmonton</text>
        <text  x="164" y="258" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Winnipeg</text>
        <text  x="316" y="190" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >St. John's</text>
        <text  x="334" y="258" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Halifax</text>
        <text  x="249" y="230" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Charlottetown</text>
        <text  x="241" y="242" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Quebec</text>
        <text  x="223" y="260" font-family="fritqat-italic" font-size="8pt"   fill="#ff0000" stroke="#ffffff" stroke-width="0.5"  >Ottawa</text>
        <text  x="210" y="279" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Toronto</text>
        <text  x="82" y="234" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Regina</text>
        <text  x="40" y="223" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Victoria</text>
        <text  x="214" y="125" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Iqaluit</text>
        </svg>    
    

You can now view the SVG file in a supported browser (see the official list of SVG implementations for possible SVG viewers). The Adobe Viewer plugin is very popular.

goSVG is now supported as a vector output format in MapServer 4.5 (and later).

This definition of goSVG was taken from http://www.svgopen.org/2004/papers/goSVGauthoringtool-1/:

goSVG is short for "G-XML over SVG" and "g-contents over SVG". This is a subset for mobiles specified within the G-XML (a Japanese Spatial Information Format which is an XML based protocol with the ability to describe, communicate and exchange Spatial Information and Electric Maps), and is a Spatial Information Exchanging format that determines the method to expand spatial information and connect to the backend system(G-XML standard mark format). goSVG is an expanded SVG Tiny profile (a Mobile profile of SVG 1.1. suited for cellular phones) that adds functions that are useful for Spatial Information Services( SVG Map Service ).

Refer to the section 'Testing your SVG Output' to generate and test your goSVG output. goSVG can be read by regular SVG viewers (they will just ignore the goSVG headers).

Below is a sample goSVG file of a point layer with labels:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat.dtd">
    <svg version="1.1" width="400" height="300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:au="http://www.svgmovile.jp/2004/kddip"  au:boundingBox="0 0 400 300">
    <title>DEMO</title>
    <metadata> 
    <rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:crs = "http://www.ogc.org/crs" xmlns:svg="http://wwww.w3.org/2000/svg"> 
    <rdf:Description> 
    <crs:CoordinateReferenceSystem svg:transform="matrix(0.000066,0.000000,0.000000,-0.000066,171.243002,253.040495)" 
    rdf:resource="http://www.opengis.net/gml/srs/epsg.xml#42304"/> 
    </rdf:Description> 
     </rdf:RDF> 
    <au:lbs protocol="maprequest">
    <au:zoomin th="20" xlink:href="."/>
    <au:zoomout th="40" xlink:href="."/>
    <au:scroll th="60" xlink:href="."/>
    </au:lbs>
    </metadata>

    <!-- START LAYER popplace -->
    <ellipse cx="252" cy="130" rx="3" ry="3" fill="#000000"  />
    <ellipse cx="37" cy="227" rx="3" ry="3" fill="#000000"  />
    <ellipse cx="127" cy="239" rx="3" ry="3" fill="#000000"  />
    <ellipse cx="255" cy="282" rx="3" ry="3" fill="#000000"  />
    <polygon fill="#000000"   stroke-width="1"  points=" 267,263 270,263 271,260 272,263 275,263 273,265 274,268 271,266 268,268 269,265"/>
    <ellipse cx="288" cy="247" rx="3" ry="3" fill="#000000"  />
    <ellipse cx="313" cy="243" rx="3" ry="3" fill="#000000"  />
    <ellipse cx="328" cy="233" rx="3" ry="3" fill="#000000"  />
    <ellipse cx="331" cy="245" rx="3" ry="3" fill="#000000"  />
    <ellipse cx="366" cy="196" rx="3" ry="3" fill="#000000"  />
    <ellipse cx="161" cy="246" rx="3" ry="3" fill="#000000"  />
    <ellipse cx="92" cy="208" rx="3" ry="3" fill="#000000"  />
    <ellipse cx="40" cy="125" rx="3" ry="3" fill="#000000"  />
    <ellipse cx="108" cy="146" rx="3" ry="3" fill="#000000"  />
    <text  x="40" y="143" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Yellowknife</text>
    <text  x="43" y="121" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Whitehorse</text>
    <text  x="34" y="205" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Edmonton</text>
    <text  x="164" y="258" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Winnipeg</text>
    <text  x="316" y="190" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >St. John's</text>
    <text  x="334" y="258" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Halifax</text>
    <text  x="249" y="230" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Charlottetown</text>
    <text  x="241" y="242" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Quebec</text>
    <text  x="223" y="260" font-family="fritqat-italic" font-size="8pt"   fill="#ff0000" stroke="#ffffff" stroke-width="0.5"  >Ottawa</text>
    <text  x="210" y="279" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Toronto</text>
    <text  x="82" y="234" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Regina</text>
    <text  x="40" y="223" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Victoria</text>
    <text  x="214" y="125" font-family="fritqat" font-size="8pt"   fill="#000000" stroke="#ffffff" stroke-width="0.5"  >Iqaluit</text>
    </svg>      
      

The numbering is in parallel with the revision control system. Missing numbers indicate minor maintenance revision updates.

Revision History
Revision Number: 1.0Date: 2005-03-04Author: Jeff McKenna
created initial version