Beispiel #1
0
        protected override void OnActivate()
        {
            try
            {
                UID dockWinID = new UIDClass();
                dockWinID.Value = ThisAddIn.IDs.EditForm;
                IDockableWindow dockWindow = ArcMap.DockableWindowManager.GetDockableWindow(dockWinID);
                if (!dockWindow.IsVisible())
                {
                    dockWindow.Show(true);
                }

                if (Editor.ActiveLayer == null)
                {
                    return;
                }

                IRasterLayer rasterLayer = (IRasterLayer)Editor.ActiveLayer;
                IRasterProps rasterProp = (IRasterProps)rasterLayer.Raster;
                maxIndex = new Position(rasterProp.Width - 1, rasterProp.Height - 1);

                EditForm editForm = AddIn.FromID<EditForm.AddinImpl>(ThisAddIn.IDs.EditForm).UI;
                editForm.SetLayer(Editor.ActiveLayer.Name);
                System.Array noDataValue = (System.Array)rasterProp.NoDataValue;
                editForm.RasterGridView.NoDataValue = Convert.ToDouble(noDataValue.GetValue(0));
                editForm.SetNoDataValue(editForm.RasterGridView.NoDataValue);
            }
            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");
            }

            base.OnActivate();
        }
Beispiel #2
0
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            base.OnMouseDown(arg);

            if ((Painter.ActiveLayer == null) ||
                (arg.Button != MouseButtons.Left))
            {
                return;
            }

            preMousePos = Raster.ScreenCoor2RasterCoor(arg.X, arg.Y, Painter.ActiveLayer);
        }
Beispiel #3
0
        public void DrawLine()
        {
            Position start = new Position();
            Position end = new Position();

            // Horizontal Line
            start.Column = end.Column = 3;
            start.Row = 3;
            end.Row = 9;

            Console.WriteLine("Horizontal Line");
            PrintPositions(ARES.Display.GetPolyline(start, end, new ARES.Envelope(0, 5, 0, 5)));

            // Vertical Line
            start.Row = end.Row = 3;
            start.Column = 3;
            end.Column = 9;

            Console.WriteLine("Vertical Line");
            PrintPositions(ARES.Display.GetPolyline(start, end, new ARES.Envelope(0, 5, 0, 5)));

            // k > 0
            start.Row = 8;
            end.Row = 3;
            start.Column = 12;
            end.Column = 8;

            Console.WriteLine("k >0");
            PrintPositions(ARES.Display.GetPolyline(start, end, new ARES.Envelope(0, 100, 0, 100)));

            // k < 0
            start.Row = 8;
            end.Row = 12;
            start.Column = 12;
            end.Column = 7;

            Console.WriteLine("k >0");
            PrintPositions(ARES.Display.GetPolyline(start, end, new ARES.Envelope(0, 100, 0, 100)));

            // outside box
            start.Row = 0;
            end.Row = 5;
            start.Column = 0;
            end.Column = 5;

            Console.WriteLine("outside box");
            PrintPositions(ARES.Display.GetPolyline(start, end, new ARES.Envelope(0, 3, 0, 3)));
        }
Beispiel #4
0
        /// <summary>
        /// Set the cell values of the identified region
        /// </summary>
        /// <param name="tlCorner">Left-top corner</param>
        /// <param name="brCorner">Right-bottom corner</param>
        /// <param name="values"></param>
        public void SetValues(Position tlCorner, Position brCorner, double[,] values)
        {
            tlPosTextBox.Text = String.Format("({0}, {1})", tlCorner.Column + 1, tlCorner.Row + 1);
            brPosTextBox.Text = String.Format("({0}, {1})", brCorner.Column + 1, brCorner.Row + 1);

            rasterGridView.SetValues(tlCorner, brCorner, values);
            PixelCollection editedCellCollection = Editor.Edits.WithIn(tlCorner, brCorner);
            for (int i = 0; i < editedCellCollection.Count; i++)
            {
                int gridViewCol = editedCellCollection[i].Position.Column - tlCorner.Column + 1;
                int gridViewRow = editedCellCollection[i].Position.Row - tlCorner.Row;

                if (editedCellCollection[i].NewValue == rasterGridView.NoDataValue)
                {
                    rasterGridView[gridViewCol, gridViewRow].Value = editedCellCollection[i].NewValue;
                }

                rasterGridView[gridViewCol, gridViewRow].Style.Font = new Font(rasterGridView.Font, FontStyle.Bold);
            }

            rasterGridView[0, 0].Selected = false;
        }
