php - Point inside polygon weird results -
i want determine if coordinates inside polygon, i'm getting results not in polygon. it's checks if either lat or lon in range not both. ideas??
public function subcacheclients (){ $clients = gzfile('tmp/whazzup/cache/clients.txt.gz'); for($i=1;$i<count($clients);$i++){ $clients[$i] = explode(':', $clients[$i]); //polygon of canada $polylat = array(90,82,77,75,65,64,61,53,49,45,45,42,47,47.33,45,45,43.63,43.5,42.83,41.63,41.85,42.33,42.5,43.58,45.33,48,49,49,48.42,48.18,48.5,48.33,5,54,54.83,59.5,60.32,90); $polylon = array(-141,-60,-75,-76,-57.75,-63,63,-54,-51,-51,-53,-67,-67.75,-69.33,-71.5,-75,-76.92,-79.2,-78.93,-82.5,-83.06,-83.03,-82.5,-82.12,-82.5,-88.33,-95.0,-123.33,-123.12,-123.35,-124.83,-128,-133.75,-136,-130,-135,-141,-141); $inpolygon = $this->inpolygon($clients[$i][5], $clients[$i][6], $polylat, $polylon); if($inpolygon == true && $clients[$i][5]>0 && $clients[$i][6]<0 && $clients[$i][3]=='atc'){ echo $clients[$i][0]; file_put_contents('tmp/whazzup/cache/controllersonline.txt', implode(':', $clients[$i]), file_append); } } } public function inpolygon($lat, $lon, $polylat, $polylon) { $j = count($polylat)-1; $result = false; for($i=0;$i<count($polylat);$i++){ if($polylat[$i]<$lat && $polylat[$j]>=$lat || $polylat[$j]<$lat && $polylat[$i]>=$lat){ //if latitude @ beggining bigger , @ end smaller or vise versa if($polylon[$i]+($lat-$polylat[$i])/($polylat[$j]-$polylat[$i])*($polylon[$j]-$polylon[$i])<$lon){ // $result = true; } } $j=$i; } return $result; }
Comments
Post a Comment