Skip to content
Snippets Groups Projects
Commit 47dfec68 authored by Riccardo Boero's avatar Riccardo Boero :innocent:
Browse files

Updated FACT_bldgs to include partitioning.

parent 14242013
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment