| Server IP : 162.214.74.102 / Your IP : 216.73.217.80 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/public_html/lrsys_projetos/sopizzas/application/third_party/ |
Upload File : |
<?php
/**
Description: The point-in-polygon algorithm allows you to check if a point is
inside a polygon or outside of it.
Author: Michaël Niessen (2009)
Website: http://AssemblySys.com
If you find this script useful, you can show your
appreciation by getting Michaël a cup of coffee ;)
PayPal: michael.niessen@assemblysys.com
As long as this notice (including author name and details) is included and
UNALTERED, this code is licensed under the GNU General Public License version 3:
http://www.gnu.org/licenses/gpl.html
########################
Modified By NARAYAN SARKAR on 09/12/2016
*/
class pointLocation {
var $pointOnVertex = true; // Check if the point sits exactly on one of the vertices?
function _pointLocation() {
}
function pointInPolygon($point, $polygon, $pointOnVertex = true) {
$this->pointOnVertex = $pointOnVertex;
// Transform string coordinates into arrays with x and y values
$point = $this->pointStringToCoordinates($point);
$vertices = array();
foreach ($polygon as $vertex) {
$vertices[] = $this->pointStringToCoordinates($vertex);
}
//print_r($vertices);
// Check if the point sits exactly on a vertex
if ($this->pointOnVertex == true and $this->pointOnVertex($point, $vertices) == true) {
return "vertex";
}
// Check if the point is inside the polygon or on the boundary
$intersections = 0;
$vertices_count = count($vertices);
for ($i=1; $i < $vertices_count; $i++) {
$vertex1 = $vertices[$i-1];
$vertex2 = $vertices[$i];
if ($vertex1['y'] == $vertex2['y'] and $vertex1['y'] == $point['y'] and $point['x'] > min($vertex1['x'], $vertex2['x']) and $point['x'] < max($vertex1['x'], $vertex2['x'])) { // Check if point is on an horizontal polygon boundary
return "boundary";
}
//echo "vertex1: ".$vertex1['y']."<br/>";
//echo "vertex2: ".$vertex2['y']."<br/>";
//echo min($vertex1['y'], $vertex2['y'])."<br/>";
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 ($xinters == $point['x']) { // Check if point is on the polygon boundary (other than horizontal)
return "boundary";
}
// echo "vertex1: ".$vertex1['x']."<br/>";
// echo "vertex2: ".$vertex2['x']."<br/>";
// echo "point: ".$point['x']."<br/>";
// echo "xinters: ".$xinters."<br/>";
if ($vertex1['x'] == $vertex2['x'] || $point['x'] <= $xinters) {
$intersections++;
}
}
}
// If the number of edges we passed through is odd, 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) {
//print_r($pointString);
$coordinates = explode(" ", $pointString);
return array("x" => $coordinates[0], "y" => $coordinates[1]);
}
function formatDataIntoArray($dbValue='')
{
$newStringArr = array();
//echo strpos($dbValue, "@@");
if(strpos($dbValue, "],["))
{
$explodeArr = explode("],[", $dbValue);
if(!empty($explodeArr))
{
$firstPoint = "";
foreach ($explodeArr as $key => $value) {
if($key == 0){
$value = str_replace('[[', '', $value);
$firstPoint = str_replace(',', ' ', $value);
}
if($key == (count($explodeArr) - 1)){
$value = str_replace(']]', '', $value);
}
$value = str_replace(',', ' ', $value);
//$value = $this->pointFormat($value);
array_push($newStringArr, $value);
}
array_push($newStringArr, $firstPoint);
//print_r($newStringArr);
}
}
return ($newStringArr);
}
function pointFormat($point)
{
//echo $point;
$newPoint = "";
$pointexp = explode(" ", $point);
//print_r($pointexp);
foreach ($pointexp as $key => $value) {
$newPoint .= number_format($value, 6)." ";
}
return $newPoint = rtrim($newPoint);
}
function drawPolygon()
{
// Create a blank image
$image = imagecreatetruecolor(1400, 768);
// Allocate a color for the polygon
$col_poly = imagecolorallocate($image, 255, 255, 255);
// Draw the polygon
//imagepolygon($image, array(25.774, -80.19,18.466,-66.118,32.321,-64.757), 3, $col_poly);
imagepolygon($image, array(
32.93305569462244,-117.2464370727539,
32.926860188864964,-117.24746704101562,
32.92671610217319,-117.23939895629883,
32.931326759919536,-117.23793983459473
),
3,
$col_poly);
// Output the picture to the browser
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
}
function checkPolygon($address = '', $dbData = '', $point = array()) {
//echo $dbData;
if($dbData == "" || $dbData == "0") {
//echo "False";
return false;
}
//echo "ok";
if(!empty($address))
{
// define("MAP_API_KEY", "AIzaSyBhlorKcyineKe635WRfxJjhplJM1Cyhz0");
// $geo = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&key='.MAP_API_KEY);
// added by arka
$url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&key='.MAP_API_KEY;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
$geo = $response;
curl_close($ch);
// ended by arka
// We convert the JSON to an array
$geo = json_decode($geo, true);
/*echo '<pre>';
print_r($geo);
echo '</pre>';*/
//echo $geo['results'][0]['geometry']['location']['lat'];
// If everything is cool
if ($geo['status'] = 'OK') {
// We set our values
$latitude = isset($geo['results'][0]['geometry']['location']['lat'])? $geo['results'][0]['geometry']['location']['lat']: DEFAULT_LAT;
$longitude = isset($geo['results'][0]['geometry']['location']['lng'])? $geo['results'][0]['geometry']['location']['lng'] : DEFAULT_LONG;
}
else {
$latitude = DEFAULT_LAT;
$longitude = DEFAULT_LONG;
}
}
else {
$latitude = DEFAULT_LAT;
$longitude = DEFAULT_LONG;
}
$polygon = $this->formatDataIntoArray($dbData);
//print_r($polygon);
//$points = array("21.69826549685252 -66.357421875");
// print_r($point);
if($point == "")
{
//echo "Empty";
$points = $latitude.' '.$longitude;
}else
{
// echo "Not Empty";
$points = $point;
}
//print_r($points);
// 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): " . $this->pointInPolygon($point, $polygon) . "<br>";
// }
return true;
if($this->pointInPolygon($points, $polygon) == "outside") return false;
else return true;
}
}
###################### EXAMPLE ######################################
// define("MAP_API_KEY", "AIzaSyDflBkLkm9R2f_dIsSkpFRI203Lgwlo1yo");
// $address = "Ilford IG1 4QR, United Kingdom";
// $points = $latitude.' '.$longitude;
// $dbData = "[[51.564137081950065,0.06724834442138672],[51.565711045912614,0.07106781005859375],[51.565604338213134,0.07458686828613281],[51.56424379309297,0.07626056671142578],[51.56280317153341,0.0748443603515625],[51.56150924104206,0.07226943969726562],[51.56069551331916,0.06701231002807617]]";
// $pointLocation = new pointLocation();
// echo $pointLocation->checkPolygon($address, $dbData, $points = "")
//"[[41.49324271131432,-90.47262668609619],[41.49700357252215,-90.46794891357422],[41.49240693472465,-90.46438694000244],[41.48780997072924,-90.46940803527832]]";
?>