|
@@ -3,7 +3,7 @@
|
|
|
|
|
|
<mapper namespace="com.onemap.analyse.mapper.raster.RasterMapper">
|
|
|
<select id="getAveValue" resultType="Double">
|
|
|
- WITH poly AS (SELECT public.st_geomfromtext(#{geomWkt}, 4326) AS geom)
|
|
|
+ WITH poly AS (SELECT PUBLIC.st_transform(public.st_geomfromtext(#{geomWkt}, 4326), 3857) AS geom)
|
|
|
SELECT AVG((gv).val) AS avg_dsm
|
|
|
FROM (SELECT public.st_clip(rast, 1, geom, false) AS clipped_rast
|
|
|
FROM ${tableName},
|
|
@@ -13,7 +13,7 @@
|
|
|
WHERE (gv).val IS NOT NULL;
|
|
|
</select>
|
|
|
<select id="getMaxValue" resultType="Double">
|
|
|
- WITH poly AS (SELECT public.st_geomfromtext(#{geomWkt}, 4326) AS geom)
|
|
|
+ WITH poly AS (SELECT PUBLIC.st_transform(public.st_geomfromtext(#{geomWkt}, 4326), 3857) AS geom)
|
|
|
SELECT MAX((gv).val) AS max_dsm
|
|
|
FROM (SELECT public.st_clip(rast, 1, geom, false) AS clipped_rast
|
|
|
FROM ${tableName},
|
|
@@ -23,7 +23,7 @@
|
|
|
WHERE (gv).val IS NOT NULL;
|
|
|
</select>
|
|
|
<select id="getMinValue" resultType="Double">
|
|
|
- WITH poly AS (SELECT public.st_geomfromtext(#{geomWkt}, 4326) AS geom)
|
|
|
+ WITH poly AS (SELECT PUBLIC.st_transform(public.st_geomfromtext(#{geomWkt}, 4326), 3857) AS geom)
|
|
|
SELECT MIN((gv).val) AS min_dsm
|
|
|
FROM (SELECT public.st_clip(rast, 1, geom, false) AS clipped_rast
|
|
|
FROM ${tableName},
|
|
@@ -33,69 +33,58 @@
|
|
|
WHERE (gv).val IS NOT NULL;
|
|
|
</select>
|
|
|
|
|
|
- <select id="getDemVolume" resultType="Double">
|
|
|
- SELECT (stats.count * (pixel_info.pixel_size * pixel_info.pixel_size) * (stats.mean - #{minHeight})) AS volume
|
|
|
- FROM (SELECT (public.ST_SummaryStats(
|
|
|
- public.ST_MapAlgebra(
|
|
|
- public.ST_Clip(rast, 1, public.ST_GeomFromText(#{geomWkt}, 4326)),1,
|
|
|
- 'CASE WHEN [rast] >= #{minHeight} AND [rast] <= #{maxHeight} THEN [rast] ELSE NULL END',
|
|
|
- '32BF')
|
|
|
- )).*) AS stats,
|
|
|
- (SELECT public.ST_PixelWidth(public.ST_Clip(rast, 1, public.ST_GeomFromText(#{geomWkt}, 4326))) as pixel_size
|
|
|
- FROM ${tableName}
|
|
|
- WHERE public.ST_Intersects(rast, public.ST_GeomFromText(#{geomWkt}, 4326)) LIMIT 1) AS pixel_info;
|
|
|
+ <select id="getHilltopVolume" parameterType="map" resultType="Double">
|
|
|
+ WITH geom AS (SELECT PUBLIC.st_transform(PUBLIC.ST_GeomFromText('${geomWkt}', 4326), 3857) AS geom),
|
|
|
+ pixel AS (SELECT (PUBLIC.ST_MetaData(rast)).scalex AS pixel_width
|
|
|
+ FROM ${tableName} LIMIT 1
|
|
|
+ ), clipped_raster AS (
|
|
|
+ SELECT PUBLIC.ST_Clip(rast, 1, geom.geom, FALSE) AS rast
|
|
|
+ FROM ${tableName}, geom
|
|
|
+ WHERE PUBLIC.ST_Intersects(rast
|
|
|
+ , geom.geom)
|
|
|
+ )
|
|
|
+ , stats AS (
|
|
|
+ SELECT (PUBLIC.ST_SummaryStats(PUBLIC.ST_MapAlgebraExpr(
|
|
|
+ rast, 1, '32BF', 'CASE WHEN [rast] >= ${height} THEN [rast] ELSE NULL END'
|
|
|
+ ), 1)).*
|
|
|
+ FROM clipped_raster
|
|
|
+ )
|
|
|
+ SELECT SUM((stats.mean - #{height}) * stats.count * (pixel.pixel_width * pixel.pixel_width)) AS fill_volume
|
|
|
+ FROM stats,
|
|
|
+ pixel;
|
|
|
</select>
|
|
|
|
|
|
<select id="getFillVolume" parameterType="map" resultType="Double">
|
|
|
- WITH geom AS (
|
|
|
- SELECT PUBLIC.st_transform(PUBLIC.ST_GeomFromText('${geomWkt}', 4326), 3857) AS geom
|
|
|
- ),
|
|
|
- pixel AS (
|
|
|
- SELECT (PUBLIC.ST_MetaData(rast)).scalex AS pixel_width FROM ${tableName} LIMIT 1
|
|
|
- ),
|
|
|
- clipped_raster AS (
|
|
|
- SELECT PUBLIC.ST_Clip(rast, 1, geom.geom, FALSE) AS rast FROM ${tableName}, geom
|
|
|
- WHERE PUBLIC.ST_Intersects(rast, geom.geom)
|
|
|
- ),
|
|
|
- stats AS (
|
|
|
+ WITH geom AS (SELECT PUBLIC.st_transform(PUBLIC.ST_GeomFromText('${geomWkt}', 4326), 3857) AS geom),
|
|
|
+ pixel AS (SELECT (PUBLIC.ST_MetaData(rast)).scalex AS pixel_width
|
|
|
+ FROM ${tableName} LIMIT 1
|
|
|
+ ), clipped_raster AS (
|
|
|
+ SELECT PUBLIC.ST_Clip(rast, 1, geom.geom, FALSE) AS rast
|
|
|
+ FROM ${tableName}, geom
|
|
|
+ WHERE PUBLIC.ST_Intersects(rast
|
|
|
+ , geom.geom)
|
|
|
+ )
|
|
|
+ , stats AS (
|
|
|
SELECT (PUBLIC.ST_SummaryStats(PUBLIC.ST_MapAlgebraExpr(
|
|
|
- rast, 1, '32BF',
|
|
|
- 'CASE WHEN [rast] < ${height} THEN [rast] ELSE NULL END'
|
|
|
+ rast, 1, '32BF', 'CASE WHEN [rast] < ${height} THEN [rast] ELSE NULL END'
|
|
|
), 1)).*
|
|
|
FROM clipped_raster
|
|
|
)
|
|
|
SELECT SUM((#{height} - stats.mean) * stats.count * (pixel.pixel_width * pixel.pixel_width)) AS fill_volume
|
|
|
- FROM stats, pixel;
|
|
|
+ FROM stats,
|
|
|
+ pixel;
|
|
|
</select>
|
|
|
|
|
|
-<!-- <select id="getFillVolume" parameterType="map" resultType="Double">-->
|
|
|
-<!-- WITH geom AS (-->
|
|
|
-<!-- SELECT PUBLIC.st_transform(PUBLIC.ST_GeomFromText('${geomWkt}', 4326), 3857) AS geom-->
|
|
|
-<!-- ),-->
|
|
|
-<!-- pixel AS (-->
|
|
|
-<!-- SELECT (PUBLIC.ST_MetaData(rast)).scalex AS pixel_width FROM ${tableName} LIMIT 1-->
|
|
|
-<!-- ),-->
|
|
|
-<!-- clipped_raster AS (-->
|
|
|
-<!-- SELECT PUBLIC.ST_Clip(rast, 1, geom.geom, FALSE) AS rast FROM ${tableName}, geom-->
|
|
|
-<!-- WHERE PUBLIC.ST_Intersects(rast, geom.geom)-->
|
|
|
-<!-- ),-->
|
|
|
-<!-- stats AS (-->
|
|
|
-<!-- SELECT (PUBLIC.ST_SummaryStats(PUBLIC.ST_MapAlgebra(-->
|
|
|
-<!-- rast, 1, '32BF',-->
|
|
|
-<!-- 'CASE WHEN [rast] < ${height} THEN [rast] ELSE NULL END'-->
|
|
|
-<!-- ), 1)).*-->
|
|
|
-<!-- FROM clipped_raster-->
|
|
|
-<!-- )-->
|
|
|
-<!-- SELECT SUM((#{height} - stats.mean) * stats.count * (pixel.pixel_width * pixel.pixel_width)) AS fill_volume-->
|
|
|
-<!-- FROM stats, pixel;-->
|
|
|
-<!-- </select>-->
|
|
|
-
|
|
|
- <select id="getDemRing" resultType="String">
|
|
|
- WITH contour AS (SELECT (public.ST_Dump(public.ST_Contour(rast, 1, interval => 1))).geom AS geom, (public.ST_Value(rast, public.ST_Centroid((public.ST_Dump(public.ST_Contour(rast, 1, interval => 1))).geom)):: int) AS elevation
|
|
|
- FROM ${tableName}
|
|
|
- WHERE public.ST_Intersects(rast, public.ST_GeomFromText(#{geomWkt}, 4326)))
|
|
|
- SELECT public.ST_Intersection(geom, public.ST_GeomFromText(#{geomWkt}, 4326)) AS geom
|
|
|
- FROM contour
|
|
|
- WHERE elevation = #{height}
|
|
|
+ <select id="getDemRing" parameterType="map" resultType="String">
|
|
|
+ WITH geom AS (SELECT PUBLIC.ST_TRANSFORM(PUBLIC.ST_GEOMFROMTEXT('${geomWkt}', 4326), 3857) AS geom),
|
|
|
+ clipped_raster AS (
|
|
|
+ SELECT PUBLIC.ST_CLIP(rast, 1, geom.geom, FALSE) AS rast from ${tableName}, geom WHERE PUBLIC.ST_INTERSECTS(rast, geom.geom)
|
|
|
+ ),
|
|
|
+ subquery AS (
|
|
|
+ SELECT PUBLIC.ST_MAPALGEBRAEXPR(rast, 1, '32BF', 'CASE WHEN [rast] > ${height} THEN 1 ELSE NULL END') AS rast
|
|
|
+ FROM clipped_raster
|
|
|
+ ),
|
|
|
+ res_geom AS (SELECT (PUBLIC.ST_DUMPASPOLYGONS(rast)).geom AS result_geom FROM subquery)
|
|
|
+ SELECT PUBLIC.ST_ASEWKT(PUBLIC.ST_TRANSFORM(PUBLIC.ST_UNION(PUBLIC.ST_MakeValid(result_geom)), 4326)) AS geom_res FROM res_geom;
|
|
|
</select>
|
|
|
</mapper>
|