[Mapserver-users] classifications on the fly

Vladimir Guzmán bigfoot at main-task.com
Wed Feb 18 14:12:44 EST 2004


Hi Bart.
One can du classificatios on the air using mapscript.
Actually I make them using phpmapscript, something like this:
1. In the .map file, create a layer with the basic information 
(connection type, type, status, maxscale, etc.)
2. Then query the database for the data wanted to draw, and the joins 
with the spatial data (can be oracle spatial, postgis or myGIS)
3. Get the layer object
4. Alter the data attribute of the layer, with the desired query
5. Select max and min values, and the desired interval
6. Create classes on the layer, with defined colours.

I've got an example, that may be of help:

<?
$map = ms_newMapObj("sspd.map");
$layer=$map->getLayerByName("reporte");
$strQueryOracleSpatial="SELECT ORA_GEOMETRY, VALOR, NOMBRE FROM 
($strQueryOracle)";
$layer->set("data", $strQueryOracleSpatial);
$numClases=10;
$qid=db_oracle_query("SELECT MAX(VALOR) as max, MIN(VALOR) as min, 
(MAX(VALOR)-MIN(VALOR))/$numClases as intervalo FROM ($strQueryOracle)");
$resultado=db_oracle_fetch_array($qid);
$intervalo=$resultado["INTERVALO"];
$color=0;
$intervalo_color=255/$numClases;
$layer->set("classitem","VALOR");
$layer->set("labelitem","NOMBRE");
$inferior=$intervalo;
for($i=0;$i<$numClases;$i++){
    $superior=$inferior+$intervalo;
    $color=$color+$intervalo_color;
    $color_hexa=sprintf("#%02x%02x%02x", 255, 255-$color, 255-$color);
    if($inferior==$intervalo) $inferior=0;
    $expresion = "([VALOR] >= " . $inferior . " AND [VALOR] <= " . 
$superior . ")";
    $class = ms_newClassObj($layer);
    $class->setExpression($expresion);
    $class->set("name",$inferior . "-" . $superior);
        $label=$class->label;
         $style = ms_newStyleObj($class);
         $style->color->setRGB(255, 255-$color, 255-$color);
         $style->outlinecolor->setRGB(204, 204, 204);

    $inferior=$superior;
}
$mapa = $map->draw();
$mapa_url = $mapa->saveWebImage(1, 0, 0, 50);
?>

This example draws the map in a scale of red color.

Hope that helps.

Vladimir Ilich Guzmán R.
------------------------
http://www.maintask.com 



Bart van den Eijnden wrote:

> Hi list,
>
> can Mapserver do classifications on the fly, e.g. equal range, equal 
> count, unique value etc.? If not, does anybody know of another open 
> source tool/product to do this, or perhaps there are plans to support 
> it in Mapserver/Mapscript? This would allow a user to classify data as 
> they see fit.
>
> The result of a classification "request" could be an SLD document 
> (which after optionally being changed by a user with regard to 
> symbology, could be used in combination with a GetMap request to see 
> the result of the classification). But I can't seem to find a 
> specification for "classification services" in the OGC world, anybody 
> know of any relevant specification?
>
> Thanks in advance.
>
> Best regards,
> Bart
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>
>



More information about the mapserver-users mailing list