<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1458" name=GENERATOR></HEAD>
<BODY style="MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
<DIV>Hi all,</DIV>
<DIV> </DIV>
<DIV>I have been implementing Stepan Kafka's c-code for calculating area of a polygon in php/mapscript. His code seems to work fine. The only problem is that I keep getting a numlines result of 1 and numpoints result of NULL for my shape BEFORE I get a chance to use it in the area code. This, of course will give me an invalid area of 0. The numshapes variable within the shapefile object works great, always gives me the correct result.</DIV>
<DIV> </DIV>
<DIV>Wonder if anyone could let me know what they think is going on?</DIV>
<DIV> </DIV>
<DIV>Thanks,</DIV>
<DIV>Rene</DIV>
<DIV> </DIV>
<DIV>Here is the output:<BR>[15-Sep-2004 15:47:23] Numshapes:2<BR>[15-Sep-2004 15:47:23] Numlines:1<BR>[15-Sep-2004 15:47:23] Numpoints:<BR>[15-Sep-2004 15:47:23] --------------------------<BR>[15-Sep-2004 15:47:23] Numlines:1<BR>[15-Sep-2004 15:47:23] Numpoints:<BR>[15-Sep-2004 15:47:23] The sum2:0<BR>[15-Sep-2004 15:47:23] Area is:0</DIV>
<DIV> </DIV>
<DIV>Here is the code:<BR>error_log('Numshapes:'.$oShapeFile->numshapes);<BR>$theShape = $oShapeFile->getShape(0);<BR>error_log('Numlines:'.$theShape->numlines);<BR>error_log('Numpoints:'.$theShape->line[0]->numpoints);<BR>$shpArea = shapeArea($theShape);<BR>error_log('Area is:'.$shpArea);</DIV>
<DIV> </DIV>
<DIV><BR>function shapeArea($myShape)<BR>{<BR> $area = 0;<BR> if($myShape->type!=MS_SHAPE_POLYGON)<BR> {<BR> error_log('Not a Polygon!');<BR> return $area;<BR> }<BR> error_log('--------------------------');<BR> error_log('Numlines:'.$myShape->numlines);<BR> error_log('Numpoints:'.$myShape->line[0]->numpoints);<BR> for($i=0;$i<$myShape->numlines;$i++)<BR> {<BR> $sum = 0;<BR> for ($v=0;$v<$myShape->line[$i]->numpoints-2;$v++)<BR> {<BR> $sum+=(($myShape->line[$i]->point[0]->x)*($myShape->line[$i]->point[$v]->y)-($myShape->line[$i]->point[0]->y)*($myShape->line[$i]->point[$v]->x)+($myShape->line[$i]->point[0]->y)*($myShape->line[$i]->point[$v+1]->x)-($myShape->line[$i]->point[0]->x)*($myShape->line[$i]->point[$v+1]->y)+($myShape->line[$i]->point[$v]->x)*($myShape->line[$i]->point[$v+1]->y)-($myShape->line[$i]->point[$v+1]->x)*($myShape->line[$i]->point[$v]->y));<BR> error_log('The sum1:'.$sum);<BR> }<BR> error_log('The sum2:'.$sum);<BR> $sum = $sum;<BR> //test if line lies inside other ones<BR> for($v=0;$v<$i;$v++)<BR> {<BR> if(pointInLine($myShape->line[$v],$myShape->line[$i]->point[0]))<BR> {<BR> $sum = -$sum;<BR> $area += $sum;<BR> }<BR> }<BR> return $area/2;<BR> }<BR>}<BR> <BR>function pointInLine($myLine,$myPoint)<BR>{<BR> //test - point in poly - for one arc of shape<BR> <BR> $status=0;<BR> for ($i=0, $j=$myLine->numpoints-1; i<$myLine->numpoints; $j=$i++)<BR> {<BR> if (((($myLine->point[$i]->y <= $myPoint->y) && ($myPoint->y < $myLine->point[$j]->y)) || (($myLine->point[$j]->y <= $myPoint->y) && ($myPoint->y < $myLine->point[$i]->y))) && ($myPoint->x < ($myLine->point[$j]->x - $myLine->point[$i]->x) * ($myPoint->y - $myLine->point[$i]->y) / ($myLine->point[$j]->y - $myLine->point[$i]->y) + $myLine->point[$i]->x))<BR> $status = !$status;<BR> }<BR> return $status;<BR>}</DIV>
<DIV> </DIV></BODY></HTML>