public override void Initialize(DateTime Start, DateTime End, IEnumerable<Catchment> Catchments) { base.Initialize(Start, End, Catchments); List<Wetland> wetlands = new List<Wetland>(); using (ShapeReader sr = new ShapeReader(ShapeFile.FileName)) { foreach (var ldata in sr.GeoData) { Wetland w = new Wetland { Geometry = (IXYPolygon) ldata.Geometry, Name = ldata.Data[ShapeFile.ColumnNames[1]].ToString(), }; int startyear = int.Parse(ldata.Data[ShapeFile.ColumnNames[0]].ToString()); if (startyear != 0) w.StartTime = new DateTime(startyear, 1, 1); else w.StartTime = Start; wetlands.Add(w); } } //Get the soil type Parallel.ForEach(wetlands, l => { foreach (var soil in MainModel.SoilTypes) { if (l.Geometry.OverLaps((IXYPolygon)soil.Geometry)) { if ((int)soil.Data[0] < 4) l.SoilString = "sand"; else l.SoilString = "ler"; break; } } }); Parallel.ForEach(wetlands, l => { foreach (var c in Catchments) if (c.Geometry.OverLaps(l.Geometry as IXYPolygon)) { lock (Lock) { c.Wetlands.Add(l); } } }); NewMessage(wetlands.Count + " wetlands read and distributed on " + Catchments.Count(c => c.Wetlands.Count > 0) + " catchments."); }
public override void Initialize(DateTime Start, DateTime End, IEnumerable <Catchment> Catchments) { base.Initialize(Start, End, Catchments); List <Wetland> wetlands = new List <Wetland>(); using (ShapeReader sr = new ShapeReader(ShapeFile.FileName)) { foreach (var ldata in sr.GeoData) { Wetland w = new Wetland { Geometry = (IXYPolygon)ldata.Geometry, Name = ldata.Data[ShapeFile.ColumnNames[1]].ToString(), }; int startyear = int.Parse(ldata.Data[ShapeFile.ColumnNames[0]].ToString()); if (startyear != 0) { w.StartTime = new DateTime(startyear, 1, 1); } else { w.StartTime = Start; } wetlands.Add(w); } } //Get the soil type Parallel.ForEach(wetlands, l => { foreach (var soil in MainModel.SoilTypes) { if (l.Geometry.OverLaps((IXYPolygon)soil.Geometry)) { if ((int)soil.Data[0] < 4) { l.SoilString = "sand"; } else { l.SoilString = "ler"; } break; } } }); Parallel.ForEach(wetlands, l => { foreach (var c in Catchments) { if (c.Geometry.OverLaps(l.Geometry as IXYPolygon)) { lock (Lock) { c.Wetlands.Add(l); } } } }); NewMessage(wetlands.Count + " wetlands read and distributed on " + Catchments.Count(c => c.Wetlands.Count > 0) + " catchments."); }