public Dictionary <int, List <int> > GetZone() { Dictionary <int, List <int> > dic = new Dictionary <int, List <int> >(); var fs_centroid = ProjectService.Project.CentroidLayer.FeatureSet; var fs = FeatureLayer.DataSet as IFeatureSet; var dt = fs.DataTable; var npolygon = fs.NumRows(); var npt = fs_centroid.NumRows(); var polygon = new List <IFeature>(); var list_id = new List <int>(); for (int i = 0; i < npolygon; i++) { var id = int.Parse(dt.Rows[i][ZoneField].ToString()); var pts = new List <int>(); dic.Add(id, pts); var py = fs.GetFeature(i); polygon.Add(py); list_id.Add(id); } for (int i = 0; i < npt; i++) { var geo_pt = fs_centroid.GetFeature(i).Geometry; int t = 0; foreach (var fea in polygon) { if (SpatialRelationship.PointInPolygon(fea.Geometry.Coordinates, geo_pt.Coordinates[0])) { dic[list_id[t]].Add(i); break; } t++; } } return(dic); }
public override void Map() { int progress = 0; OnProcessing(progress); int count = 1; if (Source is IFeatureSet) { try { var fea_target = TargetFeatureSet.Features; var fea_source = (Source as FeatureSet); int nfea_target = fea_target.Count; int[] target_index = new int[nfea_target]; DataTable dt_source = fea_source.DataTable; int index_ap = 0; for (int i = 0; i < nfea_target; i++) { target_index[i] = -1; int j = 0; foreach (var fea in fea_source.Features) { if (SpatialRelationship.PointInPolygon(fea.Geometry.Coordinates, fea_target[i].Geometry.Coordinates[0])) { target_index[i] = j; break; } j++; } progress = i * 100 / nfea_target; OnProcessing(progress); } OnProcessing(0); foreach (var ap in ArealProperties) { var vv = Package.GetType().GetProperty(ap.PropertyName).GetValue(Package); if (vv != null) { if (ap.TypeName == typeof(float).FullName) { var fl = vv as DataCube <float>; if (fl[GridLayer] != null) { for (int i = 0; i < nfea_target; i++) { if (target_index[i] >= 0) { fl[GridLayer, 0, i] = float.Parse(GetValue(ap.AliasName, target_index[i])); } else { fl[GridLayer, 0, i] = (float)ap.DefaultValue; } } } } else if (ap.TypeName == typeof(short).FullName) { var fl = vv as DataCube <short>; if (fl[GridLayer] != null) { for (int i = 0; i < nfea_target; i++) { if (target_index[i] >= 0) { fl[GridLayer, 0, i] = short.Parse(GetValue(ap.AliasName, target_index[i])); } else { fl[GridLayer, 0, i] = (short)ap.DefaultValue; } } } } } progress = index_ap * 100 / ArealProperties.Count; if (progress > count) { OnProcessing(progress); count++; } index_ap++; } OnProcessing(100); OnProcessed(ConstantWords.Successful); } catch (Exception ex) { OnProcessing(100); OnProcessed("Failed. Error message: " + ex.Message); } } }
public IGrid Generate() { if (Source == null) { Source = new RegularGrid(); } if (Domain != null) { Source.Origin = this.Origin; Source.ActualLayerCount = this.LayerCount; Source.RowCount = RowCount; Source.ColumnCount = ColumnCount; Source.IBound = new DataCube <float>(this.LayerCount, RowCount, ColumnCount); Source.DELC = new DataCube <float>(1, 1, RowCount); Source.DELR = new DataCube <float>(1, 1, ColumnCount); Source.DELC.Flags[0, 0] = TimeVarientFlag.Constant; Source.DELR.Flags[0, 0] = TimeVarientFlag.Constant; Source.DELC.Constants[0, 0] = this.XSize; Source.DELR.Constants[0, 0] = this.YSize; Source.DELC.ILArrays[0]["0", ":"] = this.XSize; Source.DELR.ILArrays[0]["0", ":"] = this.YSize; Source.Projection = Domain.Projection; Source.BBox = new Envelope(Domain.Extent.MinX, Domain.Extent.MaxX, Domain.Extent.MinY, Domain.Extent.MaxY); int active = 0; var geo = Domain.Features[0].Geometry.Coordinates; List <Coordinate> centroids = new List <Coordinate>(); for (int r = 0; r < RowCount; r++) { for (int c = 0; c < ColumnCount; c++) { var cor = Source.LocateCentroid(c + 1, r + 1); if (SpatialRelationship.PointInPolygon(geo, cor)) { for (int l = 0; l < Source.ActualLayerCount; l++) { Source.IBound[l, r, c] = 1; } active++; centroids.Add(cor); } } } Source.ActiveCellCount = active; Source.Elevations = new DataCube <float>(Source.LayerCount, 1, active); Source.Elevations.Variables[0] = "Top Elevation"; for (int i = 0; i < active; i++) { //var cell = DEM.ProjToCell(centroids[i]); //if (cell != null && cell.Row > 0) // Source.Elevations.Value[0][0][i] = (float)DEM.Value[cell.Row, cell.Column]; //else // Source.Elevations.Value[0][0][i] = 0; var pt = new Coordinate(centroids[i].X - 0.5 * XSize, centroids[i].Y - 0.5 * YSize); Source.Elevations[0, 0, i] = ZonalStatastics.GetCellAverage(DEM, pt, XSize, AveragingMethod); } for (int l = 1; l < Source.LayerCount; l++) { Source.Elevations.Variables[l] = string.Format("Layer {0} Bottom Elevation", l); for (int i = 0; i < active; i++) { Source.Elevations[l, 0, i] = (float)(Source.Elevations[l - 1, 0, i] - LayerGroups[l - 1].LayerHeight); } } Source.BuildTopology(); Source.Elevations.Topology = Source.Topology; } else { Error = "The domain featureset is null"; } return(Source); }
public override bool Execute(ICancelProgressHandler cancelProgressHandler) { var shell = MyAppManager.Instance.CompositionContainer.GetExportedValue <IShellService>(); var prj = MyAppManager.Instance.CompositionContainer.GetExportedValue <IProjectService>(); var model = prj.Project.Model; int progress = 0; int count = 1; Modflow mf = null; if (model is HeiflowModel) { mf = (model as HeiflowModel).ModflowModel; } else if (model is Modflow) { mf = model as Modflow; } if (mf != null) { if (!mf.Packages.ContainsKey(FHBPackage.PackageName)) { var fhb = mf.Select(FHBPackage.PackageName); mf.Add(fhb); } var pck = mf.GetPackage(FHBPackage.PackageName) as FHBPackage; pck.NBDTIM = 2; pck.NHED = 0; pck.IFHBSS = 1; pck.BDTIM = new int[] { 0, prj.Project.Model.TimeService.NumTimeStep }; List <FlowBound> list = new List <FlowBound>(); int npt = _sourcefs.Features.Count; for (int i = 0; i < npt; i++) { var pt = _sourcefs.Features[i].Geometry.Coordinate; int layer = 1; float rate = 0; if (!string.IsNullOrEmpty(LayerField)) { int.TryParse(_sourcefs.DataTable.Rows[i][LayerField].ToString(), out layer); } if (!string.IsNullOrEmpty(FluxRateField)) { float.TryParse(_sourcefs.DataTable.Rows[i][FluxRateField].ToString(), out rate); } for (int j = 0; j < _grid_layer.Features.Count; j++) { var cell = _grid_layer.Features[j].Geometry.Coordinates; if (SpatialRelationship.PointInPolygon(cell, pt)) { FlowBound bound = new FlowBound() { Layer = layer, FlowRate = rate, Row = int.Parse(_grid_layer.DataTable.Rows[j]["ROW"].ToString()), Col = int.Parse(_grid_layer.DataTable.Rows[j]["COLUMN"].ToString()), }; list.Add(bound); break; } } progress = i * 100 / npt; if (progress > count) { cancelProgressHandler.Progress("Package_Tool", progress, "Processing point: " + i); count++; } } if (list.Count > 0) { pck.NFLW = list.Count; var FlowRate = new DataCube <float>(4 + pck.NBDTIM, 1, pck.NFLW) { Name = "FHB_FlowRate", TimeBrowsable = false, AllowTableEdit = true }; FlowRate.Variables[0] = "Layer";//Layer Row Column IAUX FLWRAT(NBDTIM) FlowRate.Variables[1] = "Row"; FlowRate.Variables[2] = "Column"; FlowRate.Variables[3] = "IAUX"; for (int i = 0; i < pck.NBDTIM; i++) { FlowRate.Variables[4 + i] = "FLWRAT " + (i + 1); } for (int i = 0; i < pck.NFLW; i++) { var bound = list[i]; FlowRate[0, 0, i] = bound.Layer; FlowRate[1, 0, i] = bound.Row; FlowRate[2, 0, i] = bound.Col; FlowRate[3, 0, i] = 0; for (int j = 0; j < pck.NBDTIM; j++) { FlowRate[4 + j, 0, i] = bound.FlowRate; } } FlowRate.TimeBrowsable = false; pck.FlowRate = FlowRate; pck.CreateFeature(shell.MapAppManager.Map.Projection, prj.Project.GeoSpatialDirectory); pck.BuildTopology(); pck.IsDirty = true; pck.Save(null); pck.ChangeState(Models.Generic.ModelObjectState.Ready); } else { pck.ChangeState(Models.Generic.ModelObjectState.Standby); cancelProgressHandler.Progress("Package_Tool", 100, "Warning: no points located in the modeling domain."); } return(true); } else { cancelProgressHandler.Progress("Package_Tool", 100, "Error message: Modflow is used by this tool."); return(false); } }