diff --git a/dataprocessing/sql_snippets/rea/reaosm/ego_dp_reaosm_m1.sql b/dataprocessing/sql_snippets/rea/reaosm/ego_dp_reaosm_m1.sql new file mode 100644 index 00000000..b30348b4 --- /dev/null +++ b/dataprocessing/sql_snippets/rea/reaosm/ego_dp_reaosm_m1.sql @@ -0,0 +1,417 @@ +/* +M1 biomass and solar to OSM agricultural +Allocates "biomass" & (renewable) "gas" to OSM agricultural areas. +The rest could not be allocated, consider in M4. + +__copyright__ = "Reiner Lemoine Institut" +__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)" +__url__ = "https://github.com/openego/data_processing/blob/master/LICENSE" +__author__ = "Ludee, Christian-rli" +*/ + +-- check +SELECT generation_type, generation_subtype, count(*) +FROM sandbox.ego_reaosm_m1_1_a_mview +GROUP BY generation_type, generation_subtype +ORDER BY generation_type, generation_subtype; + +-- MView M1-1 +DROP MATERIALIZED VIEW IF EXISTS sandbox.ego_reaosm_m1_1_a_mview CASCADE; +CREATE MATERIALIZED VIEW sandbox.ego_reaosm_m1_1_a_mview AS + SELECT id, + electrical_capacity, + generation_type, + generation_subtype, + voltage_level, + subst_id, + ST_TRANSFORM(geom,3035) AS geom, + rea_flag + FROM sandbox.ego_dp_res_powerplant_reaosm + WHERE (generation_type = 'biomass' OR generation_type = 'gas') + AND(voltage_level = 4 OR voltage_level = 5 + OR voltage_level = 6 OR voltage_level = 7 + OR voltage_level IS NULL ); + +-- create index GIST (geom) +CREATE INDEX ego_reaosm_m1_1_a_mview_geom_idx + ON sandbox.ego_reaosm_m1_1_a_mview USING gist (geom); + +-- grant (oeuser) +ALTER TABLE sandbox.ego_reaosm_m1_1_a_mview OWNER TO oeuser; + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +SELECT scenario_log('eGo_PP_REAOSM','v0.1','input','sandbox','ego_dp_res_powerplant_reaosm','ego_dp_reaosm_m1.sql',' '); +SELECT scenario_log('eGo_REAOSM','v0.1','temp','sandbox','ego_reaosm_m1_1_a_mview','ego_dp_reaosm_m1.sql',' '); + + +-- reaosm_flag M1-1 +UPDATE sandbox.ego_dp_res_powerplant_reaosm AS dea + SET reaosm_flag = 'M1-1_rest' + WHERE (dea.generation_type = 'biomass' OR dea.generation_type = 'gas') + AND (dea.voltage_level = 4 OR dea.voltage_level = 5 + OR dea.voltage_level = 6 OR dea.voltage_level = 7 + OR dea.voltage_level IS NULL ); + + +-- temporary tables for the loop +DROP TABLE IF EXISTS sandbox.ego_reaosm_m1_1_dea_temp CASCADE; +CREATE TABLE sandbox.ego_reaosm_m1_1_dea_temp ( + reaosm_sort bigint NOT NULL, + id bigint NOT NULL, + electrical_capacity numeric, + generation_type text, + generation_subtype character varying, + voltage_level character varying, + subst_id integer, + geom geometry(Point,3035), + reaosm_flag character varying, + CONSTRAINT ego_reaosm_m1_1_dea_temp_pkey PRIMARY KEY (reaosm_sort)); + +CREATE INDEX ego_reaosm_m1_1_dea_temp_geom_idx + ON sandbox.ego_reaosm_m1_1_dea_temp USING gist (geom); + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +--SELECT scenario_log('eGo_REAOSM','v0.1','temp','sandbox','ego_reaosm_m1_1_dea_temp','ego_dp_reaosm_m1.sql',' '); + +DROP TABLE IF EXISTS sandbox.ego_reaosm_m1_1_osm_temp CASCADE; +CREATE TABLE sandbox.ego_reaosm_m1_1_osm_temp ( + reaosm_sort bigint NOT NULL, + id bigint, + subst_id integer, + geom geometry(Point,3035), + CONSTRAINT ego_reaosm_m1_1_osm_temp_pkey PRIMARY KEY (reaosm_sort)); + +CREATE INDEX ego_reaosm_m1_1_osm_temp_geom_idx + ON sandbox.ego_reaosm_m1_1_osm_temp USING gist (geom); + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +--SELECT scenario_log('eGo_REAOSM','v0.1','temp','sandbox','ego_reaosm_m1_1_osm_temp','ego_dp_reaosm_m1.sql',' '); + +DROP TABLE IF EXISTS sandbox.ego_reaosm_m1_1_jnt_temp CASCADE; +CREATE TABLE sandbox.ego_reaosm_m1_1_jnt_temp ( + reaosm_sort bigint NOT NULL, + id bigint, + reaosm_geom_line geometry(LineString,3035), + geom geometry(Point,3035), + CONSTRAINT ego_reaosm_m1_1_jnt_temp_pkey PRIMARY KEY (reaosm_sort)); + +CREATE INDEX ego_reaosm_m1_1_jnt_temp_geom_idx + ON sandbox.ego_reaosm_m1_1_jnt_temp USING gist (geom); + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +--SELECT scenario_log('eGo_REAOSM','v0.1','temp','sandbox','ego_reaosm_m1_1_jnt_temp','ego_dp_reaosm_m1.sql',' '); + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +-- SELECT scenario_log('eGo_REAOSM','v0.1','input','model_draft','ego_osm_sector_per_griddistrict_4_agricultural','ego_dp_reaosm_m1.sql',' '); + +-- loop for grid_district +DO +$$ +DECLARE gd integer; +BEGIN + FOR gd IN 1..3591 -- subst_id + LOOP + EXECUTE ' + INSERT INTO sandbox.ego_reaosm_m1_1_dea_temp + SELECT row_number() over (ORDER BY electrical_capacity DESC)as reaosm_sort, + * + FROM sandbox.ego_reaosm_m1_1_a_mview + WHERE subst_id =' || gd || '; + + INSERT INTO sandbox.ego_reaosm_m1_1_osm_temp + SELECT row_number() over (ORDER BY osm_id DESC)as reaosm_sort, + osm_id, + subst_id, + geom + FROM sandbox.ego_pp_osm_deu_power_point_reaosm + WHERE rea_method = ''M1'' + AND subst_id =' || gd || '; + + INSERT INTO sandbox.ego_reaosm_m1_1_jnt_temp + SELECT dea.reaosm_sort, + dea.id, + ST_MAKELINE(dea.geom,ST_CENTROID(osm.geom)) ::geometry(LineString,3035) AS reaosm_geom_line, + osm.geom ::geometry(Point,3035) AS geom -- NEW LOCATION! + FROM sandbox.ego_reaosm_m1_1_dea_temp AS dea + INNER JOIN sandbox.ego_reaosm_m1_1_osm_temp AS osm ON (dea.reaosm_sort = osm.reaosm_sort); + + UPDATE sandbox.ego_dp_res_powerplant_reaosm AS t1 + SET reaosm_geom_new = t2.reaosm_geom_new, + reaosm_geom_line = t2.reaosm_geom_line, + reaosm_flag = ''M1-1'' + FROM (SELECT m.id AS id, + m.reaosm_geom_line, + m.geom AS reaosm_geom_new + FROM sandbox.ego_reaosm_m1_1_jnt_temp AS m + )AS t2 + WHERE t1.id = t2.id; + + TRUNCATE TABLE sandbox.ego_reaosm_m1_1_dea_temp, sandbox.ego_reaosm_m1_1_osm_temp, sandbox.ego_reaosm_m1_1_jnt_temp; + '; + END LOOP; +END; +$$; + +-- M1-1 result +DROP MATERIALIZED VIEW IF EXISTS sandbox.ego_reaosm_m1_1_mview CASCADE; +CREATE MATERIALIZED VIEW sandbox.ego_reaosm_m1_1_mview AS + SELECT dea.* + FROM sandbox.ego_dp_res_powerplant_reaosm AS dea + WHERE rea_flag = 'M1-1'; + +-- create index GIST (geom) +CREATE INDEX ego_reaosm_m1_1_mview_geom_idx + ON sandbox.ego_reaosm_m1_1_mview USING gist (geom); + +-- create index GIST (rea_geom_line) +CREATE INDEX ego_reaosm_m1_1_mview_rea_geom_line_idx + ON sandbox.ego_reaosm_m1_1_mview USING gist (rea_geom_line); + +-- create index GIST (rea_geom_new) +CREATE INDEX ego_reaosm_m1_1_mview_rea_geom_new_idx + ON sandbox.ego_reaosm_m1_1_mview USING gist (rea_geom_new); + +-- grant (oeuser) +ALTER TABLE sandbox.ego_reaosm_m1_1_mview OWNER TO oeuser; + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +--SELECT scenario_log('eGo_REAOSM','v0.1','output','sandbox','ego_reaosm_m1_1_mview','ego_dp_reaosm_m1.sql',' '); + + +-- M1-1 rest +DROP MATERIALIZED VIEW IF EXISTS model_draft.ego_supply_rea_m1_1_rest_mview CASCADE; +CREATE MATERIALIZED VIEW model_draft.ego_supply_rea_m1_1_rest_mview AS + SELECT id, + electrical_capacity, + generation_type, + generation_subtype, + voltage_level, + subst_id, + geom, + rea_flag + FROM sandbox.ego_dp_res_powerplant_reaosm AS dea + WHERE dea.rea_flag = 'M1-1_rest'; + +-- create index GIST (geom) +CREATE INDEX ego_supply_rea_m1_1_rest_mview_geom_idx + ON model_draft.ego_supply_rea_m1_1_rest_mview USING gist (geom); + +-- grant (oeuser) +ALTER TABLE model_draft.ego_supply_rea_m1_1_rest_mview OWNER TO oeuser; + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +SELECT scenario_log('eGo_REAOSM','v0.1','output','model_draft','ego_supply_rea_m1_1_rest_mview','ego_dp_reaosm_m1.sql',' '); + +-- Drop temp +DROP TABLE IF EXISTS sandbox.ego_reaosm_m1_1_dea_temp CASCADE; +DROP TABLE IF EXISTS sandbox.ego_reaosm_m1_1_osm_temp CASCADE; +DROP TABLE IF EXISTS sandbox.ego_reaosm_m1_1_jnt_temp CASCADE; + + +/* 2. M1-2 +Move "solar roof mounted" with "4" to OSM agricultural areas. +The rest could not be allocated, consider in M4. +*/ + +-- MView M1-2 +DROP MATERIALIZED VIEW IF EXISTS model_draft.ego_supply_rea_m1_2_a_mview CASCADE; +CREATE MATERIALIZED VIEW model_draft.ego_supply_rea_m1_2_a_mview AS + SELECT id, + electrical_capacity, + generation_type, + generation_subtype, + voltage_level, + subst_id, + ST_TRANSFORM(geom,3035) AS geom, + rea_flag + FROM sandbox.ego_dp_res_powerplant_reaosm AS dea + WHERE (dea.voltage_level = 4 OR dea.voltage_level = 5) AND + (dea.generation_subtype = 'solar_roof_mounted') + AND (dea.flag in ('commissioning','constantly')); + +-- create index GIST (geom) +CREATE INDEX ego_supply_rea_m1_2_a_mview_geom_idx + ON model_draft.ego_supply_rea_m1_2_a_mview USING gist (geom); + +-- grant (oeuser) +ALTER TABLE model_draft.ego_supply_rea_m1_2_a_mview OWNER TO oeuser; + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +SELECT scenario_log('eGo_REAOSM','v0.1','temp','model_draft','ego_supply_rea_m1_2_a_mview','ego_dp_reaosm_m1.sql',' '); + + +-- rea_flag M1-2 +UPDATE sandbox.ego_dp_res_powerplant_reaosm AS dea + SET rea_flag = 'M1-2_rest' + WHERE (dea.voltage_level = 4 OR dea.voltage_level = 5) AND + (dea.generation_subtype = 'solar_roof_mounted') + AND (dea.flag in ('commissioning','constantly')); + + +-- create temporary tables for the loop +DROP TABLE IF EXISTS model_draft.ego_supply_rea_m1_2_dea_temp CASCADE; +CREATE TABLE model_draft.ego_supply_rea_m1_2_dea_temp ( + rea_sorted bigint NOT NULL, + id bigint NOT NULL, + electrical_capacity numeric, + generation_type text, + generation_subtype character varying, + voltage_level character varying, + subst_id integer, + geom geometry(Point,3035), + rea_flag character varying, + CONSTRAINT ego_supply_rea_m1_2_dea_temp_pkey PRIMARY KEY (rea_sorted)); + +CREATE INDEX ego_supply_rea_m1_2_dea_temp_geom_idx + ON model_draft.ego_supply_rea_m1_2_dea_temp USING gist (geom); + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +SELECT scenario_log('eGo_REAOSM','v0.1','temp','model_draft','ego_supply_rea_m1_2_dea_temp','ego_dp_reaosm_m1.sql',' '); + +DROP TABLE IF EXISTS model_draft.ego_supply_rea_m1_2_osm_temp ; +CREATE TABLE model_draft.ego_supply_rea_m1_2_osm_temp ( + rea_sorted bigint NOT NULL, + id integer, + subst_id integer, + area_ha numeric, + geom geometry(Polygon,3035), + CONSTRAINT ego_supply_rea_m1_2_osm_temp_pkey PRIMARY KEY (rea_sorted)); + +CREATE INDEX ego_supply_rea_m1_2_osm_temp_geom_idx + ON model_draft.ego_supply_rea_m1_2_osm_temp USING gist (geom); + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +SELECT scenario_log('eGo_REAOSM','v0.1','temp','model_draft','ego_supply_rea_m1_2_osm_temp','ego_dp_reaosm_m1.sql',' '); + +DROP TABLE IF EXISTS model_draft.ego_supply_rea_m1_2_jnt_temp CASCADE; +CREATE TABLE model_draft.ego_supply_rea_m1_2_jnt_temp ( + rea_sorted bigint NOT NULL, + id bigint, + electrical_capacity numeric, + generation_type text, + generation_subtype character varying, + voltage_level character varying, + subst_id integer, + old_geom geometry(Point,3035), + rea_geom_line geometry(LineString,3035), + geom geometry(Point,3035), + CONSTRAINT ego_supply_rea_m1_2_jnt_temp_pkey PRIMARY KEY (rea_sorted)); + +CREATE INDEX ego_supply_rea_m1_2_jnt_temp_geom_idx + ON model_draft.ego_supply_rea_m1_2_jnt_temp USING gist (geom); + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +SELECT scenario_log('eGo_REAOSM','v0.1','temp','model_draft','ego_supply_rea_m1_2_jnt_temp','ego_dp_reaosm_m1.sql',' '); + +-- loop for grid_district +DO +$$ +DECLARE gd integer; +BEGIN + FOR gd IN 1..3591 -- subst_id + LOOP + EXECUTE ' + INSERT INTO model_draft.ego_supply_rea_m1_2_dea_temp + SELECT row_number() over (ORDER BY dea.electrical_capacity DESC)as rea_sorted, + dea.* + FROM model_draft.ego_supply_rea_m1_2_a_mview AS dea + WHERE dea.subst_id =' || gd || '; + + INSERT INTO model_draft.ego_supply_rea_m1_2_osm_temp + SELECT row_number() over (ORDER BY osm.area_ha DESC)as rea_sorted, + osm.id, + osm.subst_id, + osm.area_ha, + osm.geom + FROM model_draft.ego_osm_sector_per_griddistrict_4_agricultural AS osm + WHERE subst_id =' || gd || '; + + INSERT INTO model_draft.ego_supply_rea_m1_2_jnt_temp + SELECT dea.rea_sorted, + dea.id, + dea.electrical_capacity, + dea.generation_type, + dea.generation_subtype, + dea.voltage_level, + dea.subst_id, + dea.geom AS old_geom, + ST_MAKELINE(dea.geom,ST_CENTROID(osm.geom)) ::geometry(LineString,3035) AS rea_geom_line, + ST_CENTROID(osm.geom) ::geometry(Point,3035) AS geom -- NEW LOCATION! + FROM model_draft.ego_supply_rea_m1_2_dea_temp AS dea + INNER JOIN model_draft.ego_supply_rea_m1_2_osm_temp AS osm ON (dea.rea_sorted = osm.rea_sorted); + + UPDATE sandbox.ego_dp_res_powerplant_reaosm AS t1 + SET rea_geom_new = t2.rea_geom_new, + rea_geom_line = t2.rea_geom_line, + rea_flag = ''M1-2'' + FROM (SELECT m.id AS id, + m.rea_geom_line, + m.geom AS rea_geom_new + FROM model_draft.ego_supply_rea_m1_2_jnt_temp AS m + )AS t2 + WHERE t1.id = t2.id; + + TRUNCATE TABLE model_draft.ego_supply_rea_m1_2_dea_temp, model_draft.ego_supply_rea_m1_2_osm_temp, model_draft.ego_supply_rea_m1_2_jnt_temp; + '; + END LOOP; +END; +$$; + +-- M1-2 result +DROP MATERIALIZED VIEW IF EXISTS model_draft.ego_supply_rea_m1_2_mview CASCADE; +CREATE MATERIALIZED VIEW model_draft.ego_supply_rea_m1_2_mview AS + SELECT dea.* + FROM sandbox.ego_dp_res_powerplant_reaosm AS dea + WHERE rea_flag = 'M1-2'; + +-- create index GIST (geom) +CREATE INDEX ego_supply_rea_m1_2_mview_geom_idx + ON model_draft.ego_supply_rea_m1_2_mview USING gist (geom); + +-- create index GIST (rea_geom_line) +CREATE INDEX ego_supply_rea_m1_2_mview_rea_geom_line_idx + ON model_draft.ego_supply_rea_m1_2_mview USING gist (rea_geom_line); + +-- create index GIST (rea_geom_new) +CREATE INDEX ego_supply_rea_m1_2_mview_rea_geom_new_idx + ON model_draft.ego_supply_rea_m1_2_mview USING gist (rea_geom_new); + +-- grant (oeuser) +GRANT ALL ON TABLE model_draft.ego_supply_rea_m1_2_mview TO oeuser WITH GRANT OPTION; +ALTER TABLE model_draft.ego_supply_rea_m1_2_mview OWNER TO oeuser; + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +SELECT scenario_log('eGo_REAOSM','v0.1','output','model_draft','ego_supply_rea_m1_2_mview','ego_dp_reaosm_m1.sql',' '); + +-- M1-2 rest +DROP MATERIALIZED VIEW IF EXISTS model_draft.ego_supply_rea_m1_2_rest_mview CASCADE; +CREATE MATERIALIZED VIEW model_draft.ego_supply_rea_m1_2_rest_mview AS + SELECT id, + electrical_capacity, + generation_type, + generation_subtype, + voltage_level, + subst_id, + geom, + rea_flag + FROM sandbox.ego_dp_res_powerplant_reaosm AS dea + WHERE dea.rea_flag = 'M1-2_rest'; + +-- create index GIST (geom) +CREATE INDEX ego_supply_rea_m1_2_rest_mview_geom_idx + ON model_draft.ego_supply_rea_m1_2_rest_mview USING gist (geom); + +-- grant (oeuser) +ALTER TABLE model_draft.ego_supply_rea_m1_2_rest_mview OWNER TO oeuser; + +-- scenario log (project,version,io,schema_name,table_name,script_name,comment) +SELECT scenario_log('eGo_REAOSM','v0.1','output','model_draft','ego_supply_rea_m1_2_rest_mview','ego_dp_reaosm_m1.sql',' '); + + +-- Drop temp +DROP TABLE IF EXISTS model_draft.ego_supply_rea_m1_2_dea_temp CASCADE; +DROP TABLE IF EXISTS model_draft.ego_supply_rea_m1_2_osm_temp CASCADE; +DROP TABLE IF EXISTS model_draft.ego_supply_rea_m1_2_jnt_temp CASCADE; + +--DROP MATERIALIZED VIEW IF EXISTS model_draft.ego_reaosm_m1_1_a_mview CASCADE; +DROP MATERIALIZED VIEW IF EXISTS model_draft.ego_supply_rea_m1_2_a_mview CASCADE; diff --git a/dataprocessing/sql_snippets/rea/reaosm/ego_dp_reaosm_setup.sql b/dataprocessing/sql_snippets/rea/reaosm/ego_dp_reaosm_setup.sql index cc07f354..389d40cd 100644 --- a/dataprocessing/sql_snippets/rea/reaosm/ego_dp_reaosm_setup.sql +++ b/dataprocessing/sql_snippets/rea/reaosm/ego_dp_reaosm_setup.sql @@ -65,8 +65,8 @@ COMMENT ON MATERIALIZED VIEW sandbox.ego_pp_osm_deu_power_point_mview IS '{ "version": "v0.1" }' ; -- scenario log (project,version,io,schema_name,table_name,script_name,comment) -SELECT scenario_log('eGo_PP_REAOSM', 'v0.1','input','sandbox','ego_pp_osm_deu_power_point','ego_pp_osm_deu_power.sql',' '); -SELECT scenario_log('eGo_PP_REAOSM', 'v0.1','output','sandbox','ego_pp_osm_deu_power_point_mview','ego_pp_osm_deu_power.sql',' '); +SELECT scenario_log('eGo_REAOSM','v0.1','input','sandbox','ego_pp_osm_deu_power_point','ego_pp_osm_deu_power.sql',' '); +SELECT scenario_log('eGo_REAOSM','v0.1','output','sandbox','ego_pp_osm_deu_power_point_mview','ego_pp_osm_deu_power.sql',' '); -- Allocate to REA methods @@ -95,7 +95,7 @@ COMMENT ON TABLE sandbox.ego_pp_osm_deu_power_point_reaosm IS '{ "version": "v0.1" }' ; -- scenario log (project,version,io,schema_name,table_name,script_name,comment) -SELECT scenario_log('eGo_PP_REAOSM', 'v0.1','setup','sandbox','ego_pp_osm_deu_power_point_reaosm','ego_pp_osm_deu_power.sql',' '); +SELECT scenario_log('eGo_REAOSM','v0.1','setup','sandbox','ego_pp_osm_deu_power_point_reaosm','ego_pp_osm_deu_power.sql',' '); -- insert M1 @@ -126,7 +126,7 @@ INSERT INTO sandbox.ego_pp_osm_deu_power_point_reaosm (osm_id, rea_method, geom) ORDER BY osm_id; -- scenario log (project,version,io,schema_name,table_name,script_name,comment) -SELECT scenario_log('eGo_PP_REAOSM', 'v0.1','output','sandbox','ego_pp_osm_deu_power_point_reaosm','ego_pp_osm_deu_power.sql',' '); +SELECT scenario_log('eGo_REAOSM','v0.1','output','sandbox','ego_pp_osm_deu_power_point_reaosm','ego_pp_osm_deu_power.sql',' '); -- eGo Grid District @@ -161,8 +161,8 @@ COMMENT ON MATERIALIZED VIEW grid.ego_dp_mv_griddistrict_v0_4_3_mview IS '{ "version": "v0.1" }' ; -- scenario log (project,version,io,schema_name,table_name,script_name,comment) -SELECT scenario_log('eGo_PP_REAOSM', 'v0.1','input','grid','ego_dp_mv_griddistrict','ego_pp_osm_deu_power.sql',' '); -SELECT scenario_log('eGo_PP_REAOSM', 'v0.1','output','grid','ego_dp_mv_griddistrict_v0_4_3_mview','ego_pp_osm_deu_power.sql',' '); +SELECT scenario_log('eGo_REAOSM','v0.1','input','grid','ego_dp_mv_griddistrict','ego_pp_osm_deu_power.sql',' '); +SELECT scenario_log('eGo_REAOSM','v0.1','output','grid','ego_dp_mv_griddistrict_v0_4_3_mview','ego_pp_osm_deu_power.sql',' '); -- update subst_id from eGo mv_grid_district @@ -213,8 +213,8 @@ COMMENT ON MATERIALIZED VIEW demand.ego_dp_loadarea_v0_4_3_mview IS '{ "version": "v0.1" }' ; -- scenario log (project,version,io,schema_name,table_name,script_name,comment) -SELECT scenario_log('eGo_PP_REAOSM', 'v0.1','input','demand','ego_dp_loadarea','ego_pp_osm_deu_power.sql',' '); -SELECT scenario_log('eGo_PP_REAOSM', 'v0.1','output','demand','ego_dp_loadarea_v0_4_3_mview','ego_pp_osm_deu_power.sql',' '); +SELECT scenario_log('eGo_REAOSM','v0.1','input','demand','ego_dp_loadarea','ego_pp_osm_deu_power.sql',' '); +SELECT scenario_log('eGo_REAOSM','v0.1','output','demand','ego_dp_loadarea_v0_4_3_mview','ego_pp_osm_deu_power.sql',' '); -- update subst_id from eGo mv_grid_district @@ -225,7 +225,6 @@ UPDATE sandbox.ego_pp_osm_deu_power_point_reaosm AS t1 a.id AS la_id FROM demand.ego_dp_loadarea_v0_4_3_mview AS a, sandbox.ego_pp_osm_deu_power_point_reaosm AS b - WHERE a.geom && b.geom AND ST_CONTAINS(a.geom,b.geom) ) AS t2 @@ -251,11 +250,31 @@ CREATE TABLE sandbox.ego_dp_res_powerplant_reaosm AS -- PK (id) ALTER TABLE sandbox.ego_dp_res_powerplant_reaosm ADD PRIMARY KEY (id); +ALTER TABLE sandbox.ego_dp_res_powerplant_reaosm + DROP COLUMN IF EXISTS reaosm_sort CASCADE, + ADD COLUMN reaosm_sort integer, + DROP COLUMN IF EXISTS reaosm_flag CASCADE, + ADD COLUMN reaosm_flag character varying, + DROP COLUMN IF EXISTS reaosm_geom_line CASCADE, + ADD COLUMN reaosm_geom_line geometry(LineString,3035), + DROP COLUMN IF EXISTS reaosm_geom_new CASCADE, + ADD COLUMN reaosm_geom_new geometry(Point,3035); + -- index GIST (geom) CREATE INDEX ego_dp_res_powerplant_reaosm_geom_idx ON sandbox.ego_dp_res_powerplant_reaosm USING GIST (geom); +-- index GIST (rea_geom_new) +CREATE INDEX ego_dp_res_powerplant_reaosm_rea_geom_new_idx + ON sandbox.ego_dp_res_powerplant_reaosm + USING GIST (rea_geom_new); + +-- index GIST (reaosm_geom_new) +CREATE INDEX ego_dp_res_powerplant_reaosm_reaosm_geom_new_idx + ON sandbox.ego_dp_res_powerplant_reaosm + USING GIST (reaosm_geom_new); + -- grant (oeuser) ALTER TABLE sandbox.ego_dp_res_powerplant_reaosm OWNER TO oeuser; @@ -264,9 +283,11 @@ COMMENT ON TABLE sandbox.ego_dp_res_powerplant_reaosm IS '{ "comment": "eGoPP - REA OSM - Temporary Table", "version": "v0.1" }' ; + + -- scenario log (project,version,io,schema_name,table_name,script_name,comment) -SELECT scenario_log('eGo_PP_REAOSM', 'v0.1','input','supply','ego_dp_res_powerplant','ego_pp_osm_deu_power.sql',' '); -SELECT scenario_log('eGo_PP_REAOSM', 'v0.1','output','sandbox','ego_dp_res_powerplant_reaosm','ego_pp_osm_deu_power.sql',' '); +SELECT scenario_log('eGo_REAOSM','v0.1','input','supply','ego_dp_res_powerplant','ego_pp_osm_deu_power.sql',' '); +SELECT scenario_log('eGo_REAOSM','v0.1','output','sandbox','ego_dp_res_powerplant_reaosm','ego_pp_osm_deu_power.sql',' ');