Beispiel #5
0
        /// <summary>
        /// Drawing the graphic element of the pixel box.
        /// </summary>
        /// <param name="boxSymbol">The graphic symbol of the drawing box.</param>
        /// <param name="pixelPos">The postion of drawing cell.</param>
        /// <param name="activeLayer">Raster layer to be symbolized.</param>
        /// <returns>An IFillShapeElement implimentation as IElement</returns>
        private static IElement DrawBoxElement(ISimpleFillSymbol boxSymbol, Position pixelPos, ILayer activeLayer = null)
        {
            // Probably should be removed.
            ILayer layer = activeLayer == null ? Editor.ActiveLayer : activeLayer;

            IActiveView activeView = ArcMap.Document.ActiveView;

            IFillShapeElement fillShapeElement = new RectangleElementClass();
            fillShapeElement.Symbol = (IFillSymbol)boxSymbol;

            // Retrive the cell coordinate and the cell size
            double x, y;
            IRasterLayer rasterLayer = (IRasterLayer)layer;
            IRaster2 raster = (IRaster2)rasterLayer.Raster;
            raster.PixelToMap(pixelPos.Column, pixelPos.Row, out x, out y);
            IRasterProps rasterProp = (IRasterProps)raster;
            IPnt cellSize = rasterProp.MeanCellSize();

            // Define the extent of the selection box
            IEnvelope envelop = new EnvelopeClass();
            envelop.XMin = x - cellSize.X / 2;
            envelop.XMax = x + cellSize.X / 2;
            envelop.YMin = y - cellSize.Y / 2;
            envelop.YMax = y + cellSize.Y / 2;

            IElement element = (IElement)fillShapeElement;
            element.Geometry = (IGeometry)envelop;

            activeView.GraphicsContainer.AddElement(element, 0);

            return element;
        }
Beispiel #6
0
        /// <summary>
        /// Gets locations of pixels on a specified polyline.
        /// </summary>
        /// <param name="startPos">Starting position of the polyline.</param>
        /// <param name="endPos">Ending position of the polyline.</param>
        /// <param name="envelop">Envelop of editting raster.</param>
        /// <returns></returns>
        public static Position[] GetPolyline(Position startPos, Position endPos, Envelope envelop)
        {
            Position[] polyline;
            Position pStartPos = startPos;
            Position pEndPos = endPos;

            #region Horizontal Line

            if (pStartPos.Column == pEndPos.Column)
            {
                if (pStartPos.Row > pEndPos.Row)
                {
                    Position temp = pStartPos;
                    pStartPos = pEndPos;
                    pEndPos = startPos;
                }

                pStartPos.Adjust(envelop);
                pEndPos.Adjust(envelop);

                polyline = new Position[pEndPos.Row - pStartPos.Row + 1];
                for (int i = pStartPos.Row; i <= pEndPos.Row; i++)
                {
                    polyline[i - pStartPos.Row] = new Position(pStartPos.Column, i);
                }

                return polyline;
            }

            #endregion

            #region Vertical Line

            if (pStartPos.Row == pEndPos.Row)
            {
                if (pStartPos.Column > pEndPos.Column)
                {
                    Position temp = pStartPos;
                    pStartPos = pEndPos;
                    pEndPos = startPos;
                }

                pStartPos.Adjust(envelop);
                pEndPos.Adjust(envelop);

                polyline = new Position[pEndPos.Column - pStartPos.Column + 1];
                for (int i = pStartPos.Column; i <= pEndPos.Column; i++)
                {
                    polyline[i - pStartPos.Column] = new Position(pStartPos.Column, i);
                }

                return polyline;
            }

            #endregion

            return DDALine(pStartPos, pEndPos, envelop);
        }
Beispiel #7
0
        /// <summary>
        /// Gets pixels on given line using Digital Differential Analyzer(DDA).
        /// </summary>
        /// <param name="startPos">Starting position</param>
        /// <param name="endPos">Ending position</param>
        /// <returns></returns>
        private static Position[] DDALine(Position startPos, Position endPos, Envelope envelope)
        {
            int x0 = startPos.Column;
            int y0 = startPos.Row;
            int x1 = endPos.Column;
            int y1 = endPos.Row;

            int dx = x1 - x0;
            int dy = y1 - y0;

            double x = x0;
            double y = y0;

            int steps = 0;
            if (System.Math.Abs(dx) > System.Math.Abs(dy))
            {
                steps = (int)System.Math.Abs(dx);
            }
            else
            {
                steps = (int)System.Math.Abs(dy);
            }

            List<Position> line = new List<Position>();

            double xIncrement = dx / (double)steps;
            double yincrement = dy / (double)steps;
            for (int k = 0; k <= steps; k++)
            {
                if (x >= 0 && x <= envelope.MaxColumn && y >= 0 && y <= envelope.MaxRow)
                {
                    line.Add(new Position((int)System.Math.Round(x), (int)System.Math.Round(y)));
                }

                x += xIncrement;
                y += yincrement;
            }

            return line.ToArray();
        }
