博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java实现判断一个经纬度坐标是否在一个多边形内(经自己亲测)
阅读量:6319 次
发布时间:2019-06-22

本文共 3674 字,大约阅读时间需要 12 分钟。

1.在高德地图上绘制的多边形;经纬度逗号分隔格式;上面是用来方便存坐标的对象;下面是方法测试;直接复制代码即可运行

public class Point {           private Double x;          private Double y;          public Point (Double x , Double y) {              this.x = x;              this.y = y;          }          public Double getX() {              return x;          }          public void setX(Double x) {              this.x = x;          }          public Double getY() {              return y;          }          public void setY(Double y) {              this.y = y;          }      }
public class Test01 {         public static void main(String[] args) {               //114.331951,30.64091#114.341049,30.610185#114.331436,30.588058#114.312038,30.56393#114.293498,30.558609#114.267922,30.563784#114.231185,30.57945#114.212303,30.601616#114.235649,30.626878#114.280624,30.646818#         Map [] map=new Map[]{};         Point[] ps = new Point[] { new Point(114.309914,30.599556),//114.309914,30.599556                    new Point(114.295688,30.592879),//114.295688,30.592879                    new Point(114.292812,30.587726), //114.292812,30.587726                    new Point(114.292812,30.587726), //114.292812,30.587726                    new Point(114.30058,30.580318),//114.30058,30.580318                    new Point(114.303606,30.586959),//114.303606,30.586959                    new Point(114.304534,30.594751),//114.304534,30.594751                    new Point(114.30838,30.590131),//114.30838,30.590131                    new Point(114.308651,30.584182),//114.308651,30.584182                    new Point(114.304495,30.584015),//114.304495,30.584015                    new Point(114.301301,30.578759),//114.301301,30.578759                    new Point(114.309437,30.578528),//114.309437,30.578528                    new Point(114.323282,30.592786)};//114.323282,30.592786            Point n1 = new Point(114.303217,30.583553);              Point n2 = new Point(114.307336,30.597592);              Point n3 = new Point(114.286565,30.590056);              Point y1 = new Point(114.227342,30.587987);              Point y2 = new Point(120.1866 , 30.2672);              Point y4 = new Point(120.1869 , 30.2718);              System.out.println( "n1:" + isPtInPoly(n1.getX() , n1.getY() , ps));              System.out.println( "n2:" + isPtInPoly(n2.getX() , n2.getY() , ps));              System.out.println( "n3:" + isPtInPoly(n3.getX() , n3.getY() , ps));              System.out.println( "y1:" + isPtInPoly(y1.getX() , y1.getY() , ps));              System.out.println( "y2:" + isPtInPoly(y2.getX() , y2.getY() , ps));              System.out.println( "y4:" + isPtInPoly(y4.getX() , y4.getY() , ps));          }          public static boolean isPtInPoly (double ALon , double ALat , Point[] ps) {              int iSum, iCount, iIndex;              double dLon1 = 0, dLon2 = 0, dLat1 = 0, dLat2 = 0, dLon;              if (ps.length < 3) {                  return false;              }              iSum = 0;              iCount = ps.length;              for (iIndex = 0; iIndex
= dLat1) && (ALat < dLat2)) || ((ALat >= dLat2) && (ALat < dLat1))) { if (Math.abs(dLat1 - dLat2) > 0) { //得到 A点向左射线与边的交点的x坐标: dLon = dLon1 - ((dLon1 - dLon2) * (dLat1 - ALat) ) / (dLat1 - dLat2); // 如果交点在A点左侧(说明是做射线与 边的交点),则射线与边的全部交点数加一: if (dLon < ALon) { iSum++; } } } } if ((iSum % 2) != 0) { return true; } return false; } }

 

转载地址:http://gujaa.baihongyu.com/

你可能感兴趣的文章
【数据库】表分区
查看>>
nutz-sqltpl 1.3.4.RELEASE 发布,在 Nutz 项目中“解决 Java 拼接 SQL”问题
查看>>
城市 | 800个地铁站数据透析的京沪白领图鉴:隐形土豪、无产中产阶级和猪猪女孩...
查看>>
前端脚本!网站图片素材中文转英文
查看>>
linux的常用易忘命令
查看>>
PHP 分割字符串
查看>>
java 基于QRCode、zxing 的二维码生成与解析
查看>>
img垂直水平居中与div
查看>>
防恶意注册的思考
查看>>
C# 命名空间
查看>>
订餐系统之同步美团商家订单
查看>>
使用ArrayList时设置初始容量的重要性
查看>>
Java Web-----JSP与Servlet(一)
查看>>
Maven搭建SpringMVC+Mybatis项目详解
查看>>
CentOS 6.9通过RPM安装EPEL源(http://dl.fedoraproject.org)
查看>>
没有功能需求设计文档?对不起,拒绝开发!
查看>>
4星|《先发影响力》:影响与反影响相关的有趣的心理学研究综述
查看>>
IE8调用window.open导出EXCEL文件题目
查看>>
vue-cli脚手架的搭建
查看>>
在网页中加入百度搜索框实例代码
查看>>