<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>&nbsp;</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>&nbsp;</DIV>
<DIV>Wonder if anyone could let me know what they think is going on?</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks,</DIV>
<DIV>Rene</DIV>
<DIV>&nbsp;</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>&nbsp;</DIV>
<DIV>Here is the code:<BR>error_log('Numshapes:'.$oShapeFile-&gt;numshapes);<BR>$theShape = $oShapeFile-&gt;getShape(0);<BR>error_log('Numlines:'.$theShape-&gt;numlines);<BR>error_log('Numpoints:'.$theShape-&gt;line[0]-&gt;numpoints);<BR>$shpArea = shapeArea($theShape);<BR>error_log('Area is:'.$shpArea);</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>function shapeArea($myShape)<BR>{<BR>&nbsp; $area = 0;<BR>&nbsp; if($myShape-&gt;type!=MS_SHAPE_POLYGON)<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp; error_log('Not a Polygon!');<BR>&nbsp;&nbsp;&nbsp; return $area;<BR>&nbsp; }<BR>&nbsp; error_log('--------------------------');<BR>&nbsp; error_log('Numlines:'.$myShape-&gt;numlines);<BR>&nbsp; error_log('Numpoints:'.$myShape-&gt;line[0]-&gt;numpoints);<BR>&nbsp; for($i=0;$i&lt;$myShape-&gt;numlines;$i++)<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp; $sum = 0;<BR>&nbsp;&nbsp;&nbsp; for ($v=0;$v&lt;$myShape-&gt;line[$i]-&gt;numpoints-2;$v++)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sum+=(($myShape-&gt;line[$i]-&gt;point[0]-&gt;x)*($myShape-&gt;line[$i]-&gt;point[$v]-&gt;y)-($myShape-&gt;line[$i]-&gt;point[0]-&gt;y)*($myShape-&gt;line[$i]-&gt;point[$v]-&gt;x)+($myShape-&gt;line[$i]-&gt;point[0]-&gt;y)*($myShape-&gt;line[$i]-&gt;point[$v+1]-&gt;x)-($myShape-&gt;line[$i]-&gt;point[0]-&gt;x)*($myShape-&gt;line[$i]-&gt;point[$v+1]-&gt;y)+($myShape-&gt;line[$i]-&gt;point[$v]-&gt;x)*($myShape-&gt;line[$i]-&gt;point[$v+1]-&gt;y)-($myShape-&gt;line[$i]-&gt;point[$v+1]-&gt;x)*($myShape-&gt;line[$i]-&gt;point[$v]-&gt;y));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error_log('The sum1:'.$sum);<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; error_log('The sum2:'.$sum);<BR>&nbsp;&nbsp;&nbsp; $sum = $sum;<BR>&nbsp;&nbsp;&nbsp; //test if line lies inside other ones<BR>&nbsp;&nbsp;&nbsp; for($v=0;$v&lt;$i;$v++)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(pointInLine($myShape-&gt;line[$v],$myShape-&gt;line[$i]-&gt;point[0]))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sum = -$sum;<BR>&nbsp;&nbsp; $area += $sum;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; return $area/2;<BR>&nbsp; }<BR>}<BR>&nbsp;<BR>function pointInLine($myLine,$myPoint)<BR>{<BR>&nbsp; //test - point in poly - for one arc of shape<BR>&nbsp;<BR>&nbsp; $status=0;<BR>&nbsp; for ($i=0, $j=$myLine-&gt;numpoints-1; i&lt;$myLine-&gt;numpoints; $j=$i++)<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp; if (((($myLine-&gt;point[$i]-&gt;y &lt;= $myPoint-&gt;y) &amp;&amp; ($myPoint-&gt;y &lt; $myLine-&gt;point[$j]-&gt;y)) || (($myLine-&gt;point[$j]-&gt;y &lt;= $myPoint-&gt;y) &amp;&amp; ($myPoint-&gt;y &lt; $myLine-&gt;point[$i]-&gt;y))) &amp;&amp; ($myPoint-&gt;x &lt; ($myLine-&gt;point[$j]-&gt;x - $myLine-&gt;point[$i]-&gt;x) * ($myPoint-&gt;y - $myLine-&gt;point[$i]-&gt;y) / ($myLine-&gt;point[$j]-&gt;y - $myLine-&gt;point[$i]-&gt;y) + $myLine-&gt;point[$i]-&gt;x))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $status = !$status;<BR>&nbsp; }<BR>&nbsp; return $status;<BR>}</DIV>
<DIV>&nbsp;</DIV></BODY></HTML>