Beispiel #8
0
        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");
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Get the position of pixels at line of the polygon.
        /// </summary>
        /// <param name="vertexes"></param>
        /// <param name="envelope"></param>
        /// <returns></returns>
        public static Position[] GetPolygon(Position[] vertexes, Envelope envelope)
        {
            List<Position> lines = new List<Position>();

            // It is not sure that whether the final vertex will be the first one. I assume it is.
            for (int i = 0; i < vertexes.Length - 1; i++)
            {
                Position[] line = GetPolyline(vertexes[i], vertexes[i + 1], envelope);
                lines.AddRange(line);
            }

            return lines.ToArray();
        }
Beispiel #10
0
        /// <summary>
        /// Gets value of pixel at the specified position.
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="raster"></param>
        /// <returns></returns>
        public static double GetValue(Position pos, IRaster raster)
        {
            IPnt regionSize = new PntClass();
            regionSize.SetCoords(1, 1);
            IPixelBlock pixelBlock = raster.CreatePixelBlock(regionSize);
            IPnt tl = new PntClass();
            tl.SetCoords(pos.Column, pos.Row);
            raster.Read(tl, pixelBlock);

            return Convert.ToDouble(pixelBlock.GetVal(0, 0, 0));
        }
Beispiel #11
0
 /// <summary>
 /// Paint the pixel at given position.
 /// </summary>
 /// <param name="pos"></param>
 private void PaintPixel(Position pos)
 {
     Pixel paintedPixel = Painter.Paints[pos];
     if (paintedPixel == null)
     {
         paintedPixel = new Pixel(Raster.GetValue(pos, Painter.ActiveLayer), pos);
         Painter.Paints.Add(paintedPixel);
     }
     else
     {
         Display.RemoveElement(paintedPixel.GraphicElement);
     }
     paintedPixel.NewValue = Convert.ToDouble(selectedValue);
     paintedPixel.GraphicElement = Display.DrawBox(pos,
                           Painter.GetPaintSymbol(selectedColor),
                           Painter.ActiveLayer,true);
 }
Beispiel #12
0
 /// <summary>
 /// Searches for a cell that locates at the input position in the collection and returns its index. If nothing is found, it returns -1.
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public int IndexOf(Position position)
 {
     return IndexOf(position.Column, position.Row);
 }
Beispiel #13
0
 /// <summary>
 /// Remove the cell at the specific position.
 /// </summary>
 /// <param name="pos"></param>
 public void RemoveAt(Position pos)
 {
     RemoveAt(pos.Column, pos.Row);
 }
Beispiel #14
0
        /// <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");
                }
            }
        }
Beispiel #15
0
 /// <summary>
 /// Examine whether the given rectangle region is within the extent of active layer. 
 /// </summary>
 /// <param name="tlCorner">Top-left corner of the given rectangle region.</param>
 /// <param name="brCorner">Bottom-right corner of the given rectangle region</param>
 /// <param name="maxIndex">Maximium extent of the active layer.</param>
 /// <returns></returns>
 private bool IsIntersect(Position tlCorner, Position brCorner, Position maxIndex)
 {
     return !(tlCorner.Column > maxIndex.Column || tlCorner.Row > maxIndex.Row || brCorner.Column < 0 || brCorner.Row < 0);
 }
