 -- Create sector table
 ------------------------------------------
 -- Wähle Sektorflächen für jeden Grid District aus:
-CREATE TABLE IF NOT EXISTS calc_ego_grid_district.ego_deu_grid_district_sectors
+CREATE TABLE IF NOT EXISTS model_draft."ego_grid_lv_griddistrictsectors"
 (
   id serial NOT NULL,
   geom geometry,


-- industrial
SELECT (ST_DUMP(ST_INTERSECTION(ST_UNION(sector3.geom),grid_district.geom))).geom AS geom, grid_district.id AS grid_district_id, grid_district.load_area_id AS load_area_id, 'industrial' AS sector
FROM 	calc_ego_loads.urban_sector_per_grid_district_3_industrial AS sector3,
	calc_ego_grid_district.ego_deu_lv_grid_district AS grid_district
WHERE  ST_INTERSECTS(grid_district.geom,sector3.geom)
GROUP BY grid_district.id, grid_district.geom, load_area_id


  ont_count integer,
  ont_id integer,
  merge_id integer,
  CONSTRAINT ego_grid_lv_cut_pkey PRIMARY KEY (id)
);
 
TRUNCATE TABLE 	model_draft."ego_grid_lv_cut";
INSERT INTO		model_draft."ego_grid_lv_cut" 
	SELECT	(ST_DUMP(ST_INTERSECTION(mun.geom,voi.geom))).geom ::geometry(Polygon,3035) AS geom, mun.id AS load_area_id
	FROM	model_draft."ego_demand_loadarea" AS mun,
		model_draft."ego_grid_lv_griddistrictsvoronoi" AS voi
	WHERE	mun.geom && voi.geom 
		AND mun.subst_id = voi.subst_id
		-- make sure the boundaries really intersect and not just touch each other
