Sfoglia il codice sorgente

重叠线增加完全重叠分组处理,如完全重叠则全分为一组,否则两两分组

欧阳劲驰 1 mese fa
parent
commit
9e4c890b33

+ 51 - 5
src/main/java/com/shkpr/service/alambizplugin/components/checker/OverlapLinesFinder.java

@@ -11,6 +11,7 @@ import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyLine;
 import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckElement;
 import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckId;
 import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckResultDetail;
+import org.apache.commons.collections4.CollectionUtils;
 import org.locationtech.jts.algorithm.Orientation;
 import org.locationtech.jts.geom.Coordinate;
 import org.locationtech.jts.geom.LineSegment;
@@ -59,7 +60,8 @@ public class OverlapLinesFinder {
     /**
      * 寻找重叠线
      * <p>返回的为重叠线组,未重叠的线不会出现在返回结果</p>
-     * <p>一组线,仅为两条重叠的线,长度固定为2</p>
+     * <p>一组线,仅为两条重叠的线</p>
+     * <p>如完全重叠,则全分为一组,会出现多条线一组的情况</p>
      *
      * @param lines 线集合
      * @return 重叠线分组
@@ -84,11 +86,18 @@ public class OverlapLinesFinder {
         List<List<GisSurveySystemCheckElement>> groupElements = new ArrayList<>();
         //处理过的code
         Set<String> processedCodes = new HashSet<>();
+        //完全重叠过的code
+        Set<String> fullOverlapCodes = new HashSet<>();
+
         //遍历所有线
         for (GisSurveyLayerApplyLine line1 : lines) {
             if (line1.getGis() == null) continue;
             //响应中断
             if (Thread.interrupted()) throw new InterruptedException();
+
+            //完全重叠组
+            List<GisSurveySystemCheckElement> fullOverlaps = new ArrayList<>();
+
             //查询索引内元素
             List<?> candidates = tree.query(line1.getGis().getEnvelopeInternal());
             for (Object candidate : candidates) {
@@ -100,8 +109,14 @@ public class OverlapLinesFinder {
                 ) continue;
                 //响应中断
                 if (Thread.interrupted()) throw new InterruptedException();
-                // 判断是否重叠
-                if (calcOverlapLines(line1, line2)) {
+                //判断是否完全重叠(两线都未被标记过)
+                if (!fullOverlapCodes.contains(line1.getCode())
+                        && !fullOverlapCodes.contains(line2.getCode())
+                        && calcFullOverlap(line1, line2)) {
+                    fullOverlaps.add(BeanUtil.copy(line2, GisSurveySystemCheckElement.class));
+                }
+                //判断是否部分重叠(排除完全重叠)
+                if (!calcFullOverlap(line1, line2) && calcPartialOverlap(line1, line2)) {
                     // 创建两两一组的重叠线对
                     groupElements.add(Arrays.asList(
                             BeanUtil.copy(line1, GisSurveySystemCheckElement.class),
@@ -109,6 +124,19 @@ public class OverlapLinesFinder {
                     ));
                 }
             }
+
+            //如完全重叠组不为空,则存入结果
+            if (CollectionUtils.isNotEmpty(fullOverlaps)) {
+                //存入自身
+                fullOverlaps.add(BeanUtil.copy(line1, GisSurveySystemCheckElement.class));
+                //填入结果
+                groupElements.add(fullOverlaps);
+                //标记完全重叠
+                fullOverlapCodes.addAll(fullOverlaps.stream()
+                        .map(GisSurveySystemCheckElement::getCode)
+                        .collect(Collectors.toSet())
+                );
+            }
             //存入code,避免重复处理
             processedCodes.add(line1.getCode());
         }
@@ -116,14 +144,32 @@ public class OverlapLinesFinder {
         return new AsyncResult<>(createResult(groupElements, systemCheckId, begin));
     }
 
+
+    /**
+     * 计算完全重叠
+     *
+     * @param line1 线段1
+     * @param line2 线段2
+     * @return 重叠状态
+     */
+    public boolean calcFullOverlap(GisSurveyLayerApplyLine line1, GisSurveyLayerApplyLine line2) {
+        //取出四个点
+        Coordinate a = line1.getGis().getCoordinateN(0);
+        Coordinate b = line1.getGis().getCoordinateN(1);
+        Coordinate c = line2.getGis().getCoordinateN(0);
+        Coordinate d = line2.getGis().getCoordinateN(1);
+        if (a == null || b == null || c == null || d == null) return false;
+        return (a.equals2D(c) && b.equals2D(d)) || (a.equals2D(d) && b.equals2D(c));
+    }
+
     /**
-     * 计算重叠线
+     * 计算部分重叠线
      *
      * @param line1 线段1
      * @param line2 线段2
      * @return 重叠状态
      */
-    public boolean calcOverlapLines(GisSurveyLayerApplyLine line1, GisSurveyLayerApplyLine line2) {
+    public boolean calcPartialOverlap(GisSurveyLayerApplyLine line1, GisSurveyLayerApplyLine line2) {
         //取出四个点
         Coordinate a = line1.getGis().getCoordinateN(0);
         Coordinate b = line1.getGis().getCoordinateN(1);