|
@@ -16,17 +16,31 @@ import com.sybotan.service.models.requests.SQueryRequest
|
|
|
import com.sybotan.service.models.responses.SQueryResponse
|
|
|
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.Polygon
|
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
|
import org.springframework.stereotype.Component
|
|
|
-import java.awt.Polygon
|
|
|
import java.util.*
|
|
|
import java.util.stream.Collectors
|
|
|
|
|
|
+/**
|
|
|
+ * 空间冲突计算工具
|
|
|
+ * 基于python代码改写:relations.src.affected_space.affected_space
|
|
|
+ * @author ADM
|
|
|
+ * @date 2021-10-23
|
|
|
+ */
|
|
|
@Component
|
|
|
class SpaceAffectUtil {
|
|
|
|
|
|
@Autowired
|
|
|
private val service: DataCenterRequest? = null
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算空间冲突
|
|
|
+ * @param projectId
|
|
|
+ * @param modelId
|
|
|
+ */
|
|
|
fun affectedSpace(projectId: String, modelId: String): Boolean {
|
|
|
if (StringUtils.isBlank(projectId) || StringUtils.isBlank(modelId)) {
|
|
|
return true
|
|
@@ -81,8 +95,8 @@ class SpaceAffectUtil {
|
|
|
continue
|
|
|
}
|
|
|
val newPolygon = createPolygon(newSpace.outline)
|
|
|
- // TODO 有交集则加入有变化的元空间列表
|
|
|
- if (newPolygon == null) {
|
|
|
+ // 有交集则加入有变化的元空间列表
|
|
|
+ if (isGeoContains(polygon, newPolygon)) {
|
|
|
affectList.add(polygon)
|
|
|
continue
|
|
|
}
|
|
@@ -94,18 +108,52 @@ class SpaceAffectUtil {
|
|
|
val rsList: MutableList<DCISpace?> = ArrayList()
|
|
|
for (space in spaces!!) {
|
|
|
val polygon = createPolygon(space!!.outline)
|
|
|
- // TODO 有交集则加入有变化的空间列表
|
|
|
- if (polygon == null) {
|
|
|
- // TODO state设置为1
|
|
|
- rsList.add(space)
|
|
|
- continue
|
|
|
+ // 有交集则加入有变化的空间列表
|
|
|
+ for(affect in affectList) {
|
|
|
+ if (isGeoContains(polygon, affect!!)) {
|
|
|
+ // TODO state设置为1
|
|
|
+ rsList.add(space)
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return rsList
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 点面包含关系判断
|
|
|
+ * 用途:判断一个面是否包含一个点,即一个点是否在一个面内
|
|
|
+ * @param fromOutLines: 轮廓坐标
|
|
|
+ * @param toOutLines: 轮廓坐标
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ fun isGeoContains(fromPolygon: Polygon, toPolygon: Polygon): Boolean {
|
|
|
+ if (fromPolygon == null || toPolygon == null) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ //判断面-面包含关系
|
|
|
+ return (fromPolygon.contains(toPolygon)
|
|
|
+ || fromPolygon.equalsTopo(toPolygon)
|
|
|
+ || fromPolygon.overlaps(toPolygon)
|
|
|
+ || toPolygon.contains(fromPolygon))
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建平面对象
|
|
|
+ * @param list 轮廓线
|
|
|
+ */
|
|
|
private fun createPolygon(list: ArrayList<ArrayList<Point>>?): Polygon {
|
|
|
- return 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))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //注意数据的闭合
|
|
|
+ val coordinates = objects.toTypedArray()
|
|
|
+ val ring = geometryFactory.createLinearRing(coordinates)
|
|
|
+ return geometryFactory.createPolygon(ring, null)
|
|
|
}
|
|
|
|
|
|
/**
|