From 47dfec6876ebdd531613e4ed794e29c16188f0a9 Mon Sep 17 00:00:00 2001 From: Riccardo Boero <ribo@nilu.no> Date: Fri, 5 Jul 2024 11:47:25 +0200 Subject: [PATCH] Updated FACT_bldgs to include partitioning. --- src/FACT_bldgs.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FACT_bldgs.jl b/src/FACT_bldgs.jl index 6b76ac0..32a2f68 100644 --- a/src/FACT_bldgs.jl +++ b/src/FACT_bldgs.jl @@ -29,8 +29,8 @@ function footprint_avg_height(conn_dict::Dict, selection::Dict) for (id, shape) in zip(geo_id, shape_obj) # prepare query # given the CRS of the shape, the ST_Area will return squared degrees, hence here the max_footptin and avg_footprint are in millions of squared degrees. - query = "SELECT IF(ST_Area(ST_GeomFromText('"*shape*"')) = 0, 0, SUM(ST_Area(SHAPE))/ST_Area(ST_GeomFromText('"*shape*"'))) as perc_footprint, MAX(ST_Area(SHAPE))*1000000 as max_footprint, AVG(ST_Area(SHAPE))*1000000 as avg_footprint FROM footprints WHERE ST_Intersects(ST_GeomFromText('"*shape*"'), SHAPE);" - query2 = "SELECT CASE WHEN SUM(CASE WHEN JSON_EXTRACT(properties, '\$.height') <> -1 THEN ST_Area(SHAPE) ELSE 0 END) = 0 THEN NULL ELSE SUM(CASE WHEN JSON_EXTRACT(properties, '\$.height') <> -1 THEN JSON_EXTRACT(properties, '\$.height') * ST_Area(SHAPE) ELSE 0 END) / SUM(CASE WHEN JSON_EXTRACT(properties, '\$.height') <> -1 THEN ST_Area(SHAPE) ELSE 0 END) END as avg_height FROM footprints WHERE ST_Intersects(ST_GeomFromText('"*shape*"'), SHAPE);" + query = "SELECT IF(ST_Area(ST_GeomFromText('"*shape*"')) = 0, 0, SUM(ST_Area(SHAPE))/ST_Area(ST_GeomFromText('"*shape*"'))) as perc_footprint, MAX(ST_Area(SHAPE))*1000000 as max_footprint, AVG(ST_Area(SHAPE))*1000000 as avg_footprint FROM footprints WHERE ST_Intersects(ST_GeomFromText('"*shape*"'), SHAPE) AND part_id = LEFT('"*id*"', 2);" + query2 = "SELECT CASE WHEN SUM(CASE WHEN JSON_EXTRACT(properties, '\$.height') <> -1 THEN ST_Area(SHAPE) ELSE 0 END) = 0 THEN NULL ELSE SUM(CASE WHEN JSON_EXTRACT(properties, '\$.height') <> -1 THEN JSON_EXTRACT(properties, '\$.height') * ST_Area(SHAPE) ELSE 0 END) / SUM(CASE WHEN JSON_EXTRACT(properties, '\$.height') <> -1 THEN ST_Area(SHAPE) ELSE 0 END) END as avg_height FROM footprints WHERE ST_Intersects(ST_GeomFromText('"*shape*"'), SHAPE) AND part_id = LEFT('"*id*"', 2);" # create connection conn = establish_connection(conn_dict["host"], conn_dict["user"], conn_dict["password"], conn_dict["database"]; port=conn_dict["port"]) # execute -- GitLab