Exemplo n.º 1
0
 /**
  * Takes a location as "lon lat" and checks if it is inside a polygon which
  *   is passed as an array like array("lon lat","lon lat","lon lat","lon lat",. . .);
  *   As far as I know, the polygon can be as complex as you like.
  */
 public function __check_location($location, $m_geometry)
 {
     if ($location == 'specific') {
         // So location now needs to be in a specific spot. Gotta crunch the numbers to see if the
         //   lat/lon of this report falls inside the user defined polygons
         $pointLocation = new pointinpoly();
         foreach ($m_geometry as $geometry) {
             // Set the polygon of the fence
             $geometry = str_ireplace('{"geometry":"POLYGON((', '', $geometry);
             $geometry = str_ireplace('))"}', '', $geometry);
             $polygon = explode(',', (string) $geometry);
             // Find the lat,lon of the report
             $location = ORM::factory('location', $this->data->location_id);
             $point = $location->longitude . ' ' . $location->latitude;
             if ($pointLocation->pointInPolygon($point, $polygon)) {
                 // It's inside the fence!
                 return true;
             }
         }
         // It's not inside the fence. Sorry, bro.
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * Takes a location as "lon lat" and checks if it is inside a polygon which
  *   is passed as an array like array("lon lat","lon lat","lon lat","lon lat",. . .);
  *   As far as I know, the polygon can be as complex as you like.
  */
 public function __check_location($location, $m_geometry, $point = FALSE)
 {
     if ($location == 'specific') {
         // So location now needs to be in a specific spot. Gotta crunch the numbers to see if the
         //   lat/lon of this report falls inside the user defined polygons
         $pointLocation = new pointinpoly();
         foreach ($m_geometry as $geometry) {
             // Set the polygon of the fence
             $geometry = str_ireplace('{"geometry":"POLYGON((', '', $geometry);
             $geometry = str_ireplace('))"}', '', $geometry);
             $polygon = explode(',', (string) $geometry);
             // If no point array passed, fall back to a location_id
             if (!isset($point['lat']) or !isset($point['lon'])) {
                 $location = ORM::factory('location', $this->data->location_id);
                 $point = $location->longitude . ' ' . $location->latitude;
             } else {
                 // As a sanity check, fail this if there is no lat/lon but it's still being passed
                 if ($point['lat'] == FALSE or $point['lon'] == FALSE) {
                     // Get out, we shouldn't even be considering this data for a location search
                     //   so fail it.
                     return false;
                 }
                 // Convert the array to a string the pointInPolygon function will understand
                 $point = $point['lon'] . ' ' . $point['lat'];
             }
             if ($pointLocation->pointInPolygon($point, $polygon)) {
                 // It's inside the fence!
                 return true;
             }
         }
         // It's not inside the fence. Sorry, bro.
         return false;
     }
     return true;
 }