[OpenLayers-Users] dynamic sld/php file from UMN mapserver and Openlayers

Rahn Hanno (rahn) rahn at zhaw.ch
Mon Oct 6 05:18:29 EDT 2008


Hi List,

 

I try to realise a dynamiv sld-file. Now I make a php file. The output of this file is the sld description.

 

I think the output is ok.

Here are the code of the file.

 

<?php

 

$jahr=$HTTP_GET_VARS["jahr"];

$indikator=$HTTP_GET_VARS["indikator"];

$klassen=$HTTP_GET_VARS["klassen"];

 

                // Öffnen der PostgreSQL DB

                        require("DB_Config.php");

 

 

                        // min und max für Klassengrenzen abfragen

                        require_once("minmax.php");

 

                  $mm = minMax($indikator,$jahr,$db);

                  $min = $mm[0];

                  $max = $mm[1];

 

$classified = 'daten';

$classMin = $min;

$classMax = $max;

 

                   $sld_spec = '&lt;StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml"xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"&gt;';

                   $sld_layer_pre ='&lt;NamedLayer&gt;&lt;Name&gt;gemeinden&lt;/Name&gt;&lt;UserStyle&gt;&lt;Title&gt; gemsee &lt;/Title&gt; &lt;FeatureTypeStyle&gt;';

 

                   $sld_layer_post ='&lt;/FeatureTypeStyle&gt; &lt;/UserStyle&gt; &lt;/NamedLayer&gt; &lt;/StyledLayerDescriptor&gt;';

 

                   $sld_first = '&lt;Rule&gt;&lt;Name&gt;';

                   $sld_mid0 =  '&lt;/Name&gt; &lt;Filter&gt; &lt;AND&gt; &lt;PropertyIsEqualTo&gt; &lt;PropertyName&gt;indikator&lt;/PropertyName&gt; &lt;Literal&gt;'.$indikator.'&lt;/Literal&gt; &lt;/PropertyIsEqualTo&gt; &lt;PropertyIsEqualTo&gt; &lt;PropertyName&gt;jahr&lt;/PropertyName&gt; &lt;Literal&gt;'.$jahr.'&lt;/Literal&gt; &lt;/PropertyIsEqualTo&gt; &lt;PropertyIsBetween&gt;&lt;PropertyName&gt;'.$classified.'&lt;/PropertyName&gt; &lt;LowerBoundary&gt; &lt;Literal&gt;';

                   $sld_mid1 =  '&lt;/Literal&gt; &lt;/LowerBoundary&gt; &lt;UpperBoundary&gt; &lt;Literal&gt;';

                   $sld_mid2 =  '&lt;/Literal&gt; &lt;/UpperBoundary&gt; &lt;/PropertyIsBetween&gt; &lt;/AND&gt; &lt;/Filter&gt; &lt;PolygonSymbolizer&gt; &lt;Fill&gt; &lt;CssParameter name="fill"&gt;';

                   $sld_last =  '&lt;/CssParameter&gt; &lt;CssParameter name="fill-opacity"&gt;1.00&lt;/CssParameter&gt; &lt;/Fill&gt; &lt;Stroke&gt; &lt;CssParameter name="stroke"&gt;#aa5500&lt;/CssParameter&gt; &lt;/Stroke&gt; &lt;/PolygonSymbolizer&gt; &lt;/Rule&gt;';

 

                   $mysld =$sld_spec.$sld_layer_pre;

 

                   $schritt = ($classMax-$classMin)/$klassen;

                   $farbe = '#FF0000';

                   $first = true;

                  for ($i=0; $i<$klassen ;$i++) {

 

                        $lbound = $classMin + ($i*$schritt);

                        $ubound = $classMin + (($i+1)*$schritt);

 

                        $lb = round($lbound,2);

                        $ub = round($ubound,2);

 

                        $name1=$lb;

                        $name2=$ub;

                        $name = $name1 . '  ' . $name2;

                        if (!$first) {

 

                        $farbe2 = hexdec($farbe);

                        $farbe2 = $farbe2-11000;

                        $farbe = dechex($farbe2);

                        $farbe = "#".$farbe;

                        }

 

                        $mysld = $mysld.$sld_first.$name.$sld_mid0.$lbound.$sld_mid1.$ubound.$sld_mid2.$farbe.$sld_last;

                        $first = false;

 

                        }

 

                  $mysld = $mysld.$sld_layer_post;

 

                  echo "$mysld";

?>

 

If I copy the output in an file and save it as *.sld. All works great with UMN Mapserver with the GetMap Request.

 

http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/Apache/htdocs/Maps/Kanton_ZH_Gemeinden.map&SLD=http://localhost/ausgabe.sld&VERSION=1.1.0&REQUEST=GetMap&SERVICE=WMS&LAYERS=gemeinden&SRS=EPSG:4149&BBOX=640866.343701,215800.843324,745288.926741,291429.980390&WIDTH=914&HEIGHT=855&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage

 

 

 

Now I will use it in OpenLayers. For this I use the following:

 

var map = new OpenLayers.Map('map',options);

 

                  var wms = new OpenLayers.Layer.WMS("Gemeinden","http://localhost/cgi-bin/mapserv.exe?", {map:"../htdocs/Maps/Kanton_ZH_Gemeinden.map",layers:"gemeinden",format:"image/png",EXCEPTIONS:"application/vnd.ogc.se_inimage"},{singleTile: true} );

                  map.addLayer(wms);

 

                  wms.mergeNewParams({ SLD : "mysld.php?jahr=2004&indikator=1&klassen=4" });

 

                  map.zoomToMaxExtent();

 

But it doesn't work. If I try to use the mysld.php file in the GetMap Request it will not work, too.

 

I have no idea why it is so. Perhaps somebody can help me to find the mistake? Thank you a lot for this.

 

Greetings 

Hanno Rahn

 

 

------------------------------------------

Hanno Rahn, Dipl.-Ing. (FH) Geoinformatik

ZHAW Zürcher Hochschule für Angewandte Wissenschaften Umwelt und Natürliche Ressourcen 

Fachstelle Geoinformatik 

Grüental, Postfach CH-8820 Wädenswil 

Tel +41 (0)58 934 5592

Fax +41 (0)58 934 5580 

hanno.rahn at zhaw.ch 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081006/298dd0e2/attachment.html


More information about the Users mailing list