Ejemplo n.º 1
0
 function loadPlace()
 {
     global $_DISPATCHER;
     @(include_once "script/include_InPoly_class.php");
     $region = array();
     $subregion = false;
     include "script/places/global.php";
     $point = floor($this->x / 1000) . " " . floor($this->y / 1000);
     $pointLocation = new pointLocation();
     $res = $pointLocation->pointInPolygon($point, $region['place_silan'], false);
     if ($res != "outside") {
         include "script/places/silan.php";
     } else {
         include "script/places/continents.php";
         $region2 = $region;
         foreach ($region2 as $key => $r) {
             $res = $pointLocation->pointInPolygon($point, $r, false);
             if ($res != "outside") {
                 include "script/places/" . $key . ".php";
                 if ($subregion == true) {
                     foreach ($region as $key2 => $r2) {
                         $res2 = $pointLocation->pointInPolygon($point, $r2, false);
                         if ($res2 != "outside") {
                             include "script/places/" . $key . "/" . $key2 . ".php";
                             break;
                         }
                     }
                 }
                 break;
             }
         }
     }
     foreach ($region as $key => $r) {
         $res = $pointLocation->pointInPolygon($point, $r, false);
         if ($res != "outside") {
             if ($this->placeid == "place_unknown") {
                 $this->placeid = $key;
             } else {
                 $tmp = new Position();
                 $tmp->x = $this->x;
                 $tmp->y = $this->y;
                 $tmp->z = $this->z;
                 $tmp->heading = $this->heading;
                 $tmp->placeid = $key;
                 $_DISPATCHER->dispatchEntity($tmp->getName(), $tmp);
             }
             #break;
         }
     }
 }
    function pointOnVertex($point, $vertices)
    {
        foreach ($vertices as $vertex) {
            if ($point == $vertex) {
                return true;
            }
        }
    }
    function pointStringToCoordinates($pointString)
    {
        $coordinates = explode(" ", $pointString);
        return array("x" => $coordinates[0], "y" => $coordinates[1]);
    }
}
/*** Example ***/
$pointLocation = new pointLocation();
// take GPS geobox polygon points and put into polygon array
$polygonArray = array();
mysql_connect('localhost', 'root', 'fin3') or die(fail('Could not connect to database.'));
mysql_select_db('gps-geobox');
$result = mysql_query("SELECT * FROM `{$phone}`");
// split each point into required string
// ##########################################################
// ##########################################################
// THESE TWO BLOCKS OF CODE GIVE PROBLEMS!! ONE WORKS SOMETIMES, THE OTHER WORKS THE OTHER TIMES
// IF ANYTHING GOES WRONG WITH GEOFENCE INBOUNDS/OUTBOUNDS ITS HERE!!
// JUST SWITCH THE COMMENTS AND ACTIVATE THE OTHER SEGMENT OF CODE
// segment 1
while ($row = mysql_fetch_array($result)) {
    $polyPoint = $row['lat'] . " " . $row['lng'];
    array_push($polygonArray, $polyPoint);
Ejemplo n.º 3
0
    //return distance in KM
    $theta = $lon1 - $lon2;
    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
    $dist = acos($dist);
    $dist = rad2deg($dist);
    $miles = $dist * 60 * 1.1515;
    return $miles * 1.609344;
}
include 'connect.php';
include 'pointLocation.php';
$connection = new createConnection();
//created a new object
$connection = $connection->connectToDatabase();
// connected to the database
$flag = 0;
$pointLocation = new pointLocation();
$lat = strval($_POST["lat"]);
$long = strval($_POST["long"]);
echo "<pre>       Longitude       :  {$lat} </pre><br>";
echo "<pre>       Latitude        :  {$long} </pre><br>";
$build_string = $lat . ',' . $long . ',' . '0.0';
$point = $build_string;
$val = $_POST["zone_id"];
if ($val == "-1") {
    $qq = "select * from area";
    $qq = $connection->prepare($qq);
    $qq->execute();
    $qq->setFetchMode(PDO::FETCH_ASSOC);
    while ($result = $qq->fetch()) {
        $latCity = $result['center_lat'];
        $longCity = $result['center_long'];
Ejemplo n.º 4
0
            if ($intersections % 2 != 0) {
                return "inside";
            } else {
                return "outside";
            }
        }
        function pointOnVertex($point, $vertices)
        {
            foreach ($vertices as $vertex) {
                if ($point == $vertex) {
                    return true;
                }
            }
        }
        function pointStringToCoordinates($pointString)
        {
            $coordinates = explode(" ", $pointString);
            return array("x" => $coordinates[0], "y" => $coordinates[1]);
        }
    }
    //////////////////
    /////ПРоверка/////
    //////////////////
    $pointLocation = new pointLocation();
    $points = array("50 70", "70 40", "-20 30", "100 10", "-10 -10", "40 -20", "110 -20");
    $polygon = array("-50 30", "50 70", "100 50", "80 10", "110 -10", "110 -30", "-20 -50", "-30 -40", "10 -10", "-10 10", "-30 -20", "-50 30");
    // The last point's coordinates must be the same as the first one's, to "close the loop"
    foreach ($points as $key => $point) {
        echo "point " . ($key + 1) . " ({$point}): " . $pointLocation->pointInPolygon($point, $polygon) . "<br>";
    }
}
Ejemplo n.º 5
0
 $long22 = $idd->response->items[$s]->client->locationlongitude;
 $lat22 = $idd->response->items[$s]->client->locationlatitude;
 $lat2 = $idd->response->items[$s]->fromlatitude;
 $long2 = $idd->response->items[$s]->fromlongitude;
 if ($long22 == "" && $long2 == "") {
     continue;
 } else {
     if ($long22 == "") {
     }
     if ($long2 == "") {
         $lat2 = $lat22;
         $long2 = $long22;
     }
 }
 $point = array('lat' => $lat2, 'long' => $long2);
 $pointLocation = new pointLocation();
 foreach ($sss1 as $dist1 => $ssd1) {
     if ($pointLocation->pointInPolygon($point, $ssd1) == "inside") {
         $from = $idd->response->items[$s]->from;
         $to = $idd->response->items[$s]->to;
         $price = $idd->response->items[$s]->price;
         $phone = $idd->response->items[$s]->client->phone;
         $idd1 = $idd->response->items[$s]->id;
         $req = "INSERT INTO `indriver`.`current_taxa` (`from`, `to`, `price`, `phone`, `dist`, `id_tax`) VALUES ('{$from}', '{$to}', '{$price}', '{$phone}', '{$dist1}', '{$idd1}');";
         echo $phone . "@suka";
         db_req_without_resp($req);
         $call_status = 88;
         include "call_status_update.php";
         curl_close($ch);
         return;
     }
 /**
  * Loads up Alerts Asyncronously for performance improvements.  Cannot use cron because cron does not run fast enough
  * for us when we are in an emergency situation... when refresh is required every 10 seconds
  */
 function reload()
 {
     // Check Lock
     if (get_site_transient('weather_alerts_reloading')) {
         // Someone Else is reloading weather alerts... quit
         return new WP_Error('weather_alerts_reloading', 'Weather Alerts are already Reloading');
     }
     // Grab the Lock
     set_site_transient('weather_alerts_reloading', true, 20);
     $alert_types_to_show = apply_filters('weather_alerts_search_terms', get_site_option('weather_alerts_search_terms', array('tornado warning', 'severe thunderstorm warning')));
     $coordinates = apply_filters('weather_alerts_coordinates', get_site_option('weather_alerts_coordinates', array(array("42.437255", "-71.430091"), array("42.412456", "-71.367254"), array("42.402443", "-71.469564"), array("42.352733", "-71.484842"), array("42.341442", "-71.389913"))));
     $weather_url = $this->get_alerts_endpoint();
     $feed = $this->get_xml_data($weather_url);
     if (is_wp_error($feed)) {
         _sudbury_log('[Error] Could not Retrieve weather data from NOAA: WP_Error');
         _sudbury_log($feed);
         // Immediately release lock to allow someone else to try again right away
         delete_site_transient('weather_alerts_reloading');
         return $feed;
     }
     $this->alerts = array();
     // Filter the alerts because we don't want small alerts like flood watches, just the big exciting ones like tornado warnings
     foreach ($feed->entry as $alert) {
         $title_lc = strtolower($alert->title);
         $show_alert = true;
         // We can filter alerts
         if (!empty($alert_types_to_show)) {
             $show_alert = false;
             foreach ($alert_types_to_show as $alert_title_frag) {
                 $search = trim(strtolower($alert_title_frag));
                 if ('' == $search) {
                     continue;
                 }
                 if (false !== strpos($title_lc, $search)) {
                     $show_alert = true;
                 }
             }
         }
         if (!empty($coordinates) && $show_alert) {
             $pointfinder = new pointLocation();
             $points = $alert->children('cap', true)->polygon;
             // Split it into an array of arrays containing x-y pairs
             $alert_polygon = array_map(function ($point) {
                 return explode(',', $point);
             }, explode(' ', $points));
             $inside = false;
             // If any part of town is within the alert zone include it
             foreach ($coordinates as $coordinate) {
                 if ('outside' !== $pointfinder->pointInPolygon($coordinate, $alert_polygon)) {
                     $inside = true;
                     break;
                 }
             }
             if (!$inside) {
                 $show_alert = true;
                 _sudbury_log('Polygon Search: [Fail] ' . $alert->title);
             } else {
                 _sudbury_log('Polygon Search: [Pass] ' . $alert->title);
             }
         }
         if ($show_alert) {
             $structured_alert = array('title' => (string) $alert->title, 'url' => (string) $alert->link['href'][0], 'readmore-text' => 'View Alert', 'alert-class' => 'alert-red');
             $this->alerts[] = $structured_alert;
         }
     }
     $cache_time = 60;
     // Default to checking NOAA every minute
     if (!empty($this->alerts)) {
         set_site_transient('weather_alerts_recently', true, 3600);
     }
     if (defined('SUDBURY_WEATHER_CACHE_TIME')) {
         $cache_time = SUDBURY_WEATHER_CACHE_TIME;
         // If there is an override in effect respect the override
     } else {
         if (get_site_transient('weather_alerts_recently')) {
             // This speeds up the cache time when weather phenomena has been detected recently for faster and more up-to-date reporting
             _sudbury_log('[Alerts] [Weather Alerts] Weather Alerts System Actively Checking Alerts at Increased Speed');
             $cache_time = 10;
             // If there were recently weather alerts check NOAA every 10 seconds instead (6x faster than default)
         }
     }
     /**
      * This filter allows you to override the time that alerts will be cached in a transient for.
      * The cache time varies based on the constant 'SUDBURY_WEATHER_CACHE_TIME' and whether there are currently
      * any active weather alerts
      */
     $cache_time = apply_filters('weather_alerts_cache_time', $cache_time, $this->alerts);
     // Fix for empty array bug with W3TC and wp_cache_set/get()
     if (empty($this->alerts)) {
         $this->alerts = 'none';
     }
     // This is the primary one... it contains the recent alerts... when it expires we need to spawn_reload()
     // When we spawn_reload we will use 'stale_weather_alerts' defined below
     set_site_transient('weather_alerts', $this->alerts, $cache_time);
     // Need a stale transient for the event that the primary transient expires... then we will return the stale one
     // while we are refreshing.
     set_site_transient('stale_weather_alerts', $this->alerts, $cache_time + 3600);
     // Holding the lock for a couple more seconds to prevent any race conditions
     sleep(2);
     // Release the Reload Lock
     delete_site_transient('weather_alerts_reloading');
     // success
     return true;
 }
Ejemplo n.º 7
0
        }
        // If the number of edges we passed through is even, then it's in the polygon.
        if ($intersections % 2 != 0) {
            return "inside";
        } else {
            return "outside";
        }
    }
    function pointOnVertex($point, $vertices)
    {
        foreach ($vertices as $vertex) {
            if ($point == $vertex) {
                return true;
            }
        }
    }
    function pointStringToCoordinates($pointString)
    {
        $coordinates = explode(" ", $pointString);
        return array("x" => $coordinates[0], "y" => $coordinates[1]);
    }
}
/*** Example ***/
$pointLocation = new pointLocation();
$points = array("30 19", "0 0", "10 0", "30 20", "11 0", "0 11", "0 10", "30 22", "20 20");
$polygon = array("10 0", "20 0", "30 10", "30 20", "20 30", "10 30", "0 20", "0 10", "10 0");
foreach ($points as $key => $point) {
    echo "{$key} ({$point}) is " . $pointLocation->pointInPolygon($point, $polygon) . "<br>";
}
?>
 
    function pointOnVertex($point, $vertices)
    {
        foreach ($vertices as $vertex) {
            if ($point == $vertex) {
                return true;
            }
        }
    }
    function pointStringToCoordinates($pointString)
    {
        $coordinates = explode(" ", $pointString);
        return array("x" => $coordinates[0], "y" => $coordinates[1]);
    }
}
/*** Example ***/
$pointLocation = new pointLocation();
mysql_connect('localhost', 'root', 'fin3') or die(fail('Could not connect to database.'));
mysql_select_db('gps-geobox');
// take GPS geobox polygon points and put into polygon array
$polygonArray = array();
$result = mysql_query("SELECT * FROM `{$phone}`");
// split each point into required string
while ($row = mysql_fetch_array($result)) {
    $polyPoint = $row['lat'] . " " . $row['lng'];
    array_push($polygonArray, $polyPoint);
    echo "<BR>POLY POINT: " . $polyPoint;
}
/*
for($i=0; $i<10; $i++)
{
$row = mysql_query("SELECT * FROM `$phone` where id = $i");
Ejemplo n.º 9
0
class pointLocation
{
    function pointLocation()
    {
    }
    function pointInPolygon($point, $polygon, $pointOnVertex = true)
    {
        $vertices = $polygon;
        $intersections = 0;
        $vertices_count = count($vertices);
        for ($i = 1; $i < $vertices_count; $i++) {
            $vertex1 = $vertices[$i - 1];
            $vertex2 = $vertices[$i];
            if ($point['y'] > min($vertex1['y'], $vertex2['y']) and $point['y'] <= max($vertex1['y'], $vertex2['y']) and $point['x'] <= max($vertex1['x'], $vertex2['x']) and $vertex1['y'] != $vertex2['y']) {
                $xinters = ($point['y'] - $vertex1['y']) * ($vertex2['x'] - $vertex1['x']) / ($vertex2['y'] - $vertex1['y']) + $vertex1['x'];
                if ($vertex1['x'] == $vertex2['x'] || $point['x'] <= $xinters) {
                    $intersections++;
                }
            }
        }
        if ($intersections % 2 != 0) {
            return "inside";
        } else {
            return "outside";
        }
    }
}
$pointLocation = new pointLocation();
//$polygon = array(array('x'=>0,'y'=>0),array('x'=>4,'y'=>1),array('x'=>4,'y'=>4),array('x'=>1,'y'=>4),array('x'=>0,'y'=>0));
//$point = array('x'=>1,'y'=>0);
echo $pointLocation->pointInPolygon($point, $polygon);