protected override void OnDoubleClick() { base.OnDoubleClick(); if (isDrawing && Editor.ActiveLayer != null) { IPoint startCoor = Raster.ScreenCoor2MapCoor(Control.MousePosition.X, Control.MousePosition.Y); newLineFeedback.AddPoint(startCoor); IPointCollection pointCollection = (IPointCollection)newLineFeedback.Stop(); List <Position> pointList = new List <Position>(); for (int i = 0; i < pointCollection.PointCount - 1; i++) { Position startPos = Raster.MapCoor2RasterCoor(pointCollection.get_Point(i), Painter.ActiveLayer); Position endPos = Raster.MapCoor2RasterCoor(pointCollection.get_Point(i + 1), Painter.ActiveLayer); pointList.AddRange(Display.GetPolyline(startPos, endPos, layerExetent)); } isDrawing = false; } }
/// <summary> /// Save modification to the original file. /// </summary> public static void SaveEdits() { Raster.SaveEdits((IRasterLayer)ActiveLayer, Edits); }
/// <summary> /// Save the edition as a specified file. /// </summary> /// <param name="fileName"></param> public static void SaveEditsAs(string fileName) { Raster.SaveEditsAs(fileName, (IRasterLayer)ActiveLayer, Edits); }
/// <summary> /// Validate the input value. /// </summary> /// <param name="value">The input value.</param> /// <param name="validValue">If validation successes, return the validated value. If not, return null.</param> /// <returns>A value indicating whether the validationg is successful.</returns> private bool ValueValidate(string value, out object validValue) { IRasterProps rasterProp = (IRasterProps)Painter.ActiveLayer.Raster; return(Raster.CSharpValue2PixelValue(value, rasterProp.PixelType, out validValue)); }
/// <summary> /// Write edits to the input raster. /// </summary> /// <param name="raster">Raster of raster layer to be edited.</param> /// <param name="edits">Pixel collection that contains edited pixels.</param> private static void WriteEdits(IRaster raster, PixelCollection edits) { IRasterProps rasterProps = (IRasterProps)raster; int minRow = rasterProps.Height - 1; int maxRow = 0; int minCol = rasterProps.Width - 1; int maxCol = 0; for (int i = 0; i < edits.Count; i++) { #region Get the extent of the edition region Position cellPos = edits[i].Position; if (cellPos.Row > maxRow) { maxRow = cellPos.Row; } if (cellPos.Row < minRow) { minRow = cellPos.Row; } if (cellPos.Column > maxCol) { maxCol = cellPos.Column; } if (cellPos.Column < minCol) { minCol = cellPos.Column; } #endregion } IPnt pos = new PntClass(); pos.SetCoords(maxCol - minCol + 1, maxRow - minRow + 1); IPixelBlock pixelBlock = raster.CreatePixelBlock(pos); pos.SetCoords(minCol, minRow); raster.Read(pos, pixelBlock); // Set new values IPixelBlock3 pixelBlock3 = (IPixelBlock3)pixelBlock; Array pixels = (Array)pixelBlock3.get_PixelData(0); for (int i = 0; i < edits.Count; i++) { object value = null; Raster.CSharpValue2PixelValue(edits[i].NewValue, rasterProps.PixelType, out value); pixels.SetValue(value, edits[i].Position.Column - minCol, edits[i].Position.Row - minRow); } pixelBlock3.set_PixelData(0, (System.Object)pixels); IRasterEdit rasterEdit = (IRasterEdit)raster; rasterEdit.Write(pos, (IPixelBlock)pixelBlock3); }
/// <summary> /// Select the pixels when mouse up. /// </summary> /// <param name="arg"></param> protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { base.OnMouseUp(arg); if (activeLayer != null) { try { IEnvelope envelop = newEnvelopeFeedback.Stop(); UID dockWinID = new UIDClass(); dockWinID.Value = ThisAddIn.IDs.IdentifyForm; // Use GetDockableWindow directly as we want the client IDockableWindow not the internal class IDockableWindow dockWindow = ArcMap.DockableWindowManager.GetDockableWindow(dockWinID); IdentifyForm identifyForm = AddIn.FromID <IdentifyForm.AddinImpl>(ThisAddIn.IDs.IdentifyForm).UI; Position tlCorner, brCorner; if (envelop.UpperLeft.IsEmpty) { tlCorner = Raster.ScreenCoor2RasterCoor(arg.X, arg.Y, activeLayer); brCorner = tlCorner; } else { tlCorner = Raster.MapCoor2RasterCoor(envelop.UpperLeft, activeLayer); brCorner = Raster.MapCoor2RasterCoor(envelop.LowerRight, activeLayer); } if (!IsIntersect(tlCorner, brCorner, maxExtent)) { identifyForm.ClearValues(); return; } tlCorner.Adjust(0, 0, maxExtent.Column, maxExtent.Row); brCorner.Adjust(0, 0, maxExtent.Column, maxExtent.Row); // Show symbols of selected pixels for (int row = tlCorner.Row; row <= brCorner.Row; row++) { for (int col = tlCorner.Column; col <= brCorner.Column; col++) { Position pos = new Position(col, row); if (!Editor.Selections.Exists(pos)) { Pixel pixel = new Pixel(pos); pixel.GraphicElement = Display.DrawBox(pixel.Position, Editor.GetSelectionSymbol(), ArcMapApp.GetRasterLayer()); Editor.Selections.Add(pixel); } } } Display.Refresh(); double[,] values = Raster.GetValues(tlCorner, brCorner, activeLayer.Raster); identifyForm.SetValues(tlCorner, brCorner, values); identifyForm.SetLayerName(activeLayer.Name); if (!dockWindow.IsVisible()) { dockWindow.Show(true); } } catch (Exception ex) { MessageBox.Show(string.Format("Unfortunately, the application meets an error.\n\nSource: {0}\nSite: {1}\nMessage: {2}", ex.Source, ex.TargetSite, ex.Message), "Error"); } } }
protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { base.OnMouseDown(arg); if (Editor.ActiveLayer != null) { try { UID uid = new UIDClass(); uid.Value = ThisAddIn.IDs.EditForm; IDockableWindow dockWin = ArcMap.DockableWindowManager.GetDockableWindow(uid); EditForm editForm = AddIn.FromID <EditForm.AddinImpl>(ThisAddIn.IDs.EditForm).UI; IEnvelope envelop = newEnvelopeFeedback.Stop(); Position tlCorner, brCorner; if (envelop.UpperLeft.IsEmpty) { tlCorner = Raster.ScreenCoor2RasterCoor(arg.X, arg.Y, (IRasterLayer)Editor.ActiveLayer); brCorner = tlCorner; } else { tlCorner = Raster.MapCoor2RasterCoor(envelop.UpperLeft, (IRasterLayer)Editor.ActiveLayer); brCorner = Raster.MapCoor2RasterCoor(envelop.LowerRight, (IRasterLayer)Editor.ActiveLayer); } if (!IsIntersect(tlCorner, brCorner, maxIndex)) { editForm.ClearValues(); return; } tlCorner.Adjust(0, 0, maxIndex.Column, maxIndex.Row); brCorner.Adjust(0, 0, maxIndex.Column, maxIndex.Row); // Show symbols of selected pixels for (int row = tlCorner.Row; row <= brCorner.Row; row++) { for (int col = tlCorner.Column; col <= brCorner.Column; col++) { Position pos = new Position(col, row); if (!Editor.Selections.Exists(pos)) { Pixel pixel = new Pixel(pos); pixel.GraphicElement = Display.DrawBox(pixel.Position, Editor.GetSelectionSymbol(), Editor.ActiveLayer); Editor.Selections.Add(pixel); } } } Display.Refresh(); IRasterLayer rasterLayer = (IRasterLayer)Editor.ActiveLayer; double[,] values = Raster.GetValues(tlCorner, brCorner, rasterLayer.Raster); editForm.SetValues(tlCorner, brCorner, values); // If there is only one value, select that. if (values.Length == 1) { editForm.RasterGridView[0, 0].Selected = false; editForm.RasterGridView[1, 0].Selected = true; } if (!dockWin.IsVisible()) { dockWin.Show(true); } } catch (Exception ex) { MessageBox.Show(string.Format("Unfortunately, the application meets an error.\n\nSource: {0}\nSite: {1}\nMessage: {2}", ex.Source, ex.TargetSite, ex.Message), "Error"); } } }
/// <summary> /// Gets the render color of the specific position in the input raster layer. /// </summary> /// <param name="rasterLayer"></param> /// <param name="position"></param> /// <returns></returns> public static IColor GetRenderColor(IRasterLayer rasterLayer, Position position) { return(GetRenderColor(rasterLayer, Raster.GetValue(position, rasterLayer))); }