瀏覽代碼

差集计算封装

gushoubang 9 月之前
父節點
當前提交
9f2bc0d8cb

+ 33 - 0
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/controller/analyse/CreateUtilsDBController.java

@@ -3,10 +3,16 @@ package com.onemap.analyse.controller.analyse;
 import com.onemap.analyse.service.AnalyseUtilsDBService;
 import com.onemap.analyse.service.CreateUtilsDBService;
 import com.onemap.common.core.web.controller.BaseController;
+import com.onemap.common.core.web.domain.RequestResult;
+import com.onemap.common.datasource.annotation.Slave;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 /**
  * 基于pgsql里的POST做的生成数据组件
  */
@@ -15,4 +21,31 @@ import org.springframework.web.bind.annotation.RestController;
 public class CreateUtilsDBController extends BaseController {
     @Autowired
     private CreateUtilsDBService createUtilsDBService;
+
+    /**
+     * 生成表空间数据的缓冲区
+     *
+     * @param tableName
+     * @param radius
+     * @return
+     */
+    @PostMapping("/buffer/tables")
+    @Slave
+    public RequestResult bufferTables(@RequestParam(value = "tableName") String tableName, @RequestParam(value = "radius") Float radius) {
+        return RequestResult.success(createUtilsDBService.bufferTable(tableName, radius));
+    }
+
+    /**
+     * 生成表tableNameB空间数据的差集,B-ST_Intersection(A,B)
+     *
+     * @param tableNameA
+     * @param tableNameB
+     * @param tableIdsB
+     * @return
+     */
+    @PostMapping("/difference/tables")
+    @Slave
+    public RequestResult differenceTables(@RequestParam(value = "inputTableA") String tableNameA, @RequestParam(value = "inputTableB") String tableNameB, @RequestParam(value = "inputIdsB", required = false) List<String> tableIdsB) {
+        return RequestResult.success(createUtilsDBService.differenceTables(tableNameA, tableNameB, tableIdsB));
+    }
 }

+ 13 - 1
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/mapper/CreateUtilsDBMapper.java

@@ -1,5 +1,7 @@
 package com.onemap.analyse.mapper;
 
+import java.util.List;
+
 public interface CreateUtilsDBMapper {
     /**
      * 计算tableName 空间数据的缓冲区,并存储成新的表
@@ -8,5 +10,15 @@ public interface CreateUtilsDBMapper {
      * @param radius
      * @return
      */
-    void bufferTable(String tableName, float radius,String newTableName);
+    void bufferTable(String tableName, float radius, String newTableName);
+
+    /**
+     * 生成表tableNameB空间数据的差集,B-ST_Intersection(A,B)
+     *
+     * @param tableNameA
+     * @param tableNameB
+     * @param tableIdsB
+     * @return
+     */
+    void differenceTables(String tableNameA, String tableNameB, List<String> tableIdsB, String newTableName);
 }

+ 17 - 5
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/service/CreateUtilsDBService.java

@@ -1,17 +1,29 @@
 package com.onemap.analyse.service;
 
-import org.springframework.web.bind.annotation.RequestParam;
+import java.util.List;
 
 /**
  * 基于pgsql里的POST做的生成数据组件
  */
 public interface CreateUtilsDBService {
     /**
-     * table中与wkt数据是否有交集
+     * 生成表空间数据的缓冲区
      *
-     * @param tableName 表名称
-     * @param radius    缓冲区半径
+     * @param tableName
+     * @param radius
      * @return
      */
-    String bufferTable(@RequestParam(value = "tableName") String tableName, float radius);
+    String bufferTable(String tableName, float radius);
+
+    /**
+     * 生成表tableNameB空间数据的差集,B-ST_Intersection(A,B)
+     *
+     * @param tableNameA
+     * @param tableNameB
+     * @param tableIdsB
+     * @return
+     */
+    String differenceTables(String tableNameA,
+                            String tableNameB,
+                            List<String> tableIdsB);
 }

+ 8 - 0
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/service/impl/CreateUtilsDBServiceImpl.java

@@ -5,6 +5,7 @@ import com.onemap.analyse.service.CreateUtilsDBService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 @Service
 public class CreateUtilsDBServiceImpl implements CreateUtilsDBService {
@@ -17,4 +18,11 @@ public class CreateUtilsDBServiceImpl implements CreateUtilsDBService {
         createUtilsDBMapper.bufferTable(tableName, radius, newBufferName);
         return newBufferName;
     }
+
+    @Override
+    public String differenceTables(String tableNameA, String tableNameB, List<String> tableIdsB) {
+        String newDiffName = tableNameB + "_diff" + tableNameA;
+        createUtilsDBMapper.differenceTables(tableNameA, tableNameB, tableIdsB, newDiffName);
+        return newDiffName;
+    }
 }

+ 15 - 2
onemap-modules/onemap-analyse/src/main/resources/mapper/oracle/raster/CreateUtilsDBMapper.xml

@@ -3,12 +3,25 @@
         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.onemap.analyse.mapper.CreateUtilsDBMapper">
-    <update id="bufferTable">
+    <insert id="bufferTable">
         <![CDATA[
         CREATE TABLE ${newTableName} AS
         SELECT ST_Buffer(geom, #{radius}) AS buffered_geom
         FROM ${tableName}
         WHERE geom IS NOT NULL
         ]]>
-    </update>
+    </insert>
+    <insert id="differenceTables">
+        CREATE TABLE new_table AS
+        SELECT ST_Difference(B.geom, A.geom) AS geom
+        FROM ${tableNameB} B
+        LEFT JOIN ${tableNameA} A ON ST_Intersects(B.geom, A.geom)
+        WHERE A.id IS NULL
+        <if test="inputIds != null and inputIds.size() > 0">
+            AND B.id IN
+            <foreach collection="inputIds" item="id" open="(" close=")" separator=",">
+                #{id}
+            </foreach>
+        </if>
+    </insert>
 </mapper>