[ms4w-users] Mapscript code to color polygons
Jeff McKenna
jmckenna at dmsolutions.ca
Mon May 15 13:05:11 EDT 2006
I would try this question on the MapServer list
(http://mapserver.gis.umn.edu/community/mailinglists/mapserver-users/).
The MS4W list is used for configuration issues, plus you'll find more
developers hang out on that list, to give you a hand.
jeff
David Laird wrote:
> Hi!
> I want to assign different colors to European countries based on data in
> a MySql database. In this example, if the SCORE_TAX number is less than
> 10, the country should appear yellow, if not it should appear blue. The
> database numbers are: France - 12, Germany - 3, UK - 9. So France
> should be blue, and Germany and the UK should be yellow. In fact, France
> is yellow while Germany and the UK are white, the color assigned by the
> mapfile.
>
> I've tried other variations on the code with no luck. Any suggestions
> would be greatly appreciated.
>
> Thanks.
>
> bagehot
>
> ======================================
> Here's the relevant code:
>
> $myquery = "SELECT * FROM scores";
> $myresult = mysql_query($myquery);
>
> for ($i = 0; $i < 3; $i++)
> {
> $this_layer = $map->getLayerByName('Europe');
> $class = $this_layer-> getClass($i);
> $style = $class->getStyle(0);
>
> while ($myrow = mysql_fetch_array($myresult))
> {
> if ($myrow['SCORE_TAX'] < 10)
> {
> //yellow
> $int_red = 255;
> $int_green = 255;
> $int_blue = 0;
> }
> else
> {
> //blue
> $int_red = 0;
> $int_green = 0;
> $int_blue = 255;
> }
>
> $style->color->setRGB($int_red,$int_green,$int_blue);
> }
> }
>
> =======================================
> The relevant mapfile data is:
>
> LAYER
> NAME "Europe"
> TYPE POLYGON
> STATUS ON
> DATA "europe1"
>
> CLASS
> EXPRESSION ('[FIRST_FIPS]' eq 'FR')
> NAME "France"
> STYLE
> COLOR 255 255 255
> END
> END
>
> CLASS
> EXPRESSION ('[FIRST_FIPS]' eq 'GM')
> NAME "Germany"
> STYLE
> COLOR 255 255 255
> END
> END
> CLASS
> EXPRESSION ('[FIRST_FIPS]' eq 'UK')
> NAME "UK"
> STYLE
> COLOR 255 255 255
> END
> END
> ======================================
--
Jeff McKenna
DM Solutions Group Inc.
http://www.dmsolutions.ca
More information about the ms4w-users
mailing list