|
@@ -1,15 +1,14 @@
|
|
|
-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.*;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
+package com.persagy.server.util
|
|
|
|
|
|
+import org.geotools.geometry.jts.JTSFactoryFinder
|
|
|
+import org.locationtech.jts.geom.LinearRing
|
|
|
+import cn.hutool.core.collection.CollUtil
|
|
|
+import com.fasterxml.jackson.databind.node.ObjectNode
|
|
|
+import com.persagy.server.datacenter.models.entities.assistant.PointPosition
|
|
|
+import org.locationtech.jts.geom.Coordinate
|
|
|
+import org.locationtech.jts.geom.Point
|
|
|
+import org.locationtech.jts.geom.Polygon
|
|
|
+import kotlin.collections.ArrayList
|
|
|
|
|
|
/**
|
|
|
* @ClassName GeoToolsUtil
|
|
@@ -17,74 +16,59 @@ import java.util.List;
|
|
|
* @Author linhuili
|
|
|
* @Date 2021/9/3 20:31
|
|
|
* @Version V1.0
|
|
|
- **/
|
|
|
-public class GeoToolsUtil {
|
|
|
+ */
|
|
|
+object GeoToolsUtil {
|
|
|
/**
|
|
|
* 创建点
|
|
|
* @param pointLocal
|
|
|
*/
|
|
|
- private static Point createPoint(ObjectNode pointLocal){
|
|
|
- double x =0L;
|
|
|
- double y =0L;
|
|
|
- double z =0L;
|
|
|
- if(pointLocal.get("X") != null){
|
|
|
- x =pointLocal.get("X").doubleValue();
|
|
|
+ private fun createPoint(pointLocal: ObjectNode): Point {
|
|
|
+ var x = 0.0
|
|
|
+ var y = 0.0
|
|
|
+ val z = 0.0
|
|
|
+ if (pointLocal["X"] != null) {
|
|
|
+ x = pointLocal["X"].doubleValue()
|
|
|
}
|
|
|
- if(pointLocal.get("Y") != null){
|
|
|
- y = pointLocal.get("Y").doubleValue();
|
|
|
+ if (pointLocal["Y"] != null) {
|
|
|
+ y = pointLocal["Y"].doubleValue()
|
|
|
}
|
|
|
- GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
|
|
|
- Coordinate coord = new Coordinate(x, y,z);
|
|
|
- Point point = geometryFactory.createPoint(coord);
|
|
|
- return point;
|
|
|
+ val geometryFactory = JTSFactoryFinder.getGeometryFactory()
|
|
|
+ val coord = Coordinate(x, y, z)
|
|
|
+ return geometryFactory.createPoint(coord)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建面
|
|
|
* @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);
|
|
|
+ private fun createPolygon(outLines: ArrayList<ArrayList<PointPosition>>?): Polygon {
|
|
|
+ val pointPositions = outLines?.get(0)
|
|
|
+ val geometryFactory = JTSFactoryFinder.getGeometryFactory()
|
|
|
+ val objects: MutableList<Coordinate> = ArrayList()
|
|
|
+ for (outLine in pointPositions!!) {
|
|
|
+ var x = 0.0
|
|
|
+ if(outLine.x != null){
|
|
|
+ x = outLine.x!!
|
|
|
+ }
|
|
|
+ var y = 0.0
|
|
|
+ if(outLine.y != null){
|
|
|
+ y = outLine.y!!
|
|
|
+ }
|
|
|
|
|
|
- return polygon;
|
|
|
- }
|
|
|
+ var z = 0.0
|
|
|
+ if(outLine.z!= null){
|
|
|
+ z = outLine.z!!
|
|
|
+ }
|
|
|
+ val coordinate = Coordinate(x, y, z)
|
|
|
+ objects.add(coordinate)
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 创建面
|
|
|
- * @param outLines
|
|
|
- */
|
|
|
- private static Polygon createPolygon(List<LinkedHashMap<String,Object>> outLines){
|
|
|
- GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
|
|
|
- List<Coordinate> objects = new ArrayList<>();
|
|
|
- for (LinkedHashMap<String,Object> outLine : outLines) {
|
|
|
- double x = Double.parseDouble(outLine.getOrDefault("X",0.0D).toString());
|
|
|
- double y = Double.parseDouble(outLine.getOrDefault("Y",0.0D).toString());
|
|
|
- double z = 0L;
|
|
|
- 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;
|
|
|
+ val coordinates = objects.toTypedArray()
|
|
|
+ val ring = geometryFactory.createLinearRing(coordinates)
|
|
|
+ val holes: Array<LinearRing>? = null
|
|
|
+ return geometryFactory.createPolygon(ring, holes)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -94,60 +78,16 @@ public class GeoToolsUtil {
|
|
|
* @param outLines 轮廓线
|
|
|
* @return
|
|
|
*/
|
|
|
- public static Boolean isPointInPoly(ObjectNode pointLocal, List<LinkedHashMap<String,Object>> outLines) {
|
|
|
- if (null==pointLocal || CollUtil.isEmpty(outLines)){
|
|
|
- return false;
|
|
|
+ fun isPointInPoly(pointLocal: ObjectNode?, outLines: ArrayList<ArrayList<PointPosition>>?): Boolean {
|
|
|
+ if (null == pointLocal || CollUtil.isEmpty(outLines)) {
|
|
|
+ return false
|
|
|
}
|
|
|
//创建点
|
|
|
- Point point = createPoint(pointLocal);
|
|
|
+ val point = createPoint(pointLocal)
|
|
|
//创建面
|
|
|
- Polygon polygon = createPolygon(outLines);
|
|
|
+ val polygon = createPolygon(outLines)
|
|
|
//判断点面包含关系
|
|
|
- return polygon.contains(point);
|
|
|
+ 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);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 点面包含关系判断
|
|
|
- * 用途:判断一个面是否包含一个点,即一个点是否在一个面内
|
|
|
- * @param fromOutLines: 轮廓坐标
|
|
|
- * @param toOutLines: 轮廓坐标
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static Boolean isPolyInPoly(List<LinkedHashMap<String,Object>> fromOutLines,
|
|
|
- List<LinkedHashMap<String,Object>> toOutLines) {
|
|
|
- if (CollUtil.isEmpty(fromOutLines) || CollUtil.isEmpty(toOutLines)){
|
|
|
- return false;
|
|
|
- }
|
|
|
- //创建点
|
|
|
- Polygon fromPolygon = createPolygon(fromOutLines);
|
|
|
- //创建面
|
|
|
- Polygon toPolygon = createPolygon(toOutLines);
|
|
|
- //判断面-面包含关系
|
|
|
- return fromPolygon.contains(toPolygon)
|
|
|
- || fromPolygon.equalsTopo(toPolygon)
|
|
|
- || fromPolygon.overlaps(toPolygon)
|
|
|
- || toPolygon.contains(fromPolygon);
|
|
|
- }
|
|
|
-}
|
|
|
+}
|