[ms4w-users] Mapscript code to color polygons

David Laird bagehot43 at hotmail.com
Sun May 14 08:57:22 EDT 2006


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
======================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/ms4w-users/attachments/20060514/baac5367/attachment.html


More information about the ms4w-users mailing list