From e8a4f9014fbea4159ea15642226c6793d57d13ee Mon Sep 17 00:00:00 2001
From: Administrator <1144154118@qq.com>
Date: 星期二, 22 八月 2023 11:05:44 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ard-work/src/main/java/com/ruoyi/utils/tools/GisTool.java | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 109 insertions(+), 0 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/utils/tools/GisTool.java b/ard-work/src/main/java/com/ruoyi/utils/tools/GisTool.java
index 661fd91..48c156f 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/tools/GisTool.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/tools/GisTool.java
@@ -4,6 +4,10 @@
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GlobalCoordinates;
+import java.awt.geom.Point2D;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* @Description:
* @ClassName: GisTool
@@ -29,4 +33,109 @@
GlobalCoordinates target = new GlobalCoordinates(latitudeTo, longitudeTo);
return geodeticCalculator.calculateGeodeticCurve(Ellipsoid.WGS84, source, target).getEllipsoidalDistance();
}
+
+ public static void main(String[] args) {
+// // 琚娴嬬殑缁忕含搴︾偣
+// Point point= new Point(126.649261,45.687377);
+// // 鍟嗕笟鍖哄煙锛堢櫨搴﹀杈瑰舰鍖哄煙缁忕含搴﹂泦鍚堬級
+// List<Point> partitionLocation = new ArrayList<>();
+// partitionLocation.add(new Point(126.64459,45.688548));
+// partitionLocation.add(new Point(126.653376,45.68938));
+// partitionLocation.add(new Point(126.645776,45.685048));
+// partitionLocation.add(new Point(126.654184,45.685778));
+// System.out.println(isInPolygon(point,partitionLocation));
+ }
+
+ /**
+ * 鍒ゆ柇褰撳墠浣嶇疆鏄惁鍦ㄥ杈瑰舰鍖哄煙鍐�
+ * @param orderLocation 褰撳墠鐐�
+ * @param partitionLocation 鍖哄煙椤剁偣
+ * @return
+ */
+ public static boolean isInPolygon(Point orderLocation,List<Point> partitionLocation){
+
+ double p_x =orderLocation.getLongitude();
+ double p_y =orderLocation.getLatitude();
+ Point2D.Double point = new Point2D.Double(p_x, p_y);
+
+ List<Point2D.Double> pointList= new ArrayList<Point2D.Double>();
+
+ for (Point points : partitionLocation){
+ double polygonPoint_x=points.getLongitude();
+ double polygonPoint_y=points.getLatitude();
+ Point2D.Double polygonPoint = new Point2D.Double(polygonPoint_x,polygonPoint_y);
+ pointList.add(polygonPoint);
+ }
+ return IsPtInPoly(point,pointList);
+ }
+ /**
+ * 鍒ゆ柇鐐规槸鍚﹀湪澶氳竟褰㈠唴锛屽鏋滅偣浣嶄簬澶氳竟褰㈢殑椤剁偣鎴栬竟涓婏紝涔熺畻鍋氱偣鍦ㄥ杈瑰舰鍐咃紝鐩存帴杩斿洖true
+ * @param point 妫�娴嬬偣
+ * @param pts 澶氳竟褰㈢殑椤剁偣
+ * @return 鐐瑰湪澶氳竟褰㈠唴杩斿洖true,鍚﹀垯杩斿洖false
+ */
+ public static boolean IsPtInPoly(Point2D.Double point, List<Point2D.Double> pts){
+
+ int N = pts.size();
+ boolean boundOrVertex = true; //濡傛灉鐐逛綅浜庡杈瑰舰鐨勯《鐐规垨杈逛笂锛屼篃绠楀仛鐐瑰湪澶氳竟褰㈠唴锛岀洿鎺ヨ繑鍥瀟rue
+ int intersectCount = 0;//cross points count of x
+ double precision = 2e-10; //娴偣绫诲瀷璁$畻鏃跺�欎笌0姣旇緝鏃跺�欑殑瀹瑰樊
+ Point2D.Double p1, p2;//neighbour bound vertices
+ Point2D.Double p = point; //褰撳墠鐐�
+
+ p1 = pts.get(0);//left vertex
+ for(int i = 1; i <= N; ++i){//check all rays
+ if(p.equals(p1)){
+ return boundOrVertex;//p is an vertex
+ }
+
+ p2 = pts.get(i % N);
+ if(p.x < Math.min(p1.x, p2.x) || p.x > Math.max(p1.x, p2.x)){
+ p1 = p2;
+ continue;
+ }
+
+ if(p.x > Math.min(p1.x, p2.x) && p.x < Math.max(p1.x, p2.x)){
+ if(p.y <= Math.max(p1.y, p2.y)){
+ if(p1.x == p2.x && p.y >= Math.min(p1.y, p2.y)){
+ return boundOrVertex;
+ }
+
+ if(p1.y == p2.y){
+ if(p1.y == p.y){
+ return boundOrVertex;
+ }else{//before ray
+ ++intersectCount;
+ }
+ }else{
+ double xinters = (p.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
+ if(Math.abs(p.y - xinters) < precision){
+ return boundOrVertex;
+ }
+
+ if(p.y < xinters){
+ ++intersectCount;
+ }
+ }
+ }
+ }else{
+ if(p.x == p2.x && p.y <= p2.y){
+ Point2D.Double p3 = pts.get((i+1) % N);
+ if(p.x >= Math.min(p1.x, p3.x) && p.x <= Math.max(p1.x, p3.x)){
+ ++intersectCount;
+ }else{
+ intersectCount += 2;
+ }
+ }
+ }
+ p1 = p2;
+ }
+
+ if(intersectCount % 2 == 0){//鍋舵暟鍦ㄥ杈瑰舰澶�
+ return false;
+ } else { //濂囨暟鍦ㄥ杈瑰舰鍐�
+ return true;
+ }
+ }
+
}
--
Gitblit v1.9.3