From c40f8e3d2e08e108780091776437242528bf61d6 Mon Sep 17 00:00:00 2001
From: 101captain <237651143@qq.com>
Date: 星期三, 20 七月 2022 17:44:56 +0800
Subject: [PATCH] bug修改
---
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/LngLatUtils.java | 47 ++++++++++++++++++++++++++++-------------------
1 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/LngLatUtils.java b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/LngLatUtils.java
index 98b013a..56eec9c 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/LngLatUtils.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/LngLatUtils.java
@@ -1,23 +1,21 @@
package com.panzhihua.common.utlis;
-import com.panzhihua.common.model.vos.grid.LatLngVO;
-
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
+import com.panzhihua.common.model.vos.grid.LatLngVO;
+
public class LngLatUtils {
- public static boolean check(Point2D.Double _point, List<Point2D.Double> polygon)
- {
+ public static boolean check(Point2D.Double _point, List<Point2D.Double> polygon) {
java.awt.geom.GeneralPath peneralPath = new java.awt.geom.GeneralPath();
Point2D.Double first = polygon.get(0);
peneralPath.moveTo(first.x, first.y);
polygon.remove(0);
- for(Point2D.Double d : polygon)
- {
+ for (Point2D.Double d : polygon) {
peneralPath.lineTo(d.x, d.y);
}
@@ -27,8 +25,17 @@
return peneralPath.contains(_point);
}
- public static boolean isInPolygon(List<LatLngVO> bound, double pointlng, double pointLat)
- {
+ /**
+ *
+ * @param bound
+ * 经纬度数组
+ * @param pointlng
+ * 短
+ * @param pointLat
+ * 长
+ * @return
+ */
+ public static boolean isInPolygon(List<LatLngVO> bound, double pointlng, double pointLat) {
Point2D.Double point = new Point2D.Double(pointlng, pointLat);
List<Point2D.Double> pointList = new ArrayList<>();
for (int i = 0; i < bound.size(); i++) {
@@ -39,27 +46,29 @@
/**
* 从txt数据中获取经纬度
- * @param latlngTxt
+ *
+ * @param lngLatTxt
* @return
*/
- public static List<LatLngVO> getLatLngFromText(String latlngTxt){
+ public static List<LatLngVO> getLatLngFromText(String lngLatTxt) {
List<LatLngVO> rtResult = new ArrayList<>();
- String str = latlngTxt.replace("[[","");
+ String str = lngLatTxt.replace("[[", "");
- str=str.replace("]]","");
- String[] loca=str.split("],\\[");
- for (int i=0;i<loca.length;i++)
- {
- String[] loca1=loca[i].split(",");
- rtResult.add(new LatLngVO(Double.valueOf(loca1[1]), Double.valueOf(loca1[0])));
+ str = str.replace("]]", "");
+ String[] loca = str.split("],\\[");
+ for (int i = 0; i < loca.length; i++) {
+ String[] loca1 = loca[i].split(",");
+ rtResult.add(new LatLngVO(Double.valueOf(loca1[0]), Double.valueOf(loca1[1])));
}
return rtResult;
}
public static void main(String[] args) {
- String latLngTxt = "[[104.065958,30.662621],[104.06419,30.663172],[104.06315,30.660648],[104.065548,30.661036]]";
+ String latLngTxt =
+ "[[104.066974,30.660293],[104.053394,30.658114],[104.059921,30.657076],[104.065231,30.657086]]";
List<LatLngVO> latLngList = getLatLngFromText(latLngTxt);
- System.out.println(isInPolygon(latLngList, 104.0612, 30.6608));
+
+ System.out.println(isInPolygon(latLngList, 104.063398, 30.657929));
}
}
--
Gitblit v1.7.1