コード例 #1
0
ファイル: Position_entity.php プロジェクト: cls1991/ryzomcore
 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;
         }
     }
 }
コード例 #2
0
    array_push($polygonArray, $polyPoint);
}
// ##########################################################
// ##########################################################
// segment 2
/*for($i=0; $i<10; $i++)
{
$row = mysql_query("SELECT FROM `$phone` where id = `$i`");
$polyPoint = $row['lat'] . " " . $row['lng'];
echo $row['lat'];
array_push($polygonArray,$polyPoint);
}*/
// ##########################################################
// ########################################################## end segments
// take phone coordinates and add to array -- ONLY 1 POINT AT A TIME
$points = array();
$phonePoint = $lat . " " . $lng;
array_push($points, $phonePoint);
foreach ($points as $key => $point) {
    $inbounds = $pointLocation->pointInPolygon($point, $polygonArray);
}
mysql_select_db('gps-locations');
mysql_query("INSERT INTO `gps-locations`.`{$phone}` (`id`,`time`, `lat`, `lng`, `speed`,`day`,`inbounds`) VALUES (NULL, '{$date}', '{$lat}', '{$lng}','{$speed}','{$day2}','{$inbounds}')");
mysql_close($con);
echo "Phone: " . $phone;
echo "<br>Lat: " . $lat;
echo "<br>Lng: " . $lng;
echo "<br>Speed: " . $speed;
echo "<br>InBounds: " . $inbounds;
echo "<BR>Written to DB at: ";
echo $date;
コード例 #3
0
     //and given lati and long
     if ($dis < 100) {
         $z = "select * from city_info where area_id = {$a_id} ";
         $z = $connection->prepare($z);
         $z->execute();
         $z->setFetchMode(PDO::FETCH_ASSOC);
         while ($res = $z->fetch()) {
             $c_id = $res['id'];
             $b = "select * from locations where city_id = {$c_id} ";
             $b = $connection->prepare($b);
             $b->execute();
             $b->setFetchMode(PDO::FETCH_ASSOC);
             while ($ans = $b->fetch()) {
                 $array = unserialize($ans['coordinates']);
                 //echo $array[0];
                 $temp = $pointLocation->pointInPolygon($point, $array);
                 if ($temp == "inside" or $temp == "vertex") {
                     //echo nl2br("\n",false);
                     //echo "<pre>       Region    :   </pre>";
                     $Name = $ans['name'];
                     $ZONEID = $ans['id'];
                     echo "<pre>       Sub-zone ID     :  {$ZONEID}</pre>";
                     echo "<br>";
                     echo "<pre>       Sub-zone Name   :  {$Name}</pre>";
                     $flag = 1;
                 }
             }
         }
     }
 }
 if ($flag == 0) {
コード例 #4
0
ファイル: google.php プロジェクト: bottookku/botto
            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>";
    }
}
コード例 #5
0
ファイル: call_filter.php プロジェクト: bottookku/botto
     $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;
         }
     }
 } else {
コード例 #6
0
 /**
  * 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;
 }
コード例 #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>";
}
?>
 
コード例 #8
0
/*** 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");
$polyPoint = $row['lat'] . " " . $row['lng'];
echo "POLY POINT: " .$polyPoint . "<BR>";
array_push($polygonArray,$polyPoint);
}
*/
// take phone coordinates and add to array -- ONLY 1 POINT AT A TIME
$points = array();
$phonePoint = $lat . " " . $lng;
array_push($points, $phonePoint);
foreach ($points as $key => $point) {
    echo "{$key} ({$phonePoint}) is " . $pointLocation->pointInPolygon($point, $polygonArray) . "<br>";
}
?>
 
コード例 #9
0
ファイル: 111.php プロジェクト: bottookku/botto
{
    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);