class Point {
public $lat;
public $long;
function Point($lat, $long) {
$this->lat = $lat;
$this->long = $long;
}
}
//the Point in Polygon function
function pointInPolygon($p, $polygon) {
//if you operates with (hundred)thousands of points
set_time_limit(60);
$c = 0;
$p1 = $polygon[0];
$n = count($polygon);
for ($i=1; $i<=$n; $i++) {
$p2 = $polygon[$i % $n];
if ($p->long > min($p1->long, $p2->long)
&& $p->long <= max($p1->long, $p2->long)
&& $p->lat <= max($p1->lat, $p2->lat)
&& $p1->long != $p2->long) {
$xinters = ($p->long - $p1->long) * ($p2->lat - $p1->lat) / ($p2->long - $p1->long) + $p1->lat;
if ($p1->lat == $p2->lat || $p->lat <= $xinters) {
$c++;
}
}
$p1 = $p2;
}
// if the number of edges we passed through is even, then it's not in the poly.
return $c%2!=0;
}
$arr = array();
unset($list);
$sql_query = "select * from map_line_t";
$list = $DB->select_query($sql_query);
if($list) {
foreach($list as $row) {
$arr[] = new Point($row['rl_map_lat'], $row['rl_map_lng']);
}
}
$polygon = $arr;
/*
$polygon = array(
new Point(35.2440904,129.090543),
new Point(35.2438473,129.0902734),
new Point(35.2438046,129.0903405),
new Point(35.2440379,129.0906006),
);
*/
function ParkLine($lat, $lng) {
global $polygon;
$latlng=$lat.','.$lng;
echo (pointInPolygon(new Point($lat,$long), $polygon)) ? $latlng .' is inside polygon<br>' : $latlng.' is outside<br>';
}
ParkLine(35.2439421, 129.0904429);
ParkLine(35.2441031, 129.0904939);
카카오맵 폴리곤 지도 내부에 좌표가 있는지 확인
'Web > PHP' 카테고리의 다른 글
PHP] map 폴리곤(Polygon) 영역의 중심 좌표 구하기 (0) | 2021.11.05 |
---|---|
사업자등록정보 진위확인 및 상태조회 - PHP 오픈 API (0) | 2021.11.03 |
PHP 두 날짜 사이의 기간 구하기 (0) | 2021.04.02 |
또 다른 대형 공급망 공격 될 뻔한 PHP 깃 서버 침해 사건 (0) | 2021.03.30 |
두 날짜 사이의 월별, 일별 통계 구하기 (0) | 2021.03.30 |