[mapserver-users] Setting Classes for Dynamic Points (Rainfall Data)

Burgholzer, Robert (DEQ) Robert.Burgholzer at deq.virginia.gov
Thu May 24 08:54:07 PDT 2012


I am working with some dynamic rainfall point data, and trying to display it with a graduated color ramp to indicate total rainfall.  The ramp is based on the quartiles of the entire data set, hence the need to dynamically assign not only the points but also the classIndex.  I have attempted with the following code which SUCCEEDS in drawing the points, but FAILS to change their classification (they are all the same color).  The gist of my code is to set the class of each shape when setting the $shape->classIndex = whatever the quartile is (I have 4 classes defined in my ramp - mapfile CLASS excerpt follows code).

Any insight would be most helpful.  Thanks!


<CODE>
foreach($qresult as $row) {
         $shape = ms_newShapeObj(MS_SHAPE_POINT);
         if ($row['total_precip_in'] > $max_precip) {
            $max_precip = $row['total_precip_in'];
         }
         $p = $row['total_precip_in'];
         if ($p < $q25) {
            $c = 1;
         } else {
            if ($p < $q50) {
               $c = 2;
            } else {
               if ($p < $q75) {
                  $c = 3;
               } else {
                  $c = 4;
               }
            }
         }
         $this->logDebug("Adding: " . $row['x'] . "," . $row['y'] . " with Precip = $p and Class = $c <br>\n");
         $pt = ms_newPointObj();
         $pt->setXY($row['x'], $row['y'], 0.0);
         $line = ms_newLineObj();
         $line->add( $pt );
         $shape->add($line);
         $shape->classIndex = $c;
         $layer->addFeature( $shape );
         $i++;
      }
</CODE>

<MAPFILE EXCERPT>
  CLASS
      NAME "1st Quartile: 0.0 <= P <= 19.63"
      #EXPRESSION ( [globvalue] <= 19.63 )
      SYMBOL 'circle'
      SIZE 2
      COLOR 202 207 254
      BACKGROUNDCOLOR 202 207 254
      OUTLINECOLOR 202 207 254
   END
   CLASS
      NAME "2nd Quartile: 19.63 < P <= 22.64"
      #EXPRESSION ( [globvalue] > 19.63 and [globvalue] <= 22.64 )
      SYMBOL 'circle'
      SIZE 4
      COLOR 137 148 253
      BACKGROUNDCOLOR 137 148 253
      OUTLINECOLOR 137 148 253
   END
   CLASS
      NAME "3rd Quartile: 22.64 < P <= 25.6"
      #EXPRESSION ( [globvalue] > 22.64 and [globvalue] <= 25.6 )
      SYMBOL 'circle'
      SIZE 6
      COLOR 66 84 252
      BACKGROUNDCOLOR 66 84 252
      OUTLINECOLOR 66 84 252
   END
   CLASS
      NAME "4th Quartile: P > 25.6"
      #EXPRESSION ( [globvalue] > 25.6 )
      SYMBOL 'circle'
      SIZE 8
      COLOR 4 26 236
      BACKGROUNDCOLOR 4 26 236
      OUTLINECOLOR 4 26 236
   END
   CLASS
      NAME "No Data"
      SYMBOL 'circle'
      SIZE 2
      COLOR 96 160 248
      BACKGROUNDCOLOR 96 160 248
      OUTLINECOLOR 96 160 248
   END

</MAPFILE EXCERPT>



More information about the MapServer-users mailing list