Beispiel #16
0
        /// <summary>
        /// Start to track the rectangle when mouse down.
        /// </summary>
        /// <param name="arg"></param>
        protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            base.OnMouseDown(arg);

            activeLayer = ArcMapApp.GetRasterLayer();

            if (activeLayer != null)
            {
                try
                {
                    Display.ClearElement(Editor.Selections.GetAllGraphicElements());
                    Editor.Selections.Clear();

                    // Define the selection symbol.
                    IRgbColor color = new RgbColorClass();
                    color.Red = 255;
                    color.Green = 255;
                    color.Blue = 255;

                    ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
                    lineSymbol.Width = 1;
                    lineSymbol.Color = (IColor)color;

                    IPoint startCoor = Raster.ScreenCoor2MapCoor(arg.X, arg.Y);
                    newEnvelopeFeedback = new NewEnvelopeFeedbackClass();
                    newEnvelopeFeedback.Display = ArcMap.Document.ActiveView.ScreenDisplay;
                    newEnvelopeFeedback.Symbol = (ISymbol)lineSymbol;
                    newEnvelopeFeedback.Start(startCoor);

                    // Get the maximum extent of the active layer.
                    IRasterProps rasterProps = (IRasterProps)activeLayer.Raster;
                    maxExtent = new Position(rasterProps.Width, rasterProps.Height);
                }
                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");
                }
            }
        }
Beispiel #17
0
        private void deleteSelectionToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                int row = int.Parse(rowIndexTextBox.Text) - 1;
                int col = int.Parse(colIndexTextBox.Text) - 1;
                Position pos = new Position(col, row);

                if (Editor.Selections.Exists(pos))
                {
                    Display.RemoveElement(Editor.Selections[pos].GraphicElement, true);
                    Editor.Selections.Remove(pos);
                }
            }
            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");
            }
        }
Beispiel #18
0
        /// <summary>
        /// Get the pixel values in a region of the input raster.
        /// </summary>
        /// <param name="tlCorner"></param>
        /// <param name="brCorner"></param>
        /// <param name="raster"></param>
        /// <returns></returns>
        public static double[,] GetValues(Position tlCorner, Position brCorner, IRaster raster)
        {
            int colCount = brCorner.Column - tlCorner.Column + 1;
            int rowCount = brCorner.Row - tlCorner.Row + 1;

            IPnt regionSize = new PntClass();
            regionSize.SetCoords(colCount, rowCount);
            IPixelBlock pixelBlock = raster.CreatePixelBlock(regionSize);
            IPnt tl = new PntClass();
            tl.SetCoords(tlCorner.Column, tlCorner.Row);
            raster.Read(tl, pixelBlock);

            double[,] values = new double[colCount, rowCount];
            for (int x = 0; x < colCount; x++)
            {
                for (int y = 0; y < rowCount; y++)
                {
                    values[x, y] = Convert.ToDouble(pixelBlock.GetVal(0, x, y));
                }
            }
            return values;
        }
Beispiel #19
0
        /// <summary>
        /// Draw box symbol at the given position.
        /// </summary>
        /// <param name="pos">Position of pixel</param>
        /// <param name="activeLayer">Raster layer to add symbol</param>
        /// <param name="refresh">An value indicating whether to refresh screen after adding symbol</param>
        /// <param name="symbol">Symbol style</param>
        public static IElement DrawBox(Position pos, ISimpleFillSymbol symbol, ILayer activeLayer, bool refresh = false)
        {
            if (activeLayer != null)
            {
                IElement element = DrawBoxElement(symbol, pos, activeLayer);

                if (refresh)
                {
                    Refresh();
                }

                return element;
            }

            return null;
        }
Beispiel #20
0
 /// <summary>
 /// Get the cell with the input position.
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public Pixel this[Position position]
 {
     get { return this[position.Column, position.Row]; }
 }
Beispiel #21
0
 /// <summary>
 /// Determine whether the collection contains elements with the specified position. 
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public bool Exists(Position position)
 {
     return this.Exists(position.Column, position.Row);
 }
Beispiel #22
0
 /// <summary>
 /// Gets value of pixel at the specified position.
 /// </summary>
 /// <param name="pos"></param>
 /// <param name="rasterLayer"></param>
 /// <returns></returns>
 public static double GetValue(Position pos, IRasterLayer rasterLayer)
 {
     return GetValue(pos, rasterLayer.Raster);
 }
Beispiel #23
0
        /// <summary>
        /// Remove the pixel with input position.
        /// </summary>
        /// <param name="pos"></param>
        public void Remove(Position pos)
        {
            Pixel pixel = this[pos];

            if (pixel != null)
            {
                pixelCollection.Remove(pixel);
            }
        }
Beispiel #24
0
 /// <summary>
 /// Indicates whether the given position is within the envelope.
 /// </summary>                   
 /// <param name="position"></param>
 /// <returns></returns>
 public bool Contains(Position position)
 {
     return Contains(position.Row, position.Column);
 }
Beispiel #25
0
 /// <summary>
 /// Find all cells in the collection whose position are within the specified envelop.
 /// </summary>
 /// <param name="tlCorner"></param>
 /// <param name="brCorner"></param>
 /// <returns></returns>
 public PixelCollection WithIn(Position tlCorner, Position brCorner)
 {
     return WithIn(tlCorner.Column, brCorner.Column, tlCorner.Row, brCorner.Row);
 }
Beispiel #26
0
 /// <summary>
 /// Set the extent of the envelope.
 /// </summary>
 /// <param name="tlCorner">Top-left corner of the envelope.</param>
 /// <param name="brCorner">Bottom-right corner of the envelope.</param>
 public void SetExtent(Position tlCorner, Position brCorner)
 {
     SetExtent(tlCorner.Row, brCorner.Row, tlCorner.Column, brCorner.Column);
 }
Beispiel #27
0
        protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            base.OnMouseDown(arg);

            try
            {
                if ((Painter.ActiveLayer == null) ||
                    (arg.Button != MouseButtons.Left) ||
                    (selectedValue == null))
                {
                    return;
                }
                else
                {
                    // If the mouse does not move, paint at the clicked pixel
                    Position mousePos = Raster.ScreenCoor2RasterCoor(arg.X, arg.Y, Painter.ActiveLayer);
                    if (layerExetent.Contains(mousePos) && iniMousePos.Equals(mousePos))
                    {
                        PaintPixel(mousePos);
                    }
                }
            }
            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");
            }

            iniMousePos = null;
            preMousePos = null;
        }
Beispiel #28
0
 /// <summary>
 /// Initialize a new evelope class.
 /// </summary>
 /// <param name="tlCorner">Top-left corner of the envelope.</param>
 /// <param name="brCorner">Bottom-right corner of the envelope.</param>
 public Envelope(Position tlCorner, Position brCorner)
 {
     SetExtent(tlCorner, brCorner);
 }
Beispiel #29
0
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            base.OnMouseDown(arg);

            try
            {
                ValueSymbolForm valueSymbolForm = AddIn.FromID<ValueSymbolForm.AddinImpl>(ThisAddIn.IDs.ValueSymbolForm).UI;
                selectedValue = valueSymbolForm.SelectedValue;
                selectedColor = valueSymbolForm.SelectedColor;

                if ((Painter.ActiveLayer == null) ||
                    (arg.Button != MouseButtons.Left) ||
                    (selectedValue == null))
                {
                    return;
                }

                preMousePos = Raster.ScreenCoor2RasterCoor(arg.X, arg.Y, Painter.ActiveLayer);
                iniMousePos = preMousePos;
            }
            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");
            }
        }
Beispiel #30
0
        /// <summary>
        /// Flash the selected pixel.
        /// </summary>
        /// <param name="pixelPos">Position of the selected pixel</param>
        /// <param name="IntervalOfFlashing">Interval of Flashing (ms)</param>
        /// <param name="activeLayer">Raster layer to be symbolized.</param>
        public static void FlashSelection(Position pixelPos, int IntervalOfFlashing = 500, ILayer activeLayer = null)
        {
            ArcMap.Document.ActiveView.Refresh();

            // Probably should be removed.
            ILayer layer = activeLayer == null ? Editor.ActiveLayer : activeLayer;

            if (layer != null)
            {
                IDisplay display = (IDisplay)ArcMap.Document.ActiveView.ScreenDisplay;
                display.StartDrawing(display.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache);

                ISymbol symbol = (ISymbol)Config.SelectionSmbol;
                symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;

                // Retrive the cell coordinate and the cell size
                double x, y;
                IRasterLayer rasterLayer = (IRasterLayer)layer;
                IRaster2 raster = (IRaster2)rasterLayer.Raster;
                raster.PixelToMap(pixelPos.Column, pixelPos.Row, out x, out y);
                IRasterProps rasterProp = (IRasterProps)raster;
                IPnt cellSize = rasterProp.MeanCellSize();

                // Define the extent of the selection box
                IEnvelope envelop = new EnvelopeClass();
                envelop.XMin = x - cellSize.X / 2;
                envelop.XMax = x + cellSize.X / 2;
                envelop.YMin = y - cellSize.Y / 2;
                envelop.YMax = y + cellSize.Y / 2;

                display.SetSymbol(symbol);
                display.DrawPolygon((IGeometry)envelop);
                Thread.Sleep(IntervalOfFlashing);
                display.DrawPolygon((IGeometry)envelop);
                display.FinishDrawing();
            }
        }