[mapserver-users] layer classification with MapScript

Mr. Puneet Kishor punk.kish at gmail.com
Sun Aug 28 18:51:33 EDT 2011


Hi Brent,

Thanks for the hand-holding. I got the solution for this first part of the challenge using MapScript; no Mapfile required at all. I will write up a more generalized article on this for the docs/wiki.


On Aug 28, 2011, at 10:19 AM, Brent Fraser wrote:

> Puneet,
> 
>  If you don't care about mapserver generating a legend graphic, you could use mapserver CGI's ability (no scripting required) to do attribute binding (get values from a feature's attribute values).  I've used a single class def of:
> 
>        CLASS
>            STYLE  # Line, Poly and Point outline
>                SYMBOL       [sSymbol]
>                OUTLINECOLOR [sOutlineColor]
>                COLOR        [sColor]
>                SIZE         [sSize]
>            END
>            TEXT ([Label])
>            LABEL
>                ANGLE AUTO
>                POSITION UR
>                COLOR [lColor]
>                OUTLINECOLOR [lOutlineColor]
>                TYPE truetype
>                FONT 'Arial'
>                SIZE [lSize]
>            END
>        END
> 
> where the data/connection accessed a view joining the feature table to a class table where the styling values were defined.  And you need 3 layer defs, one for points, lines and polygons.   But using this technique, there is no way to get a legend graphic show all the classes.
> 
>  So in your PHP code you would need to do a  generic database query to get a set of classes, then for each row create a class object and add it to the layer object.  Then have mapscript process the features and render a map image by doing a draw() (and a legend graphic by doing a drawLegend()).  Or, as others have suggested,  you could pass an SLD to mapserver via WMS and request a legend graphic.
> 
> Best Regards,
> Brent Fraser
> 
> 
> On 8/27/2011 5:02 PM, Mr. Puneet Kishor wrote:
>> I have a layer classification issue. I want to do something along the lines of (semi-pseudocode ahead) --
>> 
>>     $layerObj->{data} = 'the_geom FROM (SELECT gid, the_geom, class_name, class_color FROM table) t USING UNIQUE gid';
>>     $layerObj->{classitem} = 'class_name';
>> 
>>     while (my $row in $layerObj->{data}) {
>>         create class with 'name = class_name', 'expression = class_name', 'color = class_color'
>>     }
>> 
>> How do I iterate over the rows retrieved from the table in order to create classes? I don't see any obvious reference to a db result set._______________________________________________
>> mapserver-users mailing list
>> mapserver-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapserver-users
>> 
> 



More information about the mapserver-users mailing list