Open Infrastructure Map, a view of infrastructure data in OpenStreetMap
Improve heatmap layer
Russ Garrett032f583ee6ad
diff --git a/config.toml b/config.tomlindex 9ac81ed..39923bb 100644--- a/config.toml+++ b/config.toml@@ -146,7 +146,7 @@ sql = "SELECT osm_id AS gid, ST_AsBinary(ST_Centroid(geometry)) AS geom, tags ->[[providers.layers]]name = "power_heatmap_solar"geometry_type = "Point"-sql = "SELECT ST_AsBinary(ST_SnapToGrid(ST_Centroid(geometry), ZRes(!ZOOM!), ZRes(!ZOOM!))) AS geom, round(sum(coalesce(convert_power(tags -> 'generator:output:electricity'), solar_output(geometry), 0)) / 1e3) AS output FROM osm_power_generator WHERE source = 'solar' AND construction = '' AND geometry && !BBOX! GROUP BY geom"+sql = "SELECT ST_AsBinary(ST_SnapToGrid(ST_Centroid(geometry), ZRes(!ZOOM!), ZRes(!ZOOM!))) AS geom, round(sum(coalesce(convert_power(tags -> 'generator:output:electricity'), modules_output(tags -> 'generator:solar:modules'), solar_output(geometry), 0))::NUMERIC / 1e3, 2) AS output FROM osm_power_generator WHERE source = 'solar' AND construction = '' AND geometry && !BBOX! GROUP BY geom"[[providers.layers]]name = "power_generator_area"diff --git a/functions.sql b/functions.sqlindex 3c252ed..83a6765 100644--- a/functions.sql+++ b/functions.sql@@ -8,7 +8,7 @@ DROP MATERIALIZED VIEW IF EXISTS power_substation_relation;DROP MATERIALIZED VIEW IF EXISTS power_plant_relation;-- Convert a power value into a numeric value in watts-CREATE OR REPLACE FUNCTION convert_power(value TEXT) RETURNS NUMERIC IMMUTABLE AS $$+CREATE OR REPLACE FUNCTION convert_power(value TEXT) RETURNS NUMERIC IMMUTABLE RETURNS NULL ON NULL INPUT AS $$DECLAREparts TEXT[];val NUMERIC;@@ -27,7 +27,7 @@ END$$ LANGUAGE plpgsql;-- Select the highest voltage from a semicolon-delimited list-CREATE OR REPLACE FUNCTION convert_voltage(value TEXT) RETURNS NUMERIC IMMUTABLE AS $$+CREATE OR REPLACE FUNCTION convert_voltage(value TEXT) RETURNS NUMERIC IMMUTABLE RETURNS NULL ON NULL INPUT AS $$DECLAREparts TEXT[];BEGIN@@ -158,12 +158,24 @@ CREATE OR REPLACE FUNCTION solar_output(geom GEOMETRY) RETURNS DOUBLE PRECISIONDECLAREBEGINIF ST_GeometryType(geom) = 'ST_Point' THEN- RETURN 1000; -- Assume point generators have a fixed output of 1 kW+ RETURN 4000; -- Assume point generators have a fixed output of 4 kWEND IF;RETURN area_sqm(geom) * 150; -- 150 W/m^2END$$ LANGUAGE plpgsql;+-- Convert a number of modules (as text) into an output (in watts)+CREATE OR REPLACE FUNCTION modules_output(modules TEXT) RETURNS DOUBLE PRECISION IMMUTABLE RETURNS NULL ON NULL INPUT AS $$+DECLARE+BEGIN+ BEGIN+ RETURN modules::INTEGER * 700;+ EXCEPTION WHEN OTHERS THEN+ RETURN NULL;+ END;+END+$$ LANGUAGE plpgsql;+-- Rendering functionscreate or replace function ZRes (z integer)