Explorar el Código

无效线检查加入线gis包含点gis判断

欧阳劲驰 hace 1 mes
padre
commit
2bbd1fd787

+ 80 - 0
src/main/java/com/shkpr/service/alambizplugin/commtools/GeomUtil.java

@@ -3,6 +3,10 @@ package com.shkpr.service.alambizplugin.commtools;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
+import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyLine;
+import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyPoint;
+import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckDefine;
+import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckDeviation;
 import org.geotools.referencing.CRS;
 import org.geotools.referencing.GeodeticCalculator;
 import org.locationtech.jts.geom.Coordinate;
@@ -10,10 +14,15 @@ import org.locationtech.jts.geom.Envelope;
 import org.locationtech.jts.geom.GeometryFactory;
 import org.locationtech.jts.geom.Polygon;
 import org.locationtech.jts.util.GeometricShapeFactory;
+import org.locationtech.jts.util.NumberUtil;
 import org.opengis.referencing.FactoryException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.TransformException;
 
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
 /**
  * 地理工具类
  *
@@ -35,6 +44,77 @@ public class GeomUtil {
      */
     private final static GeometricShapeFactory shapeFactory = new GeometricShapeFactory(geometryFactory);
 
+
+    /**
+     * 获取公差
+     *
+     * @param define   系统检查定义
+     * @param property 属性
+     * @return 公差
+     */
+    public static double getTolerance(GisSurveySystemCheckDefine define, String property) {
+        //偏差集合
+        List<GisSurveySystemCheckDeviation> deviations = define != null ? define.getDeviation() : Collections.emptyList();
+        //匹配属性
+        return deviations.stream()
+                .filter(deviation -> Objects.equals(property, deviation.getProperty()))
+                .map(GisSurveySystemCheckDeviation::getTolerance)
+                .findFirst().orElse(0d);
+    }
+
+    /**
+     * 计算包含
+     *
+     * @param line         线
+     * @param point        点
+     * @param lngTolerance 经度公差
+     * @param latTolerance 纬度公差
+     * @return 包含关系
+     */
+    public static Boolean calcContain(GisSurveyLayerApplyLine line, GisSurveyLayerApplyPoint point, double lngTolerance, double latTolerance) {
+        //上节点判断
+        if (Objects.equals(point.getCode(), line.getUpNode())) {
+            //线坐标
+            Coordinate lineCcoordinate = line.getGis().getCoordinateN(0);
+            //点坐标
+            Coordinate pointCoordinate = point.getGis().getCoordinate();
+            //比较x和y
+            return NumberUtil.equalsWithTolerance(lineCcoordinate.x, pointCoordinate.x, lngTolerance) &&
+                    NumberUtil.equalsWithTolerance(lineCcoordinate.y, pointCoordinate.y, latTolerance);
+
+        }
+        //下节点判断
+        if (Objects.equals(point.getCode(), line.getDownNode())) {
+            //线坐标
+            Coordinate lineCcoordinate = line.getGis().getCoordinateN(line.getGis().getCoordinates().length - 1);
+            //点坐标
+            Coordinate pointCoordinate = point.getGis().getCoordinate();
+            //比较x和y
+            return NumberUtil.equalsWithTolerance(lineCcoordinate.x, pointCoordinate.x, lngTolerance) &&
+                    NumberUtil.equalsWithTolerance(lineCcoordinate.y, pointCoordinate.y, latTolerance);
+        }
+        return false;
+    }
+
+    /**
+     * 计算长度
+     *
+     * @param coordinate1 坐标1
+     * @param coordinate2 坐标2
+     * @return 长度
+     */
+    public static double calcLength(Coordinate coordinate1, Coordinate coordinate2) {
+        double x1 = coordinate1.getX();
+        double y1 = coordinate1.getY();
+        double x2 = coordinate2.getX();
+        double y2 = coordinate2.getY();
+        //计算差
+        double dx = Math.abs(x1 - x2);
+        double dy = Math.abs(y1 - y2);
+        //计算长
+        return Math.sqrt(dx * dx + dy * dy);
+    }
+
     /**
      * 创建圆
      *

+ 6 - 2
src/main/java/com/shkpr/service/alambizplugin/components/GisSurveySystemChecker.java

@@ -155,6 +155,10 @@ public class GisSurveySystemChecker {
             GisSurveySystemCheckDefine isolatedPointsDefine = systemCheckDefines.stream().
                     filter(it -> Objects.equals(GisSurveySystemCheckKeys.ISOLATED_POINTS, it.getKey()))
                     .findFirst().orElse(null);
+            //无效线定义
+            GisSurveySystemCheckDefine invalidLinesDefine = systemCheckDefines.stream().
+                    filter(it -> Objects.equals(GisSurveySystemCheckKeys.INVALID_LINES, it.getKey()))
+                    .findFirst().orElse(null);
             //重复点定义
             GisSurveySystemCheckDefine duplicatePointsDefine = systemCheckDefines.stream().
                     filter(it -> Objects.equals(GisSurveySystemCheckKeys.DUPLICATE_POINTS, it.getKey()))
@@ -172,14 +176,14 @@ public class GisSurveySystemChecker {
             //孤立点检查
             if (points != null && lines != null) {
                 if (params.getStartSubitemKeys().contains(GisSurveySystemCheckKeys.ISOLATED_POINTS)) {
-                    isolatedPointsFuture = isolatedPointsFinder.findIsolatedPoints(points, lines, isolatedPointsDefine,systemCheckId);
+                    isolatedPointsFuture = isolatedPointsFinder.findIsolatedPoints(points, lines, isolatedPointsDefine, systemCheckId);
                     subtask.put(GisSurveySystemCheckKeys.ISOLATED_POINTS, isolatedPointsFuture);
                 }
             }
             //无效线检查
             if (points != null && lines != null) {
                 if (params.getStartSubitemKeys().contains(GisSurveySystemCheckKeys.INVALID_LINES)) {
-                    invalidLinesFuture = invalidLinesFinder.finderInvalidLines(points, lines, systemCheckId);
+                    invalidLinesFuture = invalidLinesFinder.finderInvalidLines(points, lines, invalidLinesDefine, systemCheckId);
                     subtask.put(GisSurveySystemCheckKeys.INVALID_LINES, invalidLinesFuture);
                 }
             }

+ 36 - 22
src/main/java/com/shkpr/service/alambizplugin/components/checker/InvalidLinesFinder.java

@@ -4,6 +4,7 @@ import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.google.common.collect.Lists;
 import com.shkpr.service.alambizplugin.commtools.BeanUtil;
+import com.shkpr.service.alambizplugin.commtools.GeomUtil;
 import com.shkpr.service.alambizplugin.commtools.ThirdImportTemplateUtils;
 import com.shkpr.service.alambizplugin.components.AsyncResultManager;
 import com.shkpr.service.alambizplugin.components.GisSurveyThirdImporter;
@@ -11,20 +12,14 @@ import com.shkpr.service.alambizplugin.constants.GisMetadataDefine;
 import com.shkpr.service.alambizplugin.constants.GisSurveyExcelDefine;
 import com.shkpr.service.alambizplugin.constants.GisSurveySystemCheckKeys;
 import com.shkpr.service.alambizplugin.constants.GisSurveySystemCheckResultHead;
+import com.shkpr.service.alambizplugin.constants.GisSurveyTemplateDefine;
 import com.shkpr.service.alambizplugin.constants.GisSurveyThirdImportKeys;
 import com.shkpr.service.alambizplugin.constants.GisSurveyThirdImportResultHead;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
-import com.shkpr.service.alambizplugin.dto.GisMetadataLayerTemplate;
-import com.shkpr.service.alambizplugin.dto.GisMetadataPropertyTemplate;
-import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyLine;
-import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyPoint;
-import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckElement;
-import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckId;
-import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckResultDetail;
-import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportElement;
-import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportResultDetail;
+import com.shkpr.service.alambizplugin.dto.*;
 import com.shkpr.service.alambizplugin.exception.UncheckedInterruptedException;
 import org.apache.commons.lang3.StringUtils;
+import org.locationtech.jts.geom.Coordinate;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.AsyncResult;
 import org.springframework.stereotype.Component;
@@ -182,7 +177,12 @@ public class InvalidLinesFinder {
      */
     @Async
     public ListenableFuture<GisSurveySystemCheckResultDetail> finderInvalidLines(
-            List<GisSurveyLayerApplyPoint> points, List<GisSurveyLayerApplyLine> lines, GisSurveySystemCheckId systemCheckId) {
+            List<GisSurveyLayerApplyPoint> points, List<GisSurveyLayerApplyLine> lines,
+            GisSurveySystemCheckDefine define, GisSurveySystemCheckId systemCheckId) {
+        //经纬度公差
+        double lngTolerance = GeomUtil.getTolerance(define, GisSurveyTemplateDefine.LNG);
+        double latTolerance = GeomUtil.getTolerance(define, GisSurveyTemplateDefine.LAT);
+
         LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行寻找无效线   ======>");
         long begin = System.currentTimeMillis();
 
@@ -202,29 +202,43 @@ public class InvalidLinesFinder {
         //如线为空,则无无效线
         if (lines.isEmpty())
             return new AsyncResult<>(createSystemCheckResult(Lists.newArrayList(), systemCheckId, begin));
-
-        //点编码集合
-        Set<String> pointCodes = points.parallelStream()
+        //联通点
+        Map<String, GisSurveyLayerApplyPoint> connectedPoints = points.parallelStream()
                 //响应中断
                 .peek(line -> {
                     if (Thread.currentThread().isInterrupted())
                         throw new UncheckedInterruptedException(new InterruptedException());
                 })
-                //获取点号,并去重
-                .map(GisSurveyLayerApplyPoint::getCode)
-                .filter(Objects::nonNull)
-                .collect(Collectors.toSet());
-
-        //并行流寻找重复点号
+                .filter(point -> Objects.nonNull(point) && Objects.nonNull(point.getCode()))
+                //获取点编码
+                .collect(Collectors.toMap(GisSurveyLayerApplyPoint::getCode, point -> point));
+        //并行流寻找无效线
         List<GisSurveySystemCheckElement> elements = lines.parallelStream()
                 //响应中断
                 .peek(line -> {
                     if (Thread.currentThread().isInterrupted())
                         throw new UncheckedInterruptedException(new InterruptedException());
                 })
-                //过滤上下游节点都不在点集合中
-                .filter(line -> !pointCodes.contains(line.getUpNode())
-                        || !pointCodes.contains(line.getDownNode()))
+                //过滤无效线
+                .filter(line -> {
+                    //线格式判断
+                    if (line.getGis() == null || line.getGis().getCoordinates().length < 2 ||
+                            StringUtils.isAnyBlank(line.getUpNode(), line.getDownNode())) return true;
+                    //判断下游节点不存在
+                    if (!connectedPoints.containsKey(line.getUpNode()) || !connectedPoints.containsKey(line.getDownNode()))
+                        return true;
+                    //判断上游节点gis包含
+                    GisSurveyLayerApplyPoint upPoint = connectedPoints.get(line.getUpNode());
+                    if (!GeomUtil.calcContain(line, upPoint, lngTolerance, latTolerance)) return true;
+                    //判断下游节点gis包含
+                    GisSurveyLayerApplyPoint downPoint = connectedPoints.get(line.getDownNode());
+                    if (!GeomUtil.calcContain(line, downPoint, lngTolerance, latTolerance)) return true;
+                    //线坐标
+                    Coordinate[] coordinates = line.getGis().getCoordinates();
+                    //判断线长度小于误差
+                    return Math.sqrt(lngTolerance * lngTolerance + latTolerance * latTolerance) >=
+                            GeomUtil.calcLength(coordinates[0], coordinates[coordinates.length - 1]);
+                })
                 .map(line -> BeanUtil.copy(line, GisSurveySystemCheckElement.class))
                 .collect(Collectors.toList());
 

+ 8 - 52
src/main/java/com/shkpr/service/alambizplugin/components/checker/IsolatedPointsFinder.java

@@ -4,6 +4,7 @@ package com.shkpr.service.alambizplugin.components.checker;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.commtools.BeanUtil;
+import com.shkpr.service.alambizplugin.commtools.GeomUtil;
 import com.shkpr.service.alambizplugin.components.AsyncResultManager;
 import com.shkpr.service.alambizplugin.constants.GisSurveySystemCheckKeys;
 import com.shkpr.service.alambizplugin.constants.GisSurveySystemCheckResultHead;
@@ -12,13 +13,10 @@ import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyLine;
 import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyPoint;
 import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckDefine;
-import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckDeviation;
 import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckElement;
 import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckId;
 import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckResultDetail;
 import com.shkpr.service.alambizplugin.exception.UncheckedInterruptedException;
-import org.locationtech.jts.geom.Coordinate;
-import org.locationtech.jts.util.NumberUtil;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.AsyncResult;
 import org.springframework.stereotype.Component;
@@ -65,17 +63,9 @@ public class IsolatedPointsFinder {
     @Async
     public ListenableFuture<GisSurveySystemCheckResultDetail> findIsolatedPoints(List<GisSurveyLayerApplyPoint> points
             , List<GisSurveyLayerApplyLine> lines, GisSurveySystemCheckDefine define, GisSurveySystemCheckId systemCheckId) throws InterruptedException {
-        //偏差集合
-        List<GisSurveySystemCheckDeviation> deviations = define != null ? define.getDeviation() : Collections.emptyList();
         //经纬度公差
-        double lngTolerance = deviations.stream()
-                .filter(deviation -> Objects.equals(GisSurveyTemplateDefine.LNG, deviation.getProperty()))
-                .map(GisSurveySystemCheckDeviation::getTolerance)
-                .findFirst().orElse(0d);
-        double latTolerance = deviations.stream()
-                .filter(deviation -> Objects.equals(GisSurveyTemplateDefine.LAT, deviation.getProperty()))
-                .map(GisSurveySystemCheckDeviation::getTolerance)
-                .findFirst().orElse(0d);
+        double lngTolerance = GeomUtil.getTolerance(define, GisSurveyTemplateDefine.LNG);
+        double latTolerance = GeomUtil.getTolerance(define, GisSurveyTemplateDefine.LAT);
 
         LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行寻找孤立点========>");
         long begin = System.currentTimeMillis();
@@ -98,8 +88,8 @@ public class IsolatedPointsFinder {
             if (lines.isEmpty()) return new AsyncResult<>(createResult(Collections.emptyList(), systemCheckId, begin));
             //点为空,则无孤立点
             if (points.isEmpty()) return new AsyncResult<>(createResult(Collections.emptyList(), systemCheckId, begin));
-            //联通线关系
-            Map<String, List<GisSurveyLayerApplyLine>> connectedPoints = lines.parallelStream()
+            //联通线
+            Map<String, List<GisSurveyLayerApplyLine>> connectedLines = lines.parallelStream()
                     //响应中断
                     .peek(it -> {
                         if (Thread.currentThread().isInterrupted())
@@ -128,10 +118,10 @@ public class IsolatedPointsFinder {
                     //过滤连通点
                     .filter(point -> {
                         //判断是否和线连通
-                        if (!connectedPoints.containsKey(point.getCode())) return true;
+                        if (!connectedLines.containsKey(point.getCode())) return true;
                         //遍历连通的线,判断是否有包含关系
-                        return connectedPoints.get(point.getCode()).stream()
-                                .noneMatch(line -> calcContain(line, point, lngTolerance, latTolerance));
+                        return connectedLines.get(point.getCode()).stream()
+                                .noneMatch(line -> GeomUtil.calcContain(line, point, lngTolerance, latTolerance));
                     })
                     //转为返回元素
                     .map(point -> BeanUtil.copy(point, GisSurveySystemCheckElement.class))
@@ -143,40 +133,6 @@ public class IsolatedPointsFinder {
     }
 
     /**
-     * 计算包含
-     *
-     * @param line         线
-     * @param point        点
-     * @param lngTolerance 经度公差
-     * @param latTolerance 纬度公差
-     * @return 包含关系
-     */
-    private Boolean calcContain(GisSurveyLayerApplyLine line, GisSurveyLayerApplyPoint point, double lngTolerance, double latTolerance) {
-        //上节点判断
-        if (Objects.equals(point.getCode(), line.getUpNode())) {
-            //线坐标
-            Coordinate lineCcoordinate = line.getGis().getCoordinateN(0);
-            //点坐标
-            Coordinate pointCoordinate = point.getGis().getCoordinate();
-            //比较x和y
-            return NumberUtil.equalsWithTolerance(lineCcoordinate.x, pointCoordinate.x, lngTolerance) &&
-                    NumberUtil.equalsWithTolerance(lineCcoordinate.y, pointCoordinate.y, latTolerance);
-
-        }
-        //下节点判断
-        if (Objects.equals(point.getCode(), line.getDownNode())) {
-            //线坐标
-            Coordinate lineCcoordinate = line.getGis().getCoordinateN(line.getGis().getCoordinates().length - 1);
-            //点坐标
-            Coordinate pointCoordinate = point.getGis().getCoordinate();
-            //比较x和y
-            return NumberUtil.equalsWithTolerance(lineCcoordinate.x, pointCoordinate.x, lngTolerance) &&
-                    NumberUtil.equalsWithTolerance(lineCcoordinate.y, pointCoordinate.y, latTolerance);
-        }
-        return false;
-    }
-
-    /**
      * 创建结果
      *
      * @param data          数据