Open Infrastructure Map, a view of infrastructure data in OpenStreetMap
Fix stats query
Russ Garrett1f285095491e
diff --git a/imposm/README.md b/imposm/README.mdindex 50f461d..bc568b7 100644--- a/imposm/README.md+++ b/imposm/README.md@@ -56,4 +56,17 @@ We create a materialized view from this, using `ST_Subdivide` to improve indexinCREATE INDEX country_eez_sub_geom ON countries.country_eez_sub USING GIST (geom);CREATE INDEX country_eez_sub_iso_sov1 ON countries.country_eez_sub(iso_sov1);- CREATE INDEX country_eez_sub_iso_ter1 ON countries.country_eez_sub(iso_ter1);\ No newline at end of file+ CREATE INDEX country_eez_sub_iso_ter1 ON countries.country_eez_sub(iso_ter1);++ CREATE MATERIALIZED VIEW countries.country_eez_3857 AS+ SELECT country_eez.gid,+ country_eez."union",+ country_eez.mrgid_eez,+ country_eez.territory1,+ country_eez.mrgid_ter1,+ country_eez.iso_ter1,+ country_eez.iso_sov1,+ country_eez.pol_type,+ ST_Transform(country_eez.geom, 3857) AS geom+ FROM countries.country_eez+ WHERE country_eez."union"::text <> 'Antarctica'::text;diff --git a/schema/jobs/update-stats.sql b/schema/jobs/update-stats.sqlindex 3bc3f99..b1ebce0 100644--- a/schema/jobs/update-stats.sql+++ b/schema/jobs/update-stats.sql@@ -4,38 +4,42 @@BEGIN;INSERT INTO stats.power_line (time, country, voltage, length)- SELECT now() AS time, country_eez_sub."union" AS country, convert_voltage(voltage)::INTEGER AS voltage,+ SELECT now() AS time, eez."union" AS country, convert_voltage(voltage)::INTEGER AS voltage,sum(ST_Length(ST_Transform(geometry, 4326)::geography)) AS length- FROM osm_power_line, countries.country_eez_sub- WHERE ST_Contains(country_eez_sub.geom, geometry)+ FROM osm_power_line, countries.country_eez_3857 AS eez+ WHERE ST_Contains(eez.geom, geometry)AND "union" != 'Antarctica'AND tags->'construction:power' IS NULL- GROUP BY country_eez_sub."union", convert_voltage(voltage);+ AND tags->'disused:power' IS NULL+ GROUP BY eez."union", convert_voltage(voltage);INSERT INTO stats.power_plant (time, country, source, count, output)- SELECT now() AS time, country_eez_sub."union", source, count(*), convert_power(output)- FROM power_plant, countries.country_eez_sub- WHERE ST_Contains(country_eez_sub.geom, geometry)+ SELECT now() AS time, eez."union", source, count(*), convert_power(output)+ FROM power_plant, countries.country_eez_3857 AS eez+ WHERE ST_Contains(eez.geom, geometry)AND "union" != 'Antarctica'AND tags->'construction:power' IS NULL- GROUP BY country_eez_sub."union", source, convert_power(output);+ AND tags->'disused:power' IS NULL+ GROUP BY eez."union", source, convert_power(output);INSERT INTO stats.power_generator (time, country, source, count, output)- SELECT now() AS time, country_eez_sub."union", source, count(*), convert_power(output)- FROM osm_power_generator, countries.country_eez_sub- WHERE ST_Contains(country_eez_sub.geom, geometry)+ SELECT now() AS time, eez."union", source, count(*), convert_power(output)+ FROM osm_power_generator, countries.country_eez_3857 AS eez+ WHERE ST_Contains(eez.geom, geometry)AND "union" != 'Antarctica'AND tags->'construction:power' IS NULL- GROUP BY country_eez_sub."union", source, convert_power(output);+ AND tags->'disused:power' IS NULL+ GROUP BY eez."union", source, convert_power(output);INSERT INTO stats.substation (time, country, voltage, count)- SELECT now() AS time, country_eez_sub."union" AS country, convert_voltage(voltage)::INTEGER AS voltage, count(*)- FROM substation, countries.country_eez_sub- WHERE ST_Contains(country_eez_sub.geom, geometry)+ SELECT now() AS time, eez."union" AS country, convert_voltage(voltage)::INTEGER AS voltage, count(*)+ FROM substation, countries.country_eez_3857 AS eez+ WHERE ST_Contains(eez.geom, geometry)AND "union" != 'Antarctica'AND tags->'construction:power' IS NULL- GROUP BY country_eez_sub."union", convert_voltage(voltage);+ AND tags->'disused:power' IS NULL+ GROUP BY eez."union", convert_voltage(voltage);COMMIT;\ No newline at end of filediff --git a/schema/stats.sql b/schema/stats.sqlindex 07fbf1c..fbc85ac 100644--- a/schema/stats.sql+++ b/schema/stats.sql@@ -10,6 +10,7 @@ CREATE TABLE stats.power_line (length INTEGER NOT NULL);+-- Power plants, grouped by output. (Note you need to sum(count * output) to get the total)CREATE TABLE stats.power_plant (id SERIAL PRIMARY KEY,time TIMESTAMP WITHOUT TIME ZONE NOT NULL,