/// <summary> /// Executes the Erase Opaeration tool programaticaly. /// </summary> /// <param name="input1">The input raster.</param> /// <param name="input2">The input raster.</param> /// <param name="output">The output raster.</param> /// <param name="cancelProgressHandler">The progress handler.</param> /// <returns></returns> public bool Execute(IRaster input1, IFeatureSet input2, IRaster output, MapWindow.Tools.ICancelProgressHandler cancelProgressHandler) { //Validates the input and output data if (input1 == null || input2 == null || output == null) { return false; } int noOfCol = input1.NumColumns; int noOfRow = input1.NumRows; //Calculate the Intersect Envelope IEnvelope envelope1 = new Envelope() as IEnvelope; IEnvelope envelope2 = new Envelope() as IEnvelope; envelope1 = input1.Bounds.Envelope; envelope2 = input2.Envelope; envelope1 = envelope1.Intersection(envelope2); //Create the new raster with the appropriate dimensions IRaster Temp = Raster.Create(output.Filename, "", noOfCol, noOfRow, 1, input1.DataType, new string[] { }); //Temp.CreateNew(output.Filename, noOfRow, noOfCol, input1.DataType); Temp.CellWidth = input1.CellWidth; Temp.CellHeight = input1.CellHeight; Temp.Xllcenter = envelope1.Minimum.X + (Temp.CellWidth / 2); Temp.Yllcenter = envelope1.Minimum.Y + (Temp.CellHeight / 2); MapWindow.Geometries.ICoordinate I1 = new MapWindow.Geometries.Coordinate() as MapWindow.Geometries.ICoordinate; RcIndex v1 = new RcIndex(); // MapWindow.Analysis.Topology.Algorithm.PointLocator pointLocator1 = new MapWindow.Analysis.Topology.Algorithm.PointLocator(); double val1; int previous = 0; int current = 0; int max = (Temp.Bounds.NumRows + 1); for (int i = 0; i < Temp.Bounds.NumRows; i++) { for (int j = 0; j < Temp.Bounds.NumColumns; j++) { I1 = Temp.CellToProj(i, j); v1 = input1.ProjToCell(I1); if (v1.Row <= input1.EndRow && v1.Column <= input1.EndColumn && v1.Row > -1 && v1.Column > -1) val1 = input1.Value[v1.Row, v1.Column]; else val1 = Temp.NoDataValue; //test if the coordinate is inside of the polygon bool isInside = false; IFeature pointFeat = new Feature(new Point(I1)) as IFeature; foreach (IFeature f in input2.Features) { if (f.Contains(pointFeat)) { Temp.Value[i, j] = val1; isInside = true; break; } } if (isInside == false) { Temp.Value[i, j] = Temp.NoDataValue; } if (cancelProgressHandler.Cancel == true) return false; } current = Convert.ToInt32(Math.Round(i * 100D / max)); //only update when increment in percentage if (current > previous) cancelProgressHandler.Progress("", current, current.ToString() + "% progress completed"); previous = current; } output = Temp; output.Save(); return true; }
/// <summary> /// Performs an intersection of this line segment with the specified envelope /// </summary> /// <param name="inEnvelope">The envelope to compare against</param> /// <returns>An ILineSegment, or null if there is no intersection.</returns> public ILineSegment Intersection(Envelope inEnvelope) { return inEnvelope.Intersection(this); }