 	mv_dea_capacity	decimal,
 	geom_type	text,
 	geom		geometry(MultiPolygon,3035),
-	CONSTRAINT ego_grid_mv_griddistrict_new_pkey PRIMARY KEY (subst_id));
+	CONSTRAINT ego_grid_mv_griddistrict_pkey PRIMARY KEY (subst_id));
 
 -- insert mvgd
-INSERT INTO	model_draft.ego_grid_mv_griddistrict_new (subst_id,geom)
-	SELECT 	subst_id,
-		ST_MULTI(geom)
-	FROM	model_draft.ego_grid_mv_griddistrict_dump_1sub
-	ORDER BY subst_id;
-
--- index GIST (geom)
-CREATE INDEX	ego_grid_mv_griddistrict_new_geom_idx
-	ON	model_draft.ego_grid_mv_griddistrict_new USING GIST (geom);
-
--- grant (oeuser)
-ALTER TABLE	model_draft.ego_grid_mv_griddistrict_new OWNER TO oeuser;
+INSERT INTO	model_draft.ego_grid_mv_griddistrict (subst_id,geom)
+	SELECT DISTINCT ON 	(dis.subst_id)
+				dis.subst_id AS subst_id,
+				ST_MULTI(ST_UNION(dis.geom)) ::geometry(MultiPolygon,3035) AS geom
+			FROM	model_draft.ego_grid_mv_griddistrict_collect AS dis
+		GROUP BY 	dis.subst_id;
+
+-- index GIST (geom)
+CREATE INDEX	ego_grid_mv_griddistrict_geom_idx
+	ON	model_draft.ego_grid_mv_griddistrict USING GIST (geom);
+
+-- grant (oeuser)
+ALTER TABLE	model_draft.ego_grid_mv_griddistrict OWNER TO oeuser;
 
 -- Count Substations in Grid Districts
-UPDATE 	model_draft.ego_grid_mv_griddistrict_new AS t1
-	SET  	geom = t2.geom
-	FROM	(SELECT	subst_id,
-			geom
-		FROM	model_draft.ego_grid_mv_griddistrict_dump_nn_collect_union
-		)AS t2
-	WHERE  	t1.subst_id = t2.subst_id;
-
--- Count Substations in Grid Districts
-UPDATE 	model_draft.ego_grid_mv_griddistrict_new AS t1
+UPDATE 	model_draft.ego_grid_mv_griddistrict AS t1
 	SET  	subst_sum = t2.subst_sum,
 		area_ha = t2.area_ha,
 		geom_type = t2.geom_type

-- ego scenario log (version,io,schema_name,table_name,script_name,comment)
SELECT ego_scenario_log('v0.2.5','temp','model_draft','ego_grid_mv_griddistrict_collect','ego_dp_mv_griddistrict.sql',' ');

-- NEW PART HERE! 



-- create grid district


-- grant (oeuser)
ALTER TABLE	model_draft.ego_grid_mv_griddistrict OWNER TO oeuser;

-- Count Substations in Grid Districts
UPDATE 	model_draft.ego_grid_mv_griddistrict AS t1
	SET  	geom = t2.geom
	FROM	(SELECT	subst_id,
			geom
		FROM	model_draft.ego_grid_mv_griddistrict_dump_nn_collect_union
		)AS t2
	WHERE  	t1.subst_id = t2.subst_id;

-- Count Substations in Grid Districts
UPDATE 	model_draft.ego_grid_mv_griddistrict AS t1
