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

Burgholzer, Robert (DEQ) Robert.Burgholzer at deq.virginia.gov
Thu May 24 09:32:45 PDT 2012


Ahhh, here is the solution (not found anywhere on the interwebs tht I could discern - hope this helps someone in the future).

In order to get the classindex change to be reflected in the map output, you need to use the "set()" method of the shape.  In other words, I change:
   $shape->classIndex = $c;
to 
   $shape->set('classindex', $c);  

Note that I also made the mistake of spelling the object property with a capital I, "classIndex" instead of "classindex".  Interestingly enough, when doing the direct setting method $shape->classindex = xx, no problems occur, but if you call the "set"  method with a property name that does not exist, a fatal error will ensue.

Cheers!
r.b.

-----Original Message-----
From: mapserver-users-bounces at lists.osgeo.org [mailto:mapserver-users-bounces at lists.osgeo.org] On Behalf Of Burgholzer, Robert (DEQ)
Sent: Thursday, May 24, 2012 11:54 AM
To: mapserver-users at lists.osgeo.org
Subject: [mapserver-users] Setting Classes for Dynamic Points (Rainfall Data)

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>
_______________________________________________
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