SVG Won't Color?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, 
  
  I have the code as in the following, and I am trying to colorize the map. The SVG File is located here: http://upload.wikimedia.org/wikipedia/commons/5/5f/USA_Counties_with_FIPS_and_names.svg. Looks like when I tried to modify the contents of the line, it does not seem to take into affect. Thus, my map does not get colorized. Do I have to save the file here? Or, is there something else I have missed here? 

<?php

//We are outputting an SVG
header("Content-type: image/svg+xml");

$array= array();
$array2= array();
$array3= array();
$array4= array();

#Map Colors
$colors_array= array("#F1EEF6","#D4B9DA","#C994C7","#DF65B0","#DD1C77","#980043");

 $file = file("unemployment09.csv");
 foreach ($file as $line) {
    $chars = preg_split("/,/", $line);
    $unemployment_rate = $chars[12];
    array_push($array,$unemployment_rate);   
  }

//Calculate the number of elements in array
$total_num = count($array);

#Load the Map
$ourFileName= "USA_Counties_with_FIPS_and_names.svg";
$fh = fopen($ourFileName, "r") or die("Can't open file");
$contents = fread($fh,filesize($ourFileName));
$lines2= file($ourFileName);

#Color the counties based on unemployment rate
for ($i=0;$i<$total_num;$i++){

  switch($array[$i]){
   
   case ($array[$i] > 10):
   $color = 5;
   break;   

   case ($array[$i] > 8):
   $color = 4;
   break;   
 
   case ($array[$i] > 6):
   $color = 3;
   break;   

   case ($array[$i] > 4):
   $color = 2;
   break;   

   case ($array[$i] > 2):
   $color = 1;
   break;   

   default:
   $color= 0;
   break; 

  }
  $color_class= $colors_array[$color];
  array_push($array4,$color_class);
}
   
foreach ($lines2 as $line_num => $line2) {

  $line_add_one = $line_num + 1;
  if(preg_match("/<path/",$line2)) {
   
   $rest = substr($lines2[$line_add_one],0,-3);
   $colors_style = ";color:" . $array4[$line_add_one];
   $rest = $rest . $colors_style . "\""; 
  }
  array_push($array3,$lines2[$line_add_one]);   
}

echo $contents;
fclose($fh); 

?>

Thanks for your help.

Alice
 		 	   		  
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/196390706/direct/01/

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux