@@ -29,8 +29,8 @@ function footprint_avg_height(conn_dict::Dict, selection::Dict)
for(id,shape)inzip(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);"