/// <summary> /// Method to query all features that intersect a given <see cref="extent"/> /// </summary> /// <param name="extent">The area used to look for features</param> /// <returns>An enumeration of features</returns> public System.Collections.Generic.IEnumerable <IFeature> Intersect(Extent extent) { var env = new SharpSbn.DataStructures.Envelope(extent.MinX, extent.MaxX, extent.MinY, extent.MaxY); foreach (var queryFid in _tree.QueryFids(env)) { var fid = (int)queryFid - 1; yield return(_featureSet.GetFeature(fid)); } }
/// <summary> /// Erase features from one feature set where they are intersected by another feature set. /// </summary> /// <param name="targetFeatures">Features which will be erased in part or whole.</param> /// <param name="sourceFeatures">Features which represent areas to erase.</param> /// <param name="cancelProgressHandler">Optional parameter to report progress and cancel entire process if needed.</param> /// <returns>A point feature set with the randomly created features.</returns> public static FeatureSet EraseFeatures(IFeatureSet targetFeatures, IFeatureSet sourceFeatures, ICancelProgressHandler cancelProgressHandler = null) { if (targetFeatures == null || sourceFeatures == null) { return(null); } // Erase features from one feature set where they are intersected by another feature set // Note: we use the ShapeIndices here rather than for each feature in featureset.features as a memory management technique. // The current version does not preserve any attribute info. // Dan Ames 2/27/2013 FeatureSet resultFeatures = new FeatureSet(); // the resulting featureset resultFeatures.CopyTableSchema(targetFeatures); // set up the data table in the new feature set for (short i = 0; i <= targetFeatures.ShapeIndices.Count - 1; i++) { var tf = targetFeatures.GetFeature(i); // get the full undifferenced feature for (short j = 0; j <= sourceFeatures.ShapeIndices.Count - 1; j++) { var sf = sourceFeatures.GetFeature(j); if (sf.Geometry.Envelope.Intersects(tf.Geometry.Envelope)) { tf = tf.Difference(sf.Geometry); // clip off any pieces of SF that overlap FR } if (tf == null) { // sometimes difference leaves nothing left of a feature break; } } if (tf != null) { resultFeatures.AddFeature(tf.Geometry).CopyAttributes(targetFeatures.GetFeature(i)); // add the fully clipped feature to the results } if (cancelProgressHandler != null) { if (cancelProgressHandler.Cancel) { return(null); } int progress = Convert.ToInt32(i * 100 / targetFeatures.ShapeIndices.Count); cancelProgressHandler.Progress(string.Empty, progress, string.Empty); } } return(resultFeatures); }
/// <summary> /// Removes the feature with the specified index. /// </summary> /// <param name="index">Removes the feature from the specified index location.</param> public void RemoveAt(int index) { // Get shape range so we can update header smartly int startIndex = index; IFeatureSet ifs = Select(null, null, ref startIndex, 1); if (ifs.NumRows() > 0) { var shx = new ShapefileIndexFile(); shx.Open(Filename); shx.Shapes.RemoveAt(index); shx.Save(); AttributeTable dbf = GetAttributeTable(Filename); dbf.RemoveRowAt(index); if (_trackDeletedRows) { _deletedRows = dbf.DeletedRows; } // Update extent in header if feature being deleted is NOT completely contained var hdr = new ShapefileHeader(Filename); Envelope featureEnv = ifs.GetFeature(0).Geometry.EnvelopeInternal; if (featureEnv.MinX <= hdr.Xmin || featureEnv.MaxX >= hdr.Xmax || featureEnv.MaxY >= hdr.Ymax || featureEnv.MinY <= hdr.Ymin) { UpdateExtents(); } // Update the Quadtree Quadtree?.Remove(featureEnv, index); } }
/// <summary> /// Erase features from one feature set where they are intersected by another feature set. /// </summary> /// <param name="TargetFeatures">Features which will be erased in part or whole.</param> /// <param name="SourceFeatures">Features which represent areas to erase.</param> /// <param name="cancelProgressHandler">Optional parameter to report progress and cancel entire process if needed.</param> /// <returns>A point feature set with the randomly created features.</returns> public static FeatureSet EraseFeatures(IFeatureSet TargetFeatures, IFeatureSet SourceFeatures, ICancelProgressHandler cancelProgressHandler = null) { if (TargetFeatures == null || SourceFeatures == null) { return(null); } //Erase features from one feature set where they are intersected by another feature set //Note: we use the ShapeIndices here rather than for each feature in featureset.features as a memory management technique. //The current version does not preserve any attribute info. //Dan Ames 2/27/2013 FeatureSet ResultFeatures = new FeatureSet(); //the resulting featureset IFeature TF, SF; //a single output feature ResultFeatures.CopyTableSchema(TargetFeatures); //set up the data table in the new feature set for (Int16 i = 0; i <= TargetFeatures.ShapeIndices.Count - 1; i++) { TF = TargetFeatures.GetFeature(i); //get the full undifferenced feature for (Int16 j = 0; j <= SourceFeatures.ShapeIndices.Count - 1; j++) { SF = SourceFeatures.GetFeature(j); if (SF.Envelope.Intersects(TF.Envelope)) { TF = TF.Difference(SF); //clip off any pieces of SF that overlap FR } if (TF == null) { //sometimes difference leaves nothing left of a feature break; } } if (TF != null) { ResultFeatures.AddFeature(TF).CopyAttributes(TargetFeatures.GetFeature(i)); //add the fully clipped feature to the results } if (cancelProgressHandler != null) { if (cancelProgressHandler.Cancel) { return(null); } int progress = Convert.ToInt32(i * 100 / TargetFeatures.ShapeIndices.Count); cancelProgressHandler.Progress(String.Empty, progress, String.Empty); } } return(ResultFeatures); }
public void EditGeometry(Dictionary <int, IGeometry> geoDic) { if (geoDic == null || geoDic.Count == 0) { return; } var hdr = new ShapefileHeader(Filename); foreach (var item in geoDic) { int fid = item.Key; IGeometry geometry = item.Value; if (geometry == null) { continue; } switch (hdr.ShapeType) { case ShapeType.Point: case ShapeType.PointM: case ShapeType.PointZ: if (geometry.OgcGeometryType != OgcGeometryType.Point) { continue; } break; case ShapeType.PolyLine: case ShapeType.PolyLineM: case ShapeType.PolyLineZ: if (geometry.OgcGeometryType != OgcGeometryType.LineString) { continue; } break; case ShapeType.Polygon: case ShapeType.PolygonM: case ShapeType.PolygonZ: if (geometry.OgcGeometryType != OgcGeometryType.Polygon) { continue; } break; } EditGeometry(hdr, fid, geometry); if (Quadtree != null) { int startIndex = fid; IFeatureSet ifs = Select(null, null, ref startIndex, 1); Envelope srcEnvelope = ifs.GetFeature(0).Geometry.EnvelopeInternal; Quadtree.Remove(srcEnvelope, fid); Quadtree.Insert(geometry.EnvelopeInternal, fid); } } UpdateExtents(); }
/// <summary> /// Erase features from one feature set where they are intersected by another feature set. /// </summary> /// <param name="TargetFeatures">Features which will be erased in part or whole.</param> /// <param name="SourceFeatures">Features which represent areas to erase.</param> /// <param name="cancelProgressHandler">Optional parameter to report progress and cancel entire process if needed.</param> /// <returns>A point feature set with the randomly created features.</returns> public static FeatureSet EraseFeatures(IFeatureSet TargetFeatures, IFeatureSet SourceFeatures, ICancelProgressHandler cancelProgressHandler = null) { if (TargetFeatures == null || SourceFeatures == null) { return null; } //Erase features from one feature set where they are intersected by another feature set //Note: we use the ShapeIndices here rather than for each feature in featureset.features as a memory management technique. //The current version does not preserve any attribute info. //Dan Ames 2/27/2013 FeatureSet ResultFeatures = new FeatureSet(); //the resulting featureset IFeature TF, SF; //a single output feature ResultFeatures.CopyTableSchema(TargetFeatures); //set up the data table in the new feature set for (Int16 i = 0; i <= TargetFeatures.ShapeIndices.Count - 1; i++) { TF = TargetFeatures.GetFeature(i); //get the full undifferenced feature for (Int16 j = 0; j <= SourceFeatures.ShapeIndices.Count - 1; j++) { SF = SourceFeatures.GetFeature(j); if (SF.Envelope.Intersects(TF.Envelope)) { TF = TF.Difference(SF); //clip off any pieces of SF that overlap FR } if (TF == null) { //sometimes difference leaves nothing left of a feature break; } } if (TF != null) { ResultFeatures.AddFeature(TF).CopyAttributes(TargetFeatures.GetFeature(i)); //add the fully clipped feature to the results } if (cancelProgressHandler != null) { if (cancelProgressHandler.Cancel) { return null; } int progress = Convert.ToInt32(i * 100 / TargetFeatures.ShapeIndices.Count); cancelProgressHandler.Progress(String.Empty, progress, String.Empty); } } return ResultFeatures; }
private FeatureSet IntersectFeatures(IFeatureSet targetFeatures, IFeatureSet sourceFeatures) { if (targetFeatures == null || sourceFeatures == null) { return(null); } FeatureSet resultFeatures = new FeatureSet(); // the resulting featureset resultFeatures.CopyTableSchema(targetFeatures); // set up the data table in the new feature set ProgressBox p = new ProgressBox(0, 100, "Self intersection check progress"); p.ShowPregress(); p.SetProgressValue(0); p.SetProgressDescription("Overlay Intersect..."); double pi = Math.Round((double)(1.0 * 100 / targetFeatures.Features.Count), 2); for (int i = 0; i < targetFeatures.Features.Count; i++) { p.SetProgressValue(i * pi + pi); p.SetProgressDescription2(string.Format("{0} feature(s) is(are) checked, the remaining {1} feature(s) is(are) being queried", i + 1, targetFeatures.Features.Count - i - 1)); var tf = targetFeatures.GetFeature(i); // get the full undifferenced feature for (int j = 0; j < sourceFeatures.Features.Count; j++) { var sf = sourceFeatures.GetFeature(j); if (sf.Geometry.Intersects(tf.Geometry)) { tf = tf.Intersection(sf.Geometry); // clip off any pieces of SF that overlap FR } if (tf == null) { break; } } if (tf != null) { resultFeatures.AddFeature(tf.Geometry).CopyAttributes(targetFeatures.GetFeature(i)); } } p.CloseProgress(); return(resultFeatures); }
private void cmdPath_Click(object sender, EventArgs e) { listBox1.Items.Clear(); if (fm.Ready) { String from = GetOD(cmbO.Text).ToString(); String to = GetOD(cmbD.Text).ToString(); dijkstra = new Algorithm(fm.Graph); LinkedList <Edge> result = dijkstra.findPath(from, to); if (result.Count > 0) { int activeLyr = getLayerID(mMap, LinkLyr); IFeatureSet FeLyr = mMap.Layers[activeLyr].DataSet as IFeatureSet; nLink = 0; int nShp = FeLyr.DataTable.Rows.Count; System.Drawing.Color col = Color.Red; mMap.MapFrame.DrawingLayers.Clear(); // Feature f = new Feature(axisLines); FeatureSet fs = new FeatureSet(FeatureType.Line); foreach (Edge edge in result) { string sID = edge.Id.ToString(); int spIndex = Convert.ToInt32(edge.Id); int spatialIndex = Math.Abs(spIndex); listBox1.Items.Add(spIndex); IFeature f = FeLyr.GetFeature(spatialIndex); fs.Features.Add(f); } MapLineLayer rangeRingAxis; rangeRingAxis = new MapLineLayer(fs);// MapPolygonLayer(fs); rangeRingAxis.Symbolizer = new LineSymbolizer(col, 4); mMap.MapFrame.DrawingLayers.Add(rangeRingAxis); // Request a redraw mMap.MapFrame.Invalidate(); } } //--------------------------------------------------------------- List <int> Links = new List <int>(); for (int i = 0; i < Links.Count; i++) { //IFeature f = FeLyr.GetFeature(Links[i]); //fs.Features.Add(f); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { IFeatureSet fs = null; if (!TypeConverterEx.IsNull(PointFeatureFileName) && File.Exists(PointFeatureFileName)) { fs = FeatureSet.Open(PointFeatureFileName); } if (fs != null) { var npt = fs.NumRows(); Coordinate[] coors = new Coordinate[npt]; int progress = 0; for (int i = 0; i < npt; i++) { var geo_pt = fs.GetFeature(i).Geometry; coors[i] = geo_pt.Coordinate; } var time = _TimeVariable.GetData() as float[]; var xx = _XVariable.GetData() as float[]; var yy = _YVariable.GetData() as float[]; var nc_array = _SelectedVariable.GetData() as float[, , ]; int nstep = time.Count(); var mat_out = new DataCube <float>(1, time.Length, npt); mat_out.Name = OutputMatrix; mat_out.Variables = new string[] { _SelectedVariableName }; mat_out.DateTimes = new DateTime[nstep]; var pt_index = GetIndex(xx, yy, coors); for (int t = 0; t < nstep; t++) { for (int i = 0; i < npt; i++) { mat_out[0, t, i] = nc_array[t, pt_index[i][1], pt_index[i][0]]; } progress = t * 100 / nstep; cancelProgressHandler.Progress("Package_Tool", progress, "Processing time step:" + t); mat_out.DateTimes[t] = DateTime.FromOADate(time[t]); } Workspace.Add(mat_out); return(true); } else { cancelProgressHandler.Progress("Package_Tool", 50, "Failed to run. The input parameters are incorrect."); return(false); } }
GetFeaturesBoundingBoxes(IFeatureSet featuresSet) { var res = new System.Collections.Generic.List <System.Tuple <uint, SharpSbn.DataStructures.Envelope> >( featuresSet.NumRows()); for (var i = 0; i < featuresSet.NumRows(); i++) { var feature = featuresSet.GetFeature(i); var min = feature.Envelope.Minimum; var max = feature.Envelope.Maximum; res.Add(System.Tuple.Create((uint)feature.Fid, new SharpSbn.DataStructures.Envelope( min.X, max.X, min.Y, max.Y))); } return(res); }
public void EditGeometry(int fid, IGeometry geometry) { var hdr = new ShapefileHeader(Filename); if (geometry == null) { return; } switch (hdr.ShapeType) { case ShapeType.Point: case ShapeType.PointM: case ShapeType.PointZ: if (geometry.OgcGeometryType != OgcGeometryType.Point) { return; } break; case ShapeType.PolyLine: case ShapeType.PolyLineM: case ShapeType.PolyLineZ: if (geometry.OgcGeometryType != OgcGeometryType.LineString) { return; } break; case ShapeType.Polygon: case ShapeType.PolygonM: case ShapeType.PolygonZ: if (geometry.OgcGeometryType != OgcGeometryType.Polygon) { return; } break; } EditGeometry(hdr, fid, geometry); UpdateExtents(); if (Quadtree != null) { int startIndex = fid; IFeatureSet ifs = Select(null, null, ref startIndex, 1); Envelope srcEnvelope = ifs.GetFeature(0).Geometry.EnvelopeInternal; Quadtree.Remove(srcEnvelope, fid); Quadtree.Insert(geometry.EnvelopeInternal, fid); } }
private IFeatureSet CorrectFeatures(IFeatureSet featureSet) { IFeatureSet corFeatureSet = featureSet; List <int> corList = new List <int>(); for (int i = 0; i < featureSet.ShapeIndices.Count; i++) { try { IFeature feature = featureSet.GetFeature(i); IFeatureSet reFeatureSet = new FeatureSet(); reFeatureSet.Features.Add(feature); //有待检验能否检测出其他异常 reFeatureSet.SelectByAttribute(""); corList.Add(i); } catch { //featureSet.Features.RemoveAt(i); } } corFeatureSet = corFeatureSet.CopySubset(corList); return(corFeatureSet); }
static void GetDataOfEachCentoid() { Stopwatch sw = new Stopwatch(); sw.Start(); Console.WriteLine("开始读取数据"); IFeatureSet centroid = FeatureSet.Open(@"D:\OneDrive\2017研究生毕业设计\数据\项目用数据\newCentroidNoDup.shp"); IFeatureSet LargePoints = FeatureSet.Open(@"D:\OneDrive\2017研究生毕业设计\数据\项目用数据\DesGauss.shp"); sw.Stop(); Console.WriteLine("数据读取完成,耗费时间为{0}s", sw.Elapsed.TotalSeconds); sw.Restart(); Console.WriteLine("开始处理数据"); KdTree myTree = new KdTree(2); foreach (var item in centroid.Features) { var c = item.Coordinates[0]; myTree.Insert(new double[] { c.X, c.Y }, item); } Console.WriteLine("KD树构建完成"); List <int>[] result = new List <int> [centroid.NumRows()]; for (int i = 0; i < result.Length; i++) { result[i] = new List <int>(); } int core = 8; double eachTaskPointsCount = LargePoints.NumRows() / 8.0; Parallel.For(0, core, new Action <int>((index) => { //并行任务开始 int start = (int)Math.Ceiling(index * eachTaskPointsCount); int end = index != 7 ? (int)Math.Floor((index + 1) * eachTaskPointsCount) : LargePoints.NumRows() - 1; Console.WriteLine("开始为:{0},终点为:{1}", start, end); for (int i = start; i <= end; i++) { var currentFeature = LargePoints.GetFeature(i); Coordinate c = currentFeature.Coordinates[0]; IFeature f = myTree.Nearest(new double[] { c.X, c.Y }) as IFeature; if (f.Distance(currentFeature) < 300) { result[f.Fid].Add(currentFeature.Fid); } } })); sw.Stop(); Console.WriteLine("计算结束!还需保存!耗时:{0}", sw.Elapsed.TotalSeconds); StreamWriter streamw = new StreamWriter("summaryDes.txt"); foreach (var item in result) { for (int i = 0; i < item.Count; i++) { streamw.Write(item[i]); if (i != item.Count - 1) { streamw.Write(','); } } streamw.Write(Environment.NewLine); } streamw.Close(); Console.WriteLine("保存完毕!"); Console.ReadKey(); }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { IFeatureSet fs = FeatureSet.Open(FeatureFile); int var_index = 0; int con_var_index = 0; var mat = Get3DMat(Matrix, ref var_index); DataCube <float> con_mat = null; if (Filter != FilterMode.None) { con_mat = Get3DMat(ConMat, ref con_var_index); } if (fs != null && mat != null) { IRaster raster = Raster.Open(TemplateFile); raster.SaveAs(TemplateFile + ".tif"); int fea_count = fs.NumRows(); Coordinate[] coors = new Coordinate[fea_count]; for (int i = 0; i < fea_count; i++) { coors[i] = fs.GetFeature(i).Geometry.Coordinates[0]; } var nsteps = mat.Size[1]; int progress = 0; string[] fns = new string[nsteps]; if (mat.DateTimes != null) { for (int t = 0; t < nsteps; t++) { fns[t] = string.Format("{0}_{1}.tif", VariableName, mat.DateTimes[t].ToString(DateFormat)); } } else { for (int t = 0; t < nsteps; t++) { fns[t] = string.Format("{0}_{1}.tif", VariableName, t.ToString("0000")); } } if (Filter != FilterMode.None) { for (int t = 0; t < nsteps; t++) { string outras = Path.Combine(Direcotry, fns[t]); int i = 0; foreach (var cor in coors) { var cell = raster.ProjToCell(cor); var temp = mat[var_index, t, i] * Scale; if (Filter == FilterMode.Maximum) { if (temp > con_mat[0, 0, i]) { temp = con_mat[0, 0, i]; } } else if (Filter == FilterMode.Minimum) { if (temp < con_mat[0, 0, i]) { temp = con_mat[0, 0, i]; } } raster.Value[cell.Row, cell.Column] = temp; i++; } raster.SaveAs(outras); progress = t * 100 / nsteps; cancelProgressHandler.Progress("Package_Tool", progress, "Saving raster to:" + outras); } } else { for (int t = 0; t < nsteps; t++) { string outras = Path.Combine(Direcotry, fns[t]); int i = 0; foreach (var cor in coors) { var cell = raster.ProjToCell(cor.X - 500, cor.Y + 500); var temp = mat[var_index, t, i] * Scale; raster.Value[cell.Row, cell.Column] = temp; i++; } raster.SaveAs(outras); progress = t * 100 / nsteps; cancelProgressHandler.Progress("Package_Tool", progress, "Saving raster to:" + outras); } } return(true); } else { cancelProgressHandler.Progress("Package_Tool", 100, "Failed to run. The input parameters are incorrect."); return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { //string basedir = @"E:\Heihe\HRB\DataSets\Driving Forces\PXD\"; //AverageTemperatureFileName = basedir + "daily_tavk_11243.dcx"; //MaxTemperatureFileName = basedir + "daily_tmaxk_11243.dcx"; //MinTemperatureFileName = basedir + "daily_tmink_11243.dcx"; //RelativeHumidityFileName = @"E:\Heihe\HRB\DataSets\Driving Forces\TY\rh.dcx"; //AirPressureFileName = basedir + "daily_ap_11243.dcx"; //WindSpeedFileName = basedir + "daily_windspeed_11243.dcx"; IFeatureSet fs = FeatureSet.Open(PointFeatureFileName); string[] files = new string[] { AverageTemperatureFileName, MaxTemperatureFileName, MinTemperatureFileName, RelativeHumidityFileName, AirPressureFileName, WindSpeedFileName }; var npt = fs.NumRows(); Coordinate[] coors = new Coordinate[npt]; for (int i = 0; i < npt; i++) { var geo_pt = fs.GetFeature(i).Geometry; coors[i] = geo_pt.Coordinate; } int nfile = files.Length; DataCubeStreamReader[] ass = new DataCubeStreamReader[nfile]; DataCube <float>[] mats = new DataCube <float> [nfile]; for (int i = 0; i < nfile; i++) { ass[i] = new DataCubeStreamReader(files[i]); ass[i].Open(); } int progress = 0; int nstep = ass[0].NumTimeStep; int ncell = ass[0].FeatureCount; PenmanMonteithET pet = new PenmanMonteithET(); DataCubeStreamWriter sw = new DataCubeStreamWriter(OutputFileName); sw.WriteHeader(new string[] { "pet" }, ncell); DataCube <float> mat_out = new DataCube <float>(1, 1, ncell); mat_out.DateTimes = new DateTime[nstep]; int count = 1; for (int t = 0; t < nstep; t++) { for (int i = 0; i < nfile; i++) { mats[i] = ass[i].LoadStep(); } for (int n = 0; n < ncell; n++) { var tav = mats[0][0, 0, n]; var tmax = mats[1][0, 0, n]; var tmin = mats[2][0, 0, n]; if (InputTemperatureUnit == TemperatureUnit.Fahrenheit) { tmax = (float)UnitConversion.Fahrenheit2Kelvin(tmax); tmin = (float)UnitConversion.Fahrenheit2Kelvin(tmin); tav = (float)UnitConversion.Fahrenheit2Kelvin(tav); } else if (InputTemperatureUnit == TemperatureUnit.Celsius) { tmax = (float)UnitConversion.Celsius2Kelvin(tmax); tmin = (float)UnitConversion.Celsius2Kelvin(tmin); tav = (float)UnitConversion.Celsius2Kelvin(tav); } double ap = mats[4][0, 0, n] / 1000; var et0 = pet.ET0(coors[n].Y, coors[n].X, tav, tmax, tmin, mats[3][0, 0, n], ap, mats[5][0, 0, n], Start.AddDays(t), CloudCover); if (OutputLengthUnit == LengthUnit.inch) { mat_out[0, 0, n] = (float)System.Math.Round(et0 * UnitConversion.mm2Inch, 3); } else { mat_out[0, 0, n] = (float)System.Math.Round(et0, 3); } } mat_out.DateTimes[t] = Start.AddDays(1); sw.WriteStep(1, ncell, mat_out); progress = t * 100 / nstep; if (progress > count) { cancelProgressHandler.Progress("Package_Tool", progress, "Processing step:" + (t + 1)); count++; } } sw.Close(); for (int i = 0; i < nfile; i++) { ass[i].Close(); } return(true); }
/// <summary> /// Returns a feature that provides information about preview. /// </summary> /// <param name="features">The set of features.</param> /// <returns>A feature that provides information about preview.</returns> public static IPreviewFeature Preview(this IFeatureSet features) { return(features.GetFeature <IPreviewFeature>()); }
private void PrePro(Dictionary<int, ReachFeatureCollection> fealist, out string msg) { double rs = 0, slope = 0, yint = 0; var dt = _out_sfr_layer.DataTable; var prj = MyAppManager.Instance.CompositionContainer.GetExportedValue<IProjectService>(); msg = ""; for (int i = 0; i < _out_sfr_layer.Features.Count; i++) { try { var dr = dt.Rows[i]; var geo = _out_sfr_layer.GetFeature(i).Geometry; if (geo.Length <= _dem_layer.CellHeight) { continue; } var npt = geo.Coordinates.Count(); int segid = int.Parse(dr[SegmentField].ToString()) + 1; double[] dis = new double[npt]; double[] ac_dis = new double[npt]; double[] elvs = new double[npt]; double elev_av = 0; var pt0 = geo.Coordinates[0]; var cell = _dem_layer.ProjToCell(pt0.X, pt0.Y); double ad = 0; dis[0] = 0; elvs[0] = _dem_layer.Value[cell.Row, cell.Column]; for (int j = 0; j < npt; j++) { cell = _ad_layer.ProjToCell(geo.Coordinates[j].X, geo.Coordinates[j].Y); ad += _ad_layer.Value[cell.Row, cell.Column]; } ad = ad / npt; for (int j = 1; j < npt; j++) { cell = _dem_layer.ProjToCell(geo.Coordinates[j].X, geo.Coordinates[j].Y); elvs[j] = _dem_layer.Value[cell.Row, cell.Column]; dis[j] = SpatialDistance.DistanceBetween(geo.Coordinates[j - 1], geo.Coordinates[j]); } for (int j = 0; j < npt; j++) { ac_dis[j] = dis.Take(j + 1).Sum(); } MyStatisticsMath.LinearRegression(ac_dis, elvs, 0, elvs.Length, out rs, out yint, out slope); if (slope < 0) { slope = -slope; } else if (slope == 0) { slope = _minum_slope; } for (int j = 0; j < npt; j++) { elvs[j] = yint + slope * ac_dis[j]; } elev_av = elvs.Average(); if (slope < _minum_slope) slope = _minum_slope; if (slope > _maximum_slope) slope = _maximum_slope; var rch = new ReachFeature() { Row = dr, Elevation = elev_av, Slope = slope }; if (fealist[segid].Reaches.ContainsKey(ad)) { ad += i * 0.001; } fealist[segid].Reaches.Add(ad, rch); fealist[segid].OutSegmentID = int.Parse(dr["DSLINKNO"].ToString()); dr["Length"] = geo.Length; } catch (Exception ex) { msg += ex.Message + "\n"; } } }
private void button2_Click(object sender, EventArgs e) { int activeLyr = getLayerID(mMap, cmbNode.Text); int linkLyr = getLayerID(mMap, cmbLinkLyr.Text); grdDemand.Rows.Clear(); //try { //IMapFeatureLayer FeLyr = mMap.Layers[activeLyr] as IMapFeatureLayer; IFeatureSet FeLyr = mMap.Layers[activeLyr].DataSet as IFeatureSet; IFeatureSet FeLinkLyr = mMap.Layers[linkLyr].DataSet as IFeatureSet; int nShp = FeLyr.DataTable.Rows.Count; for (int i = 0; i < nShp; i++) { IFeature fs = FeLyr.GetFeature(i); /* * Coordinate[] c = new Coordinate[fs.NumPoints]; * for (int iPt = 0; iPt < fs.NumPoints; iPt++) * { * double x1 = fs.Coordinates[iPt].X; * double y1 = fs.Coordinates[iPt].Y; * c[iPt] = new Coordinate(x1, y1); * } */ double x1 = fs.Coordinates[0].X; double y1 = fs.Coordinates[0].Y; object remark = fs.DataRow["AMP_ID"]; grdDemand.Rows.Add(); grdDemand.Rows[i].Cells[0].Value = i; grdDemand.Rows[i].Cells[1].Value = x1; grdDemand.Rows[i].Cells[2].Value = y1; grdDemand.Rows[i].Cells[3].Value = remark.ToString(); double x = 0; double y = 0; double min = 100000000000; double r = 1; int linkID = -1; int nLink = FeLinkLyr.DataTable.Rows.Count; for (int j = 0; j < nLink; j++) { IFeature fsLink = FeLinkLyr.GetFeature(j); int lastVertex = fsLink.NumPoints - 1; double x2 = fsLink.Coordinates[0].X; double y2 = fsLink.Coordinates[0].Y; double x3 = fsLink.Coordinates[lastVertex].X; double y3 = fsLink.Coordinates[lastVertex].Y; r = Math.Sqrt(Math.Pow((x1 - x2), 2) + Math.Pow((y1 - y2), 2)); if (r < min) { min = r; x = x2; y = y2; linkID = j; } r = Math.Sqrt(Math.Pow((x1 - x3), 2) + Math.Pow((y1 - y3), 2)); if (r < min) { min = r; x = x3; y = y3; linkID = j; } } grdDemand.Rows[i].Cells[4].Value = linkID; grdDemand.Rows[i].Cells[5].Value = x; grdDemand.Rows[i].Cells[6].Value = y; //-move demand point Coordinate c = new Coordinate(x, y); fs.Coordinates[0].X = x; fs.Coordinates[0].Y = y; } //FeLyr.Save(); } }
private void button1_Click(object sender, EventArgs e) { //read existing node //ReadExistingNodeID(); // SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; saveFileDialog1.FilterIndex = 2; saveFileDialog1.RestoreDirectory = true; double dist = Convert.ToDouble(txtDistance.Text); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { using (StreamWriter writer = new StreamWriter(saveFileDialog1.FileName)) { string st = ""; int activeLyr = getLayerID(mMap, cmbLinkLyr.Text); grdLink.Rows.Clear(); //try { //IMapFeatureLayer FeLyr = mMap.Layers[activeLyr] as IMapFeatureLayer; IFeatureSet FeLyr = mMap.Layers[activeLyr].DataSet as IFeatureSet; int nShp = FeLyr.DataTable.Rows.Count; for (int i = 0; i < nShp; i++) { IFeature fs = FeLyr.GetFeature(i); /* * Coordinate[] c = new Coordinate[fs.NumPoints]; * for (int iPt = 0; iPt < fs.NumPoints; iPt++) * { * double x1 = fs.Coordinates[iPt].X; * double y1 = fs.Coordinates[iPt].Y; * c[iPt] = new Coordinate(x1, y1); * } */ Coordinate[] c = new Coordinate[2]; double x1 = fs.Coordinates[0].X; double y1 = fs.Coordinates[0].Y; c[0] = new Coordinate(x1, y1); double x2 = fs.Coordinates[fs.NumPoints - 1].X; double y2 = fs.Coordinates[fs.NumPoints - 1].Y; c[1] = new Coordinate(x2, y2); //object remark = fs.DataRow["remark"]; grdLink.Rows.Add(); grdLink.Rows[i].Cells[0].Value = i; //Node From bool demandNode = false; double minR = 1000000000000; int iiSel = -1; for (int ii = 0; ii < grdDemand.RowCount; ii++) { double x = Convert.ToDouble(grdDemand.Rows[ii].Cells[1].Value); double y = Convert.ToDouble(grdDemand.Rows[ii].Cells[2].Value); double r = Math.Sqrt(Math.Pow(x1 - x, 2) + Math.Pow(y1 - y, 2)); if (r < minR) { iiSel = ii; minR = r; } } if (demandNode = true & minR <= dist) { grdLink.Rows[i].Cells[1].Value = grdDemand.Rows[iiSel].Cells[0].Value; grdDemand.Rows[iiSel].Cells[1].Value = x1; grdDemand.Rows[iiSel].Cells[2].Value = y1; writer.WriteLine(grdDemand.Rows[iiSel].Cells[0].Value.ToString() + ", " + x1.ToString() + ", " + y1.ToString() + ", " + grdDemand.Rows[iiSel].Cells[3].Value.ToString()); } else { if (GetNode(x1, y1) != -1) { grdLink.Rows[i].Cells[1].Value = GetNode(x1, y1); } else { grdLink.Rows[i].Cells[1].Value = newID(x1, y1); } } //Node To demandNode = false; minR = 1000000000000; iiSel = -1; for (int ii = 0; ii < grdDemand.RowCount; ii++) { double x = Convert.ToDouble(grdDemand.Rows[ii].Cells[1].Value); double y = Convert.ToDouble(grdDemand.Rows[ii].Cells[2].Value); double r = Math.Sqrt(Math.Pow(x2 - x, 2) + Math.Pow(y2 - y, 2)); if (r < minR) { iiSel = ii; minR = r; demandNode = true; } } if (demandNode = true & minR <= dist) { grdLink.Rows[i].Cells[2].Value = grdDemand.Rows[iiSel].Cells[0].Value; grdDemand.Rows[iiSel].Cells[1].Value = x2; grdDemand.Rows[iiSel].Cells[2].Value = y2; writer.WriteLine(grdDemand.Rows[iiSel].Cells[0].Value.ToString() + ", " + x2.ToString() + ", " + y2.ToString() + ", " + grdDemand.Rows[iiSel].Cells[3].Value.ToString()); } else { if (GetNode(x2, y2) != -1) { grdLink.Rows[i].Cells[2].Value = GetNode(x2, y2); } else { grdLink.Rows[i].Cells[2].Value = newID(x2, y2); } } grdLink.Rows[i].Cells[3].Value = getFeaLength(fs); } } //catch { MessageBox.Show("Error! Please select a line shape layer"); } } } }
public static void CorretionCentroid() { //中心点数据 Stopwatch sw = new Stopwatch(); sw.Start(); List <Coordinate> centroidPoints = new List <Coordinate>(80); StreamReader sr = new StreamReader(@"D:\MagicSong\OneDrive\2017研究生毕业设计\数据\项目用数据\中心点80.txt"); sr.ReadLine();//读取标题行 while (!sr.EndOfStream) { string[] line = sr.ReadLine().Split(','); centroidPoints.Add(new Coordinate(double.Parse(line[1]), double.Parse(line[2]))); } sr.Close(); //Bus数据,并且构造KD树 KdTree myKdtree = new KdTree(2); IFeatureSet busFS = FeatureSet.Open(@"D:\MagicSong\OneDrive\2017研究生毕业设计\数据\项目用数据\BusStopGauss.shp"); List <Coordinate> busStopPoints = new List <Coordinate>(busFS.NumRows()); foreach (var item in busFS.Features) { var c = item.Coordinates[0]; busStopPoints.Add(c); myKdtree.Insert(new double[] { c.X, c.Y }, item); } Console.WriteLine("数据读取完毕,开始构造遗传算法"); IFeatureSet newCentroid = new FeatureSet(FeatureType.Point); newCentroid.Name = "优化过的中心点"; newCentroid.Projection = ProjectionInfo.FromEpsgCode(GAUSS_EPSG); newCentroid.DataTable.Columns.Add("name", typeof(string)); //遗传算法,构造适应性函数 MyProblemChromosome.CandiateNumber = 5; List <int[]> candinatesForEachControid = new List <int[]>(centroidPoints.Count); foreach (var item in centroidPoints) { object[] nearest = myKdtree.Nearest(new double[] { item.X, item.Y }, MyProblemChromosome.CandiateNumber); candinatesForEachControid.Add(nearest.Select((o) => { var f = o as IFeature; return(f.Fid); }).ToArray()); } MyProblemFitness fitness = new MyProblemFitness(centroidPoints, busStopPoints, candinatesForEachControid); MyProblemChromosome mpc = new MyProblemChromosome(centroidPoints.Count); //这边可以并行 MyProblemChromosome globalBest = null; Console.WriteLine("遗传算法构造已经完成!"); sw.Stop(); Console.WriteLine("一共用时:{0}s", sw.Elapsed.TotalSeconds); int GACount = 8; Parallel.For(0, GACount, new Action <int>((index) => { var selection = new EliteSelection(); var crossover = new TwoPointCrossover(); var mutation = new ReverseSequenceMutation(); var population = new Population(1000, 1200, mpc); var ga = new GeneticAlgorithm(population, fitness, selection, crossover, mutation); ga.Termination = new GenerationNumberTermination(1000); Stopwatch sw1 = new Stopwatch(); sw1.Start(); Console.WriteLine("遗传算法任务{0}正在运行.......", index); ga.Start(); var best = ga.BestChromosome as MyProblemChromosome; if (globalBest == null || globalBest.Fitness < best.Fitness) { globalBest = best; } sw1.Stop(); Console.WriteLine("第{0}次遗传算法已经完成,耗费时间为:{1}s,最终的fitness为:{2},有效个数为:{3}", index, sw1.Elapsed.TotalSeconds, best.Fitness, best.Significance); })); Console.WriteLine("Final Choose!"); Console.WriteLine("最终的fitness为:{0},有效个数为:{1}", globalBest.Fitness, globalBest.Significance); for (int i = 0; i < globalBest.Length; i++) { int index = candinatesForEachControid[i][(int)globalBest.GetGene(i).Value]; Coordinate c = busStopPoints[index]; var f = newCentroid.AddFeature(new Point(c)); f.DataRow.BeginEdit(); f.DataRow["name"] = busFS.GetFeature(index).DataRow["name"]; f.DataRow.EndEdit(); } newCentroid.SaveAs("newCentroid.shp", true); Console.ReadKey(); }
private void cmdCreateNetworkData_Click(object sender, EventArgs e) { // toolStripProgressBar1.Visible = true; int activeLyr = getLayerID(mMap, LinkLyr); grdLink.Rows.Clear(); grdNode.Rows.Clear(); int nLinkError = 0; List <int> LinkErr = new List <int>(); txtLinkError.Clear(); //try { //IMapFeatureLayer FeLyr = mMap.Layers[activeLyr] as IMapFeatureLayer; IFeatureSet FeLyr = mMap.Layers[activeLyr].DataSet as IFeatureSet; nLink = 0; int nShp = FeLyr.DataTable.Rows.Count; toolStripProgressBar1.Maximum = nShp; for (int i = 0; i < nShp; i++) { toolStripProgressBar1.Value = i; IFeature fs = FeLyr.GetFeature(i); /* * Coordinate[] c = new Coordinate[fs.NumPoints]; * for (int iPt = 0; iPt < fs.NumPoints; iPt++) * { * double x1 = fs.Coordinates[iPt].X; * double y1 = fs.Coordinates[iPt].Y; * c[iPt] = new Coordinate(x1, y1); * } */ Coordinate[] c = new Coordinate[2]; double x1 = Math.Round(fs.Coordinates[0].X, 0); double y1 = Math.Round(fs.Coordinates[0].Y, 0); c[0] = new Coordinate(x1, y1); double x2 = Math.Round(fs.Coordinates[fs.NumPoints - 1].X, 0); double y2 = Math.Round(fs.Coordinates[fs.NumPoints - 1].Y, 0); c[1] = new Coordinate(x2, y2); //---------------------------------------------------------- //FeLyr.Features[i].Coordinates[0].X = x1; //FeLyr.Features[i].Coordinates[0].Y = y1; //FeLyr.Features[i].Coordinates[fs.NumPoints - 1].X = x2; //FeLyr.Features[i].Coordinates[fs.NumPoints - 1].Y = y2; //---------------------------------------------------------- //object remark = fs.DataRow["remark"]; int F = -1; int T = -1; //Node From if (GetNode(x1, y1) != -1) { F = GetNode(x1, y1); } else { F = newID(x1, y1); } //Node To if (GetNode(x2, y2) != -1) { T = GetNode(x2, y2); } else { T = newID(x2, y2); } if (F != T) { grdLink.Rows.Add(); grdLink.Rows[nLink].Cells[0].Value = i; grdLink.Rows[nLink].Cells[1].Value = F; grdLink.Rows[nLink].Cells[2].Value = T; grdLink.Rows[nLink].Cells[3].Value = Math.Round(getFeaLength(fs), 2); grdLink.Rows[nLink].Cells[4].Value = Math.Round(getFeaLength(fs), 2); object lane = fs.DataRow["lane"]; try { grdLink.Rows[nLink].Cells[6].Value = Convert.ToInt16(lane); } catch { grdLink.Rows[nLink].Cells[6].Value = "No data"; } nLink++; } else { nLinkError++; LinkErr.Add(i); txtLinkError.Text += i.ToString() + Environment.NewLine; } } if (nLinkError > 0) { string st = ""; for (int i = 0; i < nLinkError; i++) { st = st + " " + LinkErr[i].ToString(); } MessageBox.Show("No. of error link :" + nLinkError.ToString() + st); } //----------------------------------------------------------------------------- nNode = hashNode.Count; grdNode.Rows.Add(nNode); int ii = 0; foreach (string xy in hashNode.Keys) { var values = xy.Split('|'); grdNode.Rows[ii].Cells[0].Value = hashNode[xy]; grdNode.Rows[ii].Cells[1].Value = values[0]; grdNode.Rows[ii].Cells[2].Value = values[1]; bool DemandNodeChk = false; for (int j = 0; j < DemandNode.Count; j++) { if (DemandNode[j].ToString() == grdNode.Rows[ii].Cells[0].Value.ToString()) { grdNode.Rows[ii].Cells[3].Value = "DEMAND NODE"; grdNode.Rows[ii].Cells[4].Value = AMPNode[j].ToString(); DemandNodeChk = true; } } if (DemandNodeChk == false) { grdNode.Rows[ii].Cells[3].Value = "DUMMY NODE"; grdNode.Rows[ii].Cells[4].Value = ""; } ii++; } this.grdNode.Sort(this.grdNode.Columns[0], ListSortDirection.Ascending); /* * foreach (string value in hashNode.Values) * { * grdNode.Rows[ii].Cells[1].Value = value; * ii++; * } */ //----------------------------------------------------------------------------- } toolStripProgressBar1.Visible = false; int iDemandLyr = getLayerID(mMap, DemandLyr); IFeatureSet FeDemandLyr = mMap.Layers[iDemandLyr].DataSet as IFeatureSet; cmbO.Items.Clear(); cmbD.Items.Clear(); hashOD.Clear(); int nDemand = FeDemandLyr.DataTable.Rows.Count; for (int i = 0; i < nDemand; i++) { //IFeature fs = FeDemandLyr.GetFeature(i); double x1 = FeDemandLyr.Features[i].Coordinates[0].X; double y1 = FeDemandLyr.Features[i].Coordinates[0].Y; object AMP_ID = FeDemandLyr.Features[i].DataRow["AMP_ID"]; cmbO.Items.Add(AMP_ID); cmbD.Items.Add(AMP_ID); double x = 0; double y = 0; double min = 100000000000; double r = 1; int NodeID = -1; for (int j = 0; j < grdNode.RowCount; j++) { double x2 = Convert.ToDouble(grdNode.Rows[j].Cells[1].Value); double y2 = Convert.ToDouble(grdNode.Rows[j].Cells[2].Value); r = Math.Sqrt(Math.Pow((x1 - x2), 2) + Math.Pow((y1 - y2), 2)); if (r < min) { min = r; x = x2; y = y2; NodeID = j; } } //fs.Coordinates[0].X = x; //fs.Coordinates[0].Y = y; grdNode.Rows[NodeID].Cells[3].Value = "Demand Node"; grdNode.Rows[NodeID].Cells[4].Value = AMP_ID; hashOD.Add(AMP_ID, NodeID); } //FeDemandLyr.Save(); this.fm = new FileManager(); if (fm.readNetwork(grdLink)) { MessageBox.Show("Load network complete"); cmdPath.Enabled = true; } else { MessageBox.Show("Error load network incomplete"); cmdPath.Enabled = false; } }
/// <summary> /// This tests each feature of the input /// </summary> /// <param name="self">This featureSet</param> /// <param name="other">The featureSet to perform intersection with</param> /// <param name="joinType">The attribute join type</param> /// <param name="progHandler">A progress handler for status messages</param> /// <returns>An IFeatureSet with the intersecting features, broken down based on the join Type</returns> public static IFeatureSet Intersection(this IFeatureSet self, IFeatureSet other, FieldJoinType joinType, IProgressHandler progHandler) { IFeatureSet result = null; ProgressMeter pm = new ProgressMeter(progHandler, "Calculating Intersection", self.Features.Count); if (joinType == FieldJoinType.All) { result = CombinedFields(self, other); // Intersection is symmetric, so only consider I X J where J <= I if (!self.AttributesPopulated) { self.FillAttributes(); } if (!other.AttributesPopulated) { other.FillAttributes(); } for (int i = 0; i < self.Features.Count; i++) { IFeature selfFeature = self.Features[i]; List <IFeature> potentialOthers = other.Select(selfFeature.Geometry.EnvelopeInternal.ToExtent()); foreach (IFeature otherFeature in potentialOthers) { selfFeature.Intersection(otherFeature, result, joinType); } pm.CurrentValue = i; } pm.Reset(); } else if (joinType == FieldJoinType.LocalOnly) { if (!self.AttributesPopulated) { self.FillAttributes(); } result = new FeatureSet(); result.CopyTableSchema(self); result.FeatureType = self.FeatureType; if (other.Features != null && other.Features.Count > 0) { pm = new ProgressMeter(progHandler, "Calculating Union", other.Features.Count); IFeature union = other.Features[0]; for (int i = 1; i < other.Features.Count; i++) { union = union.Union(other.Features[i].Geometry); pm.CurrentValue = i; } pm.Reset(); pm = new ProgressMeter(progHandler, "Calculating Intersections", self.NumRows()); Extent otherEnvelope = union.Geometry.EnvelopeInternal.ToExtent(); for (int shp = 0; shp < self.ShapeIndices.Count; shp++) { if (!self.ShapeIndices[shp].Extent.Intersects(otherEnvelope)) { continue; } IFeature selfFeature = self.GetFeature(shp); selfFeature.Intersection(union, result, joinType); pm.CurrentValue = shp; } pm.Reset(); } } else if (joinType == FieldJoinType.ForeignOnly) { if (!other.AttributesPopulated) { other.FillAttributes(); } result = new FeatureSet(); result.CopyTableSchema(other); result.FeatureType = other.FeatureType; if (self.Features != null && self.Features.Count > 0) { pm = new ProgressMeter(progHandler, "Calculating Union", self.Features.Count); IFeature union = self.Features[0]; for (int i = 1; i < self.Features.Count; i++) { union = union.Union(self.Features[i].Geometry); pm.CurrentValue = i; } pm.Reset(); if (other.Features != null) { pm = new ProgressMeter(progHandler, "Calculating Intersection", other.Features.Count); for (int i = 0; i < other.Features.Count; i++) { other.Features[i].Intersection(union, result, FieldJoinType.LocalOnly); pm.CurrentValue = i; } } pm.Reset(); } } return(result); }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { int progress = 0; int count = 1; if (_target_layer != null) { var nrow = _target_layer.NumRows(); var dx = System.Math.Sqrt(_target_layer.GetFeature(0).Geometry.Area); int nsample = (int)System.Math.Floor(dx / _dem_layer.CellHeight); var mat = new DataCube <float>(1, 1, nrow); mat.Name = Matrix; mat.Variables = new string[] { Matrix }; mat.TimeBrowsable = false; mat.AllowTableEdit = true; List <Coordinate> list = new List <Coordinate>(); if (_target_layer.FeatureType == FeatureType.Polygon) { for (int i = 0; i < nrow; i++) { float sum_cellv = 0; int npt = 0; list.Clear(); var fea = _target_layer.GetFeature(i).Geometry; var x0 = (from p in fea.Coordinates select p.X).Min(); var y0 = (from p in fea.Coordinates select p.Y).Min(); for (int r = 0; r <= nsample; r++) { var y = y0 + r * _dem_layer.CellHeight; for (int c = 0; c <= nsample; c++) { var x = x0 + c * _dem_layer.CellWidth; Coordinate pt = new Coordinate(x, y); list.Add(pt); } } foreach (var pt in list) { var cell = _dem_layer.ProjToCell(pt); if (cell != null && cell.Row > 0) { var buf = (float)_dem_layer.Value[cell.Row, cell.Column]; if (buf != _dem_layer.NoDataValue) { sum_cellv += buf; npt++; } } } if (npt > 0) { sum_cellv = sum_cellv / npt; } mat[0, 0, i] = sum_cellv; progress = i * 100 / nrow; if (progress > count) { cancelProgressHandler.Progress("Package_Tool", progress, "Processing polygon: " + i); count++; } } } else { Coordinate[] coors = new Coordinate[nrow]; for (int i = 0; i < nrow; i++) { var geo_pt = _target_layer.GetFeature(i).Geometry; coors[i] = geo_pt.Coordinate; } for (int i = 0; i < nrow; i++) { var cell = _dem_layer.ProjToCell(coors[i]); if (cell != null && cell.Row > 0) { mat[0, 0, i] = (float)_dem_layer.Value[cell.Row, cell.Column]; } progress = i * 100 / nrow; if (progress > count) { cancelProgressHandler.Progress("Package_Tool", progress, "Processing point: " + i); count++; } } } Workspace.Add(mat); return(true); } else { cancelProgressHandler.Progress("Package_Tool", 100, "Error message: the input layers are incorrect."); return(false); } }