[mapguide-users] Error with geometry of type MultiCurveString

Mauricio Villablanca mgvillablanca at yahoo.com
Thu Jul 23 03:16:42 EDT 2009




Mauricio Villablanca wrote:
> 
> I need to get the centroid of a geometry of type 12 (MultiCurveString) by
> using the GetCentroid() method in PHP ($geometry->GetCentroid() ) but the
> script stops.
> 
> Any ideas?
> 


Never mind. Even though the web API documentation claims you can use the
method for geometries of MultiCurveString type (not true, it will raise an
exception instead), I calculated the x and y coordinates of the centroid by
ponderating the centroid of its components.

$partialX = 0;
$partialY = 0;
$lengthSum = 0;
for ($t=0; $t < $geometry->GetCount(); $t++) {
      $curve = $geometry->GetCurveString(); //get each component of the
geometry
      $centroid = $curve->Getcentroid();
      $ccX = $centroid->GetCoordinate()->GetX();
      $ccY = $centroid->GetCoordinate()->GetY();
      $curveLength = $curve->GetLength();
      $partialX = $ccX*$curveLength;
      $partialY = $ccY*$curveLength;
      $lengthSum += $curveLength;
}
$centroidX = $partialX/$lengthSum;
$centroidY = $partialY/$lengthSum;

Then created a point with these coordinates.
      
      

      
-- 
View this message in context: http://n2.nabble.com/Error-with-geometry-of-type-MultiCurveString-tp3276753p3307960.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list