Browse Source

fix bug:计算空间状态变化状态state失败的问题

lijie 3 years ago
parent
commit
4db0c3e1d8

+ 26 - 16
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/common/utils/SpaceAffectUtil.kt

@@ -18,7 +18,10 @@ import org.apache.commons.collections4.CollectionUtils
 import org.apache.commons.lang3.StringUtils
 import org.geotools.geometry.jts.JTSFactoryFinder
 import org.locationtech.jts.geom.Coordinate
+import org.locationtech.jts.geom.GeometryFactory
+import org.locationtech.jts.geom.LinearRing
 import org.locationtech.jts.geom.Polygon
+import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Component
 import java.util.*
@@ -34,6 +37,11 @@ import kotlin.collections.ArrayList
 @Component
 class SpaceAffectUtil {
 
+    companion object {
+        // 日志
+        private val logger = LoggerFactory.getLogger(SpaceAffectUtil::class.java)
+    } // Companion object
+
     @Autowired
     private val service: DataCenterRequest? = null
 
@@ -104,9 +112,7 @@ class SpaceAffectUtil {
                         break
                     }
                 }
-
             }
-
         }
         if (CollectionUtils.isEmpty(affectList)) {
             return null
@@ -114,9 +120,12 @@ class SpaceAffectUtil {
         // 与有变化的元空间有交集的空间
         val rsList: MutableList<DCSpace?> = ArrayList()
         for (space in spaces!!) {
+            if (space!!.outline.isNullOrEmpty()){
+                continue
+            }
             out@
             for (outLines in space!!.outline!!) {
-                for (subOutLine in outLines){
+                for (subOutLine in outLines!!){
                     val polygon = createPolygonV2(subOutLine)
                     // 有交集则加入有变化的空间列表
                     for(affect in affectList) {
@@ -141,7 +150,7 @@ class SpaceAffectUtil {
      * @param toOutLines: 轮廓坐标
      * @return
      */
-    fun isGeoContains(fromPolygon: Polygon, toPolygon: Polygon): Boolean {
+    fun isGeoContains(fromPolygon: Polygon?, toPolygon: Polygon?): Boolean {
         if (fromPolygon == null || toPolygon == null) {
             return false
         }
@@ -156,33 +165,34 @@ class SpaceAffectUtil {
      * 创建平面对象
      * @param list 轮廓线
      */
-    private fun createPolygon(list: ArrayList<ArrayList<Point>>?): Polygon {
+    private fun createPolygonV2(list: ArrayList<Point>?): Polygon? {
         val geometryFactory = JTSFactoryFinder.getGeometryFactory()
-        val objects: MutableList<Coordinate> = ArrayList()
-        for (outLines in list!!) {
-            for(point in outLines!!) {
-                objects.add(Coordinate(point.x, point.y, point.z))
+        var ring: LinearRing? =null
+        try {
+            try {
+                ring = createRing(geometryFactory,list)
+            }catch (ingroed:IllegalArgumentException){
+                list!!.add(list[0])
+                ring = createRing(geometryFactory,list)
             }
+        }catch (e:Exception){}
+        if (null==ring){
+            return null
         }
-        //注意数据的闭合
-        val coordinates = objects.toTypedArray()
-        val ring = geometryFactory.createLinearRing(coordinates)
         return geometryFactory.createPolygon(ring, null)
     }
     /**
      * 创建平面对象
      * @param list 轮廓线
      */
-    private fun createPolygonV2(list: ArrayList<Point>?): Polygon {
-        val geometryFactory = JTSFactoryFinder.getGeometryFactory()
+    private fun createRing(geometryFactory: GeometryFactory, list: ArrayList<Point>?): LinearRing {
         val objects: MutableList<Coordinate> = ArrayList()
         for (point in list!!) {
             objects.add(Coordinate(point.x, point.y, point.z))
         }
         //注意数据的闭合
         val coordinates = objects.toTypedArray()
-        val ring = geometryFactory.createLinearRing(coordinates)
-        return geometryFactory.createPolygon(ring, null)
+        return geometryFactory.createLinearRing(coordinates)
     }
 
     /**