|
@@ -2,6 +2,7 @@ package com.persagy.server.util;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
+import com.persagy.server.datacenter.models.entities.assistant.PointPosition;
|
|
|
import org.geotools.geometry.jts.JTSFactoryFinder;
|
|
|
import org.locationtech.jts.geom.*;
|
|
|
|
|
@@ -42,6 +43,31 @@ public class GeoToolsUtil {
|
|
|
* 创建面
|
|
|
* @param outLines
|
|
|
*/
|
|
|
+ private static Polygon createPolygon(ArrayList<ArrayList<PointPosition>> outLines){
|
|
|
+ ArrayList<PointPosition> pointPositions = outLines.get(0);
|
|
|
+ GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
|
|
|
+ List<Coordinate> objects = new ArrayList<>();
|
|
|
+ for (PointPosition outLine : pointPositions) {
|
|
|
+ double x = outLine.getX();
|
|
|
+ double y = outLine.getY();
|
|
|
+ double z = outLine.getZ();
|
|
|
+ Coordinate coordinate = new Coordinate(x, y, z);
|
|
|
+ objects.add(coordinate);
|
|
|
+ }
|
|
|
+ //注意数据的闭合
|
|
|
+ Coordinate[] coordinates = objects.toArray(new Coordinate[0]);
|
|
|
+ LinearRing ring = geometryFactory.createLinearRing(coordinates);
|
|
|
+ LinearRing holes[] = null;
|
|
|
+ Polygon polygon = geometryFactory.createPolygon(ring, holes);
|
|
|
+
|
|
|
+ return polygon;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建面
|
|
|
+ * @param outLines
|
|
|
+ */
|
|
|
private static Polygon createPolygon(List<LinkedHashMap<String,Object>> outLines){
|
|
|
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
|
|
|
List<Coordinate> objects = new ArrayList<>();
|
|
@@ -79,6 +105,29 @@ public class GeoToolsUtil {
|
|
|
//判断点面包含关系
|
|
|
return polygon.contains(point);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 点面包含关系判断
|
|
|
+ * 用途:判断一个面是否包含一个点,即一个点是否在一个面内
|
|
|
+ * @param pointLocal 坐标点
|
|
|
+ * @param outLines 轮廓线
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Boolean isPointInPoly(ObjectNode pointLocal, ArrayList<ArrayList<PointPosition>> outLines) {
|
|
|
+ if (null==pointLocal || CollUtil.isEmpty(outLines)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //创建点
|
|
|
+ Point point = createPoint(pointLocal);
|
|
|
+ //创建面
|
|
|
+ Polygon polygon = createPolygon(outLines);
|
|
|
+ //判断点面包含关系
|
|
|
+ return polygon.contains(point);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 点面包含关系判断
|
|
|
* 用途:判断一个面是否包含一个点,即一个点是否在一个面内
|