使用Google Maps API v3服务器端检查点在多边形区域内的存在 [英] Server-side checking of a point's existence inside a polygonal area using Google Maps API v3

查看:102
本文介绍了使用Google Maps API v3服务器端检查点在多边形区域内的存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

逻辑是:用户正在编辑一个存在于数据库中的极端点的现有多边形区域。编辑完成后,修改后的坐标在数据库中更新。现在我需要找出修改后的多边形中是否存在某个点。为此,我假设我必须执行服务器端检查。客户端检查很容易通过javaScript完成,而且我已经完成了。我遇到的真正问题是在服务器端进行检查。任何建议?

解决方案

我已经在PHP中实现了多边形中的服务器端点。

 <?php 
// Point-In-Polygon算法测试参数
$ polySides = 4; //多边形有多少个角
$ polyX = array(4,9,11,2); //角的水平坐标
$ polyY = array(10,7,2,2); //角点的垂直坐标
$ x = 3.5; //点
// $ y = 13.5; //
$ y = 3.5之外// //
$ b之内$ b函数pointInPolygon($ polySides,$ polyX,$ polyY,$ x,$ y){
$ j = $ polySides-1;
$ oddNodes = 0;如果($ polyY [$ i]< $ y&& $ polyY [$ j]> =($ i $ 0; $ i <$ polySides; $ i ++) $ y
|| $ polyY [$ j]< $ y&& $ polyY [$ i]> = $ y){
if($ polyX [$ i] +($ $ $ polyY [$ i])/($ polyY [$ j] - $ polyY [$ i])*($ polyX [$ j] - $ polyX [$ i])<$ x){
$ oddNodes =!$ oddNodes; }}
$ j = $ i; }

返回$ oddNodes; }
$ b $ //测试
if(pointInPolygon($ polySides,$ polyX,$ polyY,$ x,$ y)){
echoIs in polygon!;
}
else echo不在多边形中;
?>

这可以修改以适应选择的语言,即。 C#


The logic is: user is editing an existing polygonal area of which extreme points are stored in the database. After editing the modified co-ordinates are updated in the database. Now I need to find whether a certain point exists inside the modified polygon or not. For that I'm assuming I have to do the server-side checking. The client-side checking is easily done by javaScript and that I've done already. The real problem I'm having is to check this on the server-side. Any suggestions?

解决方案

I have implemented server side point in polygon in PHP.

<?php
//Point-In-Polygon Algorithm test parameters
$polySides  = 4; //how many corners the polygon has
$polyX    =  array(4,9,11,2);//horizontal coordinates of corners
$polyY    =  array(10,7,2,2);//vertical coordinates of corners
$x = 3.5;//point
//$y = 13.5;//Outside
$y = 3.5;//Inside

function pointInPolygon($polySides,$polyX,$polyY,$x,$y) {
  $j = $polySides-1 ;
  $oddNodes = 0;
  for ($i=0; $i<$polySides; $i++) {
    if ($polyY[$i]<$y && $polyY[$j]>=$y 
 ||  $polyY[$j]<$y && $polyY[$i]>=$y) {
    if ($polyX[$i]+($y-$polyY[$i])/($polyY[$j]-$polyY[$i])*($polyX[$j]-$polyX[$i])<$x)    {
    $oddNodes=!$oddNodes; }}
   $j=$i; }

  return $oddNodes; }

//Test 
 if (pointInPolygon($polySides,$polyX,$polyY,$x,$y)){
  echo "Is in polygon!";
}
else echo "Is not in polygon";
?>

This can be modified to suit language of choice ie. C#

这篇关于使用Google Maps API v3服务器端检查点在多边形区域内的存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