[mapserver-users] how to use sld file with wms

Jeff McKenna jmckenna at gatewaygeomatics.com
Mon Dec 6 14:59:22 EST 2010


On 10-12-06 6:23 AM, Tonton wrote:
> hello i read in mapserver documentation that we can use SLD style
> definition in server side but i dont find how to .
>
> where to write in mapfile the sld_body in each layer or  in map object  ?
>
> i don't use mapscript or php request
>
> does the only way is to set it in the url request ? no sld_body or
> include ?

I'm not sure if it was implemented any other way.  There was discussions 
on this mailing list several years ago, but I don't know the outcome:

http://osgeo-org.1803224.n2.nabble.com/server-side-SLD-support-td1997798.html
http://osgeo-org.1803224.n2.nabble.com/server-side-SLD-support-td1998273.html

I have used PHP MapScript to apply SLDs on the server side, such as:

*******************************
<?php

// define variables
define( "MAPFILE", "D:/sld-test.map" );
define( "MODULE", "php_mapscript.dll" );

// load the mapscript module
if (!extension_loaded("MapScript")) dl(MODULE);

// open map
$oMap = ms_newMapObj( MAPFILE );

//get layer
$oLayer = $oMap->getLayerByName("country_bounds");

//apply SLD
$oLayer->applySLD('<StyledLayerDescriptor 
version="1.0.0"><NamedLayer><Name>country_bounds</Name><UserStyle><Title>xxx</Title><FeatureTypeStyle><Rule><Filter><PropertyIsEqualTo><PropertyName>NA3DESC</PropertyName><Literal>Africa</Literal></PropertyIsEqualTo></Filter><LineSymbolizer><Geometry><PropertyName>center-line</PropertyName></Geometry><Stroke><CssParameter 
name="stroke">#0000ff</CssParameter><CssParameter 
name="stroke-width">2.0</CssParameter></Stroke></LineSymbolizer></Rule></FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>');

// set image size
$oMap->setsize(400, 300);

// set image format
$oMap->selectoutputformat("png");

// draw map
$oImage = $oMap->draw();

// set header
header("Content-type: image/gif");

// output map
$url = $oImage->saveImage("");

?>
**************************************


-- 
Jeff McKenna
MapServer Consulting and Training Services
http://www.gatewaygeomatics.com/






More information about the mapserver-users mailing list