Exemplo n.º 1
0
        protected override void OnActivate()
        {
            base.OnActivate();

            try
            {
                if (Painter.ActiveLayer == null)
                {
                    return;
                }

                UID dockWinID = new UIDClass();
                dockWinID.Value = ThisAddIn.IDs.ValueSymbolForm;
                IDockableWindow dockWindow = ArcMap.DockableWindowManager.GetDockableWindow(dockWinID);
                if (!dockWindow.IsVisible())
                {
                    dockWindow.Show(true);
                }

                IRasterLayer rasterLayer = (IRasterLayer)Painter.ActiveLayer;
                IRasterProps rasterProp = (IRasterProps)rasterLayer.Raster;
                layerExetent = new Envelope(0, rasterProp.Height - 1, 0, rasterProp.Width - 1);
            }
            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");
            }
        }
Exemplo n.º 2
0
        protected override void OnActivate()
        {
            base.OnActivate();

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

            IRasterLayer rasterLayer = (IRasterLayer)Painter.ActiveLayer;
            IRasterProps rasterProp = (IRasterProps)rasterLayer.Raster;
            layerExetent = new Envelope(0, rasterProp.Height - 1, 0, rasterProp.Width - 1);
        }
Exemplo n.º 3
0
        protected override void OnActivate()
        {
            base.OnActivate();

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

            UID dockWinID = new UIDClass();
            dockWinID.Value = ThisAddIn.IDs.ValueSymbolForm;
            IDockableWindow dockWindow = ArcMap.DockableWindowManager.GetDockableWindow(dockWinID);
            if (!dockWindow.IsVisible())
            {
                dockWindow.Show(true);
            }

            IRasterLayer rasterLayer = (IRasterLayer)Painter.ActiveLayer;
            IRasterProps rasterProp = (IRasterProps)rasterLayer.Raster;
            layerExetent = new Envelope(0, rasterProp.Height - 1, 0, rasterProp.Width - 1);
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Adjust the position to satisfy the given envelop.
 /// </summary>
 /// <param name="maxExtent"></param>
 public void Adjust(Envelope envelop)
 {
     Adjust(envelop.TLCorner, envelop.BRCorner);
 }