[OpenLayers-Users] dynamic sld-files with dynamic class sizes

Rahn Hanno (rahn) rahn at zhaw.ch
Mon Sep 29 08:01:48 EDT 2008


Hello List,

 

I try to realise something like a dynamic sld file. I want to get the map in different colors for different indicators.

The data for the indicators is in an database. The colorization should be in quantities. For example regions with a value between 1-10 should be red, with a value between  11-20 should be green. This is a <Propertyisbetween> Filter in SLD.

Now I try to make the number of classes for the colorization dynamic. The user can choose the number of classes at the beginning.

I realise this with the SLD_Body parameter. Here you can see my example-file:

 

.....

$classifiedPHP = 'datenwert';

                                    $indikator = 2;

                                    //echo "$classifiedPHP";

 

                                    $query = 'SELECT min('.$classifiedPHP.'),max('.$classifiedPHP.') FROM zeitreihen_daten,gines_geo where indikator='.$indikator.' and gines_geo.bfs=zeitreihen_daten.raumeinheit';

                                    //$query = 'SELECT min('.$classifiedPHP.'),max('.$classifiedPHP.') FROM gines_geo';

 

                                    //echo "$query";

                                    $result = pg_query($db,$query);

 

                                    // grössten/kleinsten Wert in Array schreiben

                                    while ($row = pg_fetch_row($result)) {

                                               $min = $row[0];

                                               $max = $row[1];

                                               //echo "$min $max";

                                    }

                        ?>

 

              <script defer="defer" type="text/javascript">

 

                        //-------------Attribut nach welchem Klassifiziert werden soll--------------------------------------

 

                                   var indikator = "<?php echo $indikator; ?>";

                                   var classified = 'daten';

                                   var klassen =7;

 

                        //-------------Einteilung der Klassengrenzen, welche in verwendet werden---

 

                                   var classMin = <?php echo $min; ?>;

                                   var classMax = <?php echo $max; ?>;

 

                                   var schritt = (classMax-classMin)/klassen;

 

                        //          var class1LB = classMin;

                                   var class1UB = classMin + schritt;

 

                                   var farbe = '#FF0000';

 

                        //-------------Definition des Styles-----------------------------------------------------------------

 

                                   var sld_spec = '<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">';

                                   

var sld_layer_pre ='<NamedLayer> <Name>gemeinden</Name> <UserStyle> <Title> gemsee </Title> <FeatureTypeStyle>';

 

                                   var sld_layer_post ='</FeatureTypeStyle> </UserStyle> </NamedLayer> </StyledLayerDescriptor>';

 

 

 

var sld_first = '<Rule> <Name>Classes</Name> <Filter> <AND> <PropertyIsEqualTo> <PropertyName>indikator</PropertyName> <Literal>'+ indikator +'</Literal> </PropertyIsEqualTo> <PropertyIsBetween><PropertyName>'+ classified +'</PropertyName> <LowerBoundary> <Literal>';

                                   

var sld_mid1 =  '</Literal> </LowerBoundary> <UpperBoundary> <Literal>';

                                   var sld_mid2 =  '</Literal> </UpperBoundary> </PropertyIsBetween> </AND> </Filter> <PolygonSymbolizer> <Fill> <CssParameter name="fill">';

var sld_last =  '</CssParameter> <CssParameter name="fill-opacity">1.00</CssParameter> </Fill> <Stroke> <CssParameter name="stroke">#aa5500</CssParameter> </Stroke> </PolygonSymbolizer> </Rule>';

 

 

                                   var mysld =sld_spec + sld_layer_pre + sld_first + classMin + sld_mid1 + class1UB + sld_mid2 + farbe + sld_last;

 

 

                                   for (i=1; i<=klassen ;i++) {

 

 

                                   lbound = classMin + (i*schritt);

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

 

                                   farbe = farbe.substr(1,6);

                                   farbe=parseInt(farbe,16);

                                   farbe=farbe-10000;

                                   farbe=farbe.toString(16);

 

                                   farbe = '#'+farbe;

 

                                   mysld = mysld + sld_first + lbound + sld_mid1 + ubound + sld_mid2 + farbe + sld_last;

 

                                   }

 

                                   mysld = mysld + sld_layer_post;

 

.....

 

This works fine. 

I hope somebody can understand what I am doing there.

 

Now I have the problem of the number of the classes. If I use more than 7 classes (var klassen) there is an error. I know that the URL-String is too long for more than 7 classes, but I need another reason for this. Has somebody an idea to solve this problem? Perhaps I must use the original SLD File. But I don't know if I can give a variable at a URL Parameter or so to the SLD file in the SLD option like this for example.

 

wmsX.mergeNewParams({ SLD : http://localhost/SLD/mysld.sld?var1=15&var2=10 });

 

Thanks a lot for your help.

Greetings

Hanno

 

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

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/20080929/ad5e992f/attachment.html


More information about the Users mailing list