Parcourir la source

空间分析作差

gushoubang il y a 9 mois
Parent
commit
df5ad7c65a

+ 17 - 4
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/controller/analyse/CreateUtilsDBController.java

@@ -10,7 +10,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 基于pgsql里的POST做的生成数据组件
@@ -30,8 +32,13 @@ public class CreateUtilsDBController extends BaseController {
      */
     @PostMapping("/buffer/tables")
     @Slave
-    public RequestResult bufferTables(@RequestParam(value = "tableName") String tableName, @RequestParam(value = "radius") Float radius) {
-        return RequestResult.success(createUtilsDBService.bufferTable(tableName, radius));
+    public RequestResult bufferTables(@RequestParam(value = "tableName") String tableName,
+                                      @RequestParam(value = "radius") Float radius) {
+        String newTable = createUtilsDBService.bufferTable(tableName, radius);
+
+        Map<String, String> result = new HashMap<>();
+        result.put("tableName", newTable);
+        return RequestResult.success(result);
     }
 
     /**
@@ -44,7 +51,13 @@ public class CreateUtilsDBController extends BaseController {
      */
     @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));
+    public RequestResult differenceTables(@RequestParam(value = "inputTableA") String tableNameA,
+                                          @RequestParam(value = "inputTableB") String tableNameB,
+                                          @RequestParam(value = "inputIdsB", required = false) List<String> tableIdsB) {
+
+        String newTable =createUtilsDBService.differenceTables(tableNameA, tableNameB, tableIdsB);
+        Map<String, String> result = new HashMap<>();
+        result.put("tableName", newTable);
+        return RequestResult.success(newTable);
     }
 }

+ 9 - 2
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/mapper/CreateUtilsDBMapper.java

@@ -1,5 +1,7 @@
 package com.onemap.analyse.mapper;
 
+import org.apache.ibatis.annotations.Param;
+
 import java.util.List;
 
 public interface CreateUtilsDBMapper {
@@ -10,7 +12,9 @@ public interface CreateUtilsDBMapper {
      * @param radius
      * @return
      */
-    void bufferTable(String tableName, float radius, String newTableName);
+    void bufferTable(@Param("tableName") String tableName,
+                     @Param("radius") float radius,
+                     @Param("newTableName") String newTableName);
 
     /**
      * 生成表tableNameB空间数据的差集,B-ST_Intersection(A,B)
@@ -20,5 +24,8 @@ public interface CreateUtilsDBMapper {
      * @param tableIdsB
      * @return
      */
-    void differenceTables(String tableNameA, String tableNameB, List<String> tableIdsB, String newTableName);
+    void differenceTables(@Param("tableNameA") String tableNameA,
+                          @Param("tableNameB") String tableNameB,
+                          @Param("tableIdsB") List<String> tableIdsB,
+                          @Param("newTableName") String newTableName);
 }

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

@@ -14,14 +14,14 @@ public class CreateUtilsDBServiceImpl implements CreateUtilsDBService {
 
     @Override
     public String bufferTable(String tableName, float radius) {
-        String newBufferName = tableName + "_buffer" + radius;
-        createUtilsDBMapper.bufferTable(tableName, radius, newBufferName);
-        return newBufferName;
+        String newTableName = tableName + "_buffer" + radius;
+        createUtilsDBMapper.bufferTable(tableName, radius, newTableName);
+        return newTableName;
     }
 
     @Override
     public String differenceTables(String tableNameA, String tableNameB, List<String> tableIdsB) {
-        String newDiffName = tableNameB + "_diff" + tableNameA;
+        String newDiffName = tableNameB + "_diff_" + tableNameA;
         createUtilsDBMapper.differenceTables(tableNameA, tableNameB, tableIdsB, newDiffName);
         return newDiffName;
     }

+ 16 - 14
onemap-modules/onemap-analyse/src/main/resources/mapper/oracle/raster/CreateUtilsDBMapper.xml

@@ -4,24 +4,26 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.onemap.analyse.mapper.CreateUtilsDBMapper">
     <insert id="bufferTable">
-        <![CDATA[
-        CREATE TABLE ${newTableName} AS
-        SELECT ST_Buffer(geom, #{radius}) AS buffered_geom
-        FROM ${tableName}
+        CREATE TABLE "${newTableName}" AS
+        SELECT public.ST_Buffer(geom, #{radius}) AS buffered_geom
+        FROM "${tableName}"
         WHERE geom IS NOT NULL
-        ]]>
     </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}
+        CREATE TABLE "${newTableName}" AS
+        SELECT CASE
+        WHEN b.geom IS NOT NULL THEN public.ST_Difference(a.geom, b.geom)
+        ELSE a.geom END AS geom_result
+        FROM "${tableNameB}" a
+        LEFT JOIN "${tableNameA}" b ON public.ST_Intersects(a.geom, b.geom)
+        WHERE
+        b.geom IS NOT NULL
+        <if test="tableIdsB != null and tableIdsB.size() > 0">
+            AND a.id::VARCHAR IN
+            <foreach collection="tableIdsB" item="tableId" open="(" close=")" separator=",">
+                #{tableId}
             </foreach>
         </if>
     </insert>
+
 </mapper>