| 
					
				 | 
			
			
				@@ -55,19 +55,19 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         DROP TABLE IF EXISTS "${temporaryTable}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     </insert> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--    <insert id="differenceTableWkt">--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--        CREATE TABLE "${newTableName}" AS--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--        SELECT id, public.ST_Difference(inTbale.geom, public.st_geomfromewkt(#{ewkt})) AS geom--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--        FROM "${tableName}" inTbale--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--        WHERE NOT public.ST_IsEmpty(public.ST_Difference(inTbale.geom, public.st_geomfromewkt(#{ewkt})))--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--        <if test="tableIds != null and tableIds.size() > 0">--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--            AND inTbale.id::VARCHAR IN--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--            <foreach collection="tableIds" item="tableId" open="(" close=")" separator=",">--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--                #{tableId}--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--            </foreach>--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--        </if>--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--        ;--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<!--    </insert>--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--    <insert id="differenceTableWkt">--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--        CREATE TABLE "${newTableName}" AS--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--        SELECT id, public.ST_Difference(inTbale.geom, public.st_geomfromewkt(#{ewkt})) AS geom--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--        FROM "${tableName}" inTbale--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--        WHERE NOT public.ST_IsEmpty(public.ST_Difference(inTbale.geom, public.st_geomfromewkt(#{ewkt})))--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--        <if test="tableIds != null and tableIds.size() > 0">--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--            AND inTbale.id::VARCHAR IN--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--            <foreach collection="tableIds" item="tableId" open="(" close=")" separator=",">--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--                #{tableId}--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--            </foreach>--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--        </if>--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--        ;--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <!--    </insert>--> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     <insert id="differenceTableWkt" timeout="60"> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         CREATE TABLE vector."${newTableName}" AS 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -114,20 +114,119 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     <insert id="getLtBandValue"> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         CREATE TABLE "${newTableName}" AS 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        SELECT DISTINCT ta.id,ta.geom 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SELECT DISTINCT ta.id, ta.geom 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         FROM "${tableNameA}" ta, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              "${tableNameB}" tb 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         WHERE public.ST_Intersects(tb.rast, ta.geom) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           AND (SELECT (stats).mean 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            FROM (SELECT PUBLIC.ST_SummaryStats(PUBLIC.ST_Clip(tb.rast,ta.geom)) AS stats) AS summary) < #{value}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            FROM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            SELECT 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PUBLIC 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            . 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ST_SummaryStats( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PUBLIC 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            . 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ST_Clip 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            tb 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            . 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            rast, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ta 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            . 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            geom 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        )) AS stats) AS summary) < #{value}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     </insert> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     <insert id="getGtBandValue"> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         CREATE TABLE "${newTableName}" AS 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        SELECT DISTINCT ta.id,ta.geom 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SELECT DISTINCT ta.id, ta.geom 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         FROM "${tableNameA}" ta, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              "${tableNameB}" tb 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         WHERE public.ST_Intersects(tb.rast, ta.geom) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           AND (SELECT (stats).mean 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            FROM (SELECT PUBLIC.ST_SummaryStats(PUBLIC.ST_Clip(tb.rast,ta.geom)) AS stats) AS summary) > #{value}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            FROM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            SELECT 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PUBLIC 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            . 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ST_SummaryStats( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PUBLIC 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            . 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ST_Clip 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            tb 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            . 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            rast, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ta 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            . 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            geom 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        )) AS stats) AS summary) > #{value}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    </insert> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <insert id="addDemValue"> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CREATE TABLE "${newTableName}" AS 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        WITH geom_transformed AS (SELECT id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                         geom, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                         public.ST_Transform(geom, 3857) AS geom_3857 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                  FROM "${tableNameA}"), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             clipped_raster AS (SELECT a.id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                       a.geom, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                       public.ST_Clip(r.rast, 1, a.geom_3857, TRUE) AS clipped 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                FROM geom_transformed a 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                         LEFT JOIN "${tableNameB}" r 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                   ON public.ST_Intersects(r.rast, a.geom_3857)), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             summary_stats AS (SELECT id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                      geom, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                      CASE 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                          WHEN COUNT(clipped) = 0 THEN 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                          ELSE SUM((public.ST_SummaryStats(clipped, 1)).sum) / 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                               SUM((public.ST_SummaryStats(clipped, 1)).count) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                          END AS average_elevation 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                               FROM clipped_raster 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                               GROUP BY id, geom) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SELECT id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               geom, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               COALESCE(average_elevation, 0) AS average_elevation 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        FROM summary_stats; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    </insert> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <insert id="addColumnValue"> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CREATE TABLE "${newTableName}" AS 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SELECT ta.id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               ta.geom, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               ta.average_elevation, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               COALESCE(tb."${column}", 0)                        AS "${column}", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               ta.average_elevation + COALESCE(tb."${column}", 0) AS height 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        FROM "${tableNameA}" as ta, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             "${tableNameB}" as tb 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        WHERE ta.id = tb.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    </insert> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    <insert id="getHeightLimit"> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CREATE TABLE "${newTableName}" AS 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        WITH intersected AS (SELECT ta.id                            AS a_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    ta.geom                          AS a_geom, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    ta.height                        AS a_height, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    tb.id                            AS b_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    tb.geom                          AS b_geom, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    tb.hight                         AS b_hight, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    public.ST_Intersection(ta.geom, tb.geom) AS intersect_geom 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                             FROM "${tableNameA}" as ta 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                      JOIN 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                  "${tableNameB}" as tb 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                  ON 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                      public.ST_Intersects(ta.geom, tb.geom)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SELECT a_id as id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               intersect_geom AS geom, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               a_height        AS height 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        FROM intersected 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        WHERE a_height <= b_hight 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        UNION ALL 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SELECT ta.id    AS id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               ta.geom  AS geom, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               ta.height AS height 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        FROM "${tableNameA}" as ta 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        WHERE NOT EXISTS (SELECT 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                          FROM "${tableNameB}" as tb 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                          WHERE public.ST_Intersects(ta.geom, tb.geom)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     </insert> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 </mapper> 
			 |