Ejemplo n.º 1
0
        public void GetLayerTypeTest()
        {
            MapWindow.Layer target      = new Layer();                                        // TODO: Initialize to an appropriate value
            int             LayerHandle = 0;                                                  // TODO: Initialize to an appropriate value

            MapWindow.Interfaces.eLayerType expected = new MapWindow.Interfaces.eLayerType(); // TODO: Initialize to an appropriate value
            MapWindow.Interfaces.eLayerType actual;
            actual = target.GetLayerType(LayerHandle);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 2
0
 private void LayerSelected(int Handle)
 {
     MapWindow.Interfaces.eLayerType lt = m_globals.MapWin.Layers[Handle].LayerType;
     if (lt == MapWindow.Interfaces.eLayerType.LineShapefile || lt == MapWindow.Interfaces.eLayerType.PointShapefile ||
         lt == MapWindow.Interfaces.eLayerType.PolygonShapefile)
     {
         m_CurrentShapefile = (MapWinGIS.Shapefile)m_globals.MapWin.Layers[Handle].GetObject();
     }
     else
     {
         m_CurrentShapefile = null;
     }
 }
Ejemplo n.º 3
0
        public void LayerSelectedEvent(int Handle)
        {
            if (m_globals.CurrentLayer != null)
            {
                MapWindow.Interfaces.eLayerType t = m_globals.MapWin.Layers[m_globals.MapWin.Layers.CurrentLayer].LayerType;

                if ((m_snapper == null) && ((t == lt.LineShapefile) || (t == lt.PointShapefile) || (t == lt.PolygonShapefile)))
                {
                    m_snapper = new SnapClass(m_globals.MapWin);
                }
            }
            else
            {
                m_snapper = null;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor.
        /// The AddShapeForm is used when creating a new shape.
        /// The user can either click on the map to generate new points, lines or polygons, or input coordinates in the text boxes provided on the form.
        /// </summary>
        public AddShapeForm(GlobalFunctions g, ref SnapClass snapper)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            m_globals         = g;
            m_cursor          = new System.Windows.Forms.Cursor(this.GetType(), "InsertPoint.cur");
            view              = g.MapWin.View;
            m_oldCursorMode   = view.CursorMode;
            m_oldCursor       = view.MapCursor;
            m_oldCursorHandle = view.UserCursorHandle;
            view.CursorMode   = MapWinGIS.tkCursorMode.cmNone;
            view.MapCursor    = MapWinGIS.tkCursor.crsrWait;

            m_SFType = g.MapWin.Layers[g.MapWin.Layers.CurrentLayer].LayerType;
            m_Shape  = new ShapeClass();

            // Sign me up for these events!
            m_MapMouseMoveDelegate = new MapWindow.Events.MapMouseMoveEvent(MouseMoveEvent);
            g.Events.AddHandler(m_MapMouseMoveDelegate);
            m_MapMouseUpDelegate = new MapWindow.Events.MapMouseUpEvent(MouseUpEvent);
            g.Events.AddHandler(m_MapMouseUpDelegate);
            m_LayerSelectedDelegate = new MapWindow.Events.LayerSelectedEvent(LayerSelectedEvent);
            g.Events.AddHandler(m_LayerSelectedDelegate);

            MapWindow.Interfaces.eLayerType t = g.MapWin.Layers[g.MapWin.Layers.CurrentLayer].LayerType;

            m_sf = g.CurrentLayer;

            if ((m_snapper == null) && ((t == lt.LineShapefile) || (t == lt.PointShapefile) || (t == lt.PolygonShapefile)))
            {
                m_snapper = new SnapClass(m_globals.MapWin);
            }

            view.MapCursor        = MapWinGIS.tkCursor.crsrUserDefined;
            view.UserCursorHandle = m_cursor.Handle.ToInt32();

            m_PointSize = 6;
        }
Ejemplo n.º 5
0
        public void UpdateCurrentLayer()
        {
            // Clear our undo history and start over:
            UndoClearHistory();

            if (MapWin == null || MapWin.Layers == null)
            {
                m_CurrentLayer = null;
                return;
            }
            int cl = MapWin.Layers.CurrentLayer;

            if (cl == -1)
            {
                m_CurrentLayer = null;
                return;
            }
            if (!MapWin.Layers.IsValidHandle(cl))
            {
                m_CurrentLayer = null;
            }
            else
            {
                MapWindow.Interfaces.eLayerType lt = MapWin.Layers[cl].LayerType;
                if (lt == MapWindow.Interfaces.eLayerType.LineShapefile || lt == MapWindow.Interfaces.eLayerType.PointShapefile || lt == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                {
                    m_CurrentLayer = (MapWinGIS.Shapefile)MapWin.Layers[MapWin.Layers.CurrentLayer].GetObject();
                    System.IO.FileInfo LayerInfo = new System.IO.FileInfo(m_CurrentLayer.Filename);
                    m_LayerSize = LayerInfo.Length;
                }
                else
                {
                    m_CurrentLayer = null;
                }
            }
        }
Ejemplo n.º 6
0
        private void LoadLayer()
        {
            try
            {
                //exit if their is no layers to load
                if (m_MapWin.Layers.NumLayers <= 0)
                {
                    return;
                }

                // Always try to create the panel; if it doesn't exist,
                // it will be created, and if it does exist, a handle will be returned.
                m_UIPanel = m_MapWin.UIPanel.CreatePanel("Identifier", DockStyle.None);
                // Not intuitive -- m_UIPanel = m_MapWin.UIPanel.CreatePanel("Identifier", MapWindow.Interfaces.MapWindowDockStyle.RightAutoHide);
                if (m_UIPanel != null)
                {
                    m_MapWin.UIPanel.AddOnCloseHandler("Identifier", OnPanelClose);
                    m_HavePanel = true;
                }

                if (m_OnWMSLayer)
                {
                    if (m_GridPropfrm.Visible || m_shpFilePropfrm.Visible)
                    {
                        m_shpFilePropfrm.Hide();
                        m_GridPropfrm.Hide();
                    }

                    if (m_WMSLayerIDReturn != "")
                    {
                        m_WMSPropfrm.PopulateForm(!m_HavePanel, m_WMSLayerIDReturn, m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Name, false);
                    }

                    if (m_HavePanel && m_UIPanel != null)
                    {
                        if (m_WMSPropfrm.panel1 == null || m_WMSPropfrm.panel1.IsDisposed)
                        {
                            m_WMSPropfrm = new mwIdentifier.Forms.frmWMSProp(this);
                        }

                        if (m_UIPanel_LastType != "WMS" && m_UIPanel_LastType != "")
                        {
                            while (m_UIPanel.Controls.Count > 0)
                            {
                                m_UIPanel.Controls.RemoveAt(0);
                            }
                        }

                        if (m_UIPanel.Controls.Count == 0)
                        {
                            m_UIPanel.Controls.Add(m_WMSPropfrm.panel1);
                            m_UIPanel_LastType = "WMS";
                        }
                        else
                        {
                            m_MapWin.UIPanel.SetPanelVisible("Identifier", true);
                        }

                        m_WMSPropfrm.Hide();
                    }
                }
                else
                {
                    //get the object from mapwindow
                    object obj       = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].GetObject();
                    string layerName = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Name;
                    MapWindow.Interfaces.eLayerType LayerType = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].LayerType;


                    //if the layer is a shapefile
                    if (LayerType == MapWindow.Interfaces.eLayerType.LineShapefile ||
                        LayerType == MapWindow.Interfaces.eLayerType.PointShapefile ||
                        LayerType == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                    {
                        if (m_GridPropfrm.Visible || m_WMSPropfrm.Visible)
                        {
                            m_WMSPropfrm.Hide();
                            m_GridPropfrm.Hide();
                        }

                        //check to see if there is any previously selected shapes
                        if (m_MapWin.View.SelectedShapes.NumSelected > 0)
                        {
                            int   numSel   = m_MapWin.View.SelectedShapes.NumSelected;
                            int[] shpIndex = new int[numSel];

                            for (int i = 0; i < numSel; i++)
                            {
                                shpIndex[i] = m_MapWin.View.SelectedShapes[i].ShapeIndex;
                            }
                            m_shpFilePropfrm.PopulateForm(!m_HavePanel, (Shapefile)obj, shpIndex, m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Name, false);
                        }
                        else
                        {
                            m_shpFilePropfrm.PopulateForm(!m_HavePanel, (Shapefile)obj, m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Name, false);
                        }
                    }
                    //if the layer is a grid
                    else if (LayerType == MapWindow.Interfaces.eLayerType.Grid)
                    {
                        if (m_shpFilePropfrm.Visible || m_WMSPropfrm.Visible)
                        {
                            m_WMSPropfrm.Hide();
                            m_shpFilePropfrm.Hide();
                        }

                        //get the grid object
                        Grid grid = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].GetGridObject;

                        if (grid != null)
                        {
                            m_GridPropfrm.PopulateForm(!m_HavePanel, grid, layerName, null, m_MapWin.Layers.CurrentLayer);
                        }
                        else
                        {
                            m_GridPropfrm.Hide();
                        }
                    }
                    //if the layer is a image
                    else if (LayerType == MapWindow.Interfaces.eLayerType.Image)
                    {
                        // Chris Michaelis - 5-17-2007 - Allow identification of image values (the color values), better than nothing.
                        // Do this when no associated grid is found of course.

                        if (m_shpFilePropfrm.Visible || m_WMSPropfrm.Visible)
                        {
                            m_WMSPropfrm.Hide();
                            m_shpFilePropfrm.Hide();
                        }

                        Grid grid = FindAssociatedGrid(((MapWinGIS.Image)obj).Filename);

                        if (grid != null)
                        {
                            m_GridPropfrm.PopulateForm(!m_HavePanel, grid, layerName, null, m_MapWin.Layers.CurrentLayer);
                        }
                        else
                        {
                            // Identify by values -- so just open the first band of the image.
                            // This only works for greyscale of course in this version (one band grids only)

                            Grid tmpGrid = new Grid();
                            try
                            {
                                // Open as a grid to get values
                                if (tmpGrid.Open(((MapWinGIS.Image)obj).Filename, GridDataType.UnknownDataType, false, GridFileType.UseExtension, null))
                                {
                                    m_GridPropfrm.PopulateForm(!m_HavePanel, tmpGrid, layerName, null, m_MapWin.Layers.CurrentLayer);
                                }
                                else
                                {
                                    MapWinUtility.Logger.Message("No information on this image can be displayed.", "Identifier", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information, DialogResult.OK);
                                    m_GridPropfrm.Hide();
                                }
                            }
                            catch
                            {
                                m_GridPropfrm.Hide();
                            }
                        }
                    }

                    if (m_HavePanel && m_UIPanel != null)
                    {
                        //if the layer is a shapefile
                        if (LayerType == MapWindow.Interfaces.eLayerType.LineShapefile ||
                            LayerType == MapWindow.Interfaces.eLayerType.PointShapefile ||
                            LayerType == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                        {
                            if (m_shpFilePropfrm.panel1 == null || m_shpFilePropfrm.panel1.IsDisposed)
                            {
                                m_shpFilePropfrm = new mwIdentifier.Forms.frmShapeFileProp(this);
                            }

                            if (m_UIPanel_LastType != "shapefile" && m_UIPanel_LastType != "")
                            {
                                while (m_UIPanel.Controls.Count > 0)
                                {
                                    m_UIPanel.Controls.RemoveAt(0);
                                }
                            }

                            if (m_UIPanel.Controls.Count == 0)
                            {
                                m_UIPanel.Controls.Add(m_shpFilePropfrm.panel1);
                                m_UIPanel_LastType = "shapefile";
                            }
                            else
                            {
                                m_MapWin.UIPanel.SetPanelVisible("Identifier", true);
                            }

                            m_shpFilePropfrm.Hide();
                        }
                        //if the layer is a grid or image
                        else if (LayerType == MapWindow.Interfaces.eLayerType.Grid || LayerType == MapWindow.Interfaces.eLayerType.Image)
                        {
                            if (m_GridPropfrm.panel1 == null || m_GridPropfrm.panel1.IsDisposed)
                            {
                                m_GridPropfrm = new mwIdentifier.Forms.frmGridProp(this);
                            }

                            if (m_UIPanel_LastType != "grid" && m_UIPanel_LastType != "")
                            {
                                while (m_UIPanel.Controls.Count > 0)
                                {
                                    m_UIPanel.Controls.RemoveAt(0);
                                }
                            }

                            if (m_UIPanel.Controls.Count == 0)
                            {
                                m_UIPanel.Controls.Add(m_GridPropfrm.panel1);
                                m_UIPanel_LastType = "grid";
                            }
                            else
                            {
                                m_MapWin.UIPanel.SetPanelVisible("Identifier", true);
                            }

                            m_GridPropfrm.Hide();
                        }
                    }
                    // else Normal identifier with a separate window
                }
            }
            catch (System.Exception ex)
            {
                ShowErrorBox("LoadLayer()", ex.Message);
            }
        }
Ejemplo n.º 7
0
        public void LoadLayerAlternate(MapWindow.Interfaces.eLayerType LayerType, string layerName)
        {
            try
            {
                //exit if their is no layers to load
                if (m_MapWin.Layers.NumLayers <= 0)
                {
                    return;
                }

                // Always try to create the panel; if it doesn't exist,
                // it will be created, and if it does exist, a handle will be returned.
                m_UIPanel = m_MapWin.UIPanel.CreatePanel("Identifier", DockStyle.None);
                // Not intuitive -- m_UIPanel = m_MapWin.UIPanel.CreatePanel("Identifier", MapWindow.Interfaces.MapWindowDockStyle.RightAutoHide);
                if (m_UIPanel != null)
                {
                    m_MapWin.UIPanel.AddOnCloseHandler("Identifier", OnPanelClose);
                    m_HavePanel = true;
                }

                //if the layer is a shapefile
                if (LayerType == MapWindow.Interfaces.eLayerType.LineShapefile ||
                    LayerType == MapWindow.Interfaces.eLayerType.PointShapefile ||
                    LayerType == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                {
                    if (m_GridPropfrm.Visible)
                    {
                        m_GridPropfrm.Hide();
                    }
                }
                //if the layer is a grid
                else if (LayerType == MapWindow.Interfaces.eLayerType.Grid)
                {
                    if (m_shpFilePropfrm.Visible)
                    {
                        m_shpFilePropfrm.Hide();
                        m_WMSPropfrm.Hide();
                    }
                }
                //if the layer is a image
                else if (LayerType == MapWindow.Interfaces.eLayerType.Image)
                {
                    if (m_shpFilePropfrm.Visible)
                    {
                        m_shpFilePropfrm.Hide();
                        m_WMSPropfrm.Hide();
                    }
                }

                if (m_HavePanel && m_UIPanel != null)
                {
                    //if the layer is a shapefile
                    if (LayerType == MapWindow.Interfaces.eLayerType.LineShapefile ||
                        LayerType == MapWindow.Interfaces.eLayerType.PointShapefile ||
                        LayerType == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                    {
                        if (m_shpFilePropfrm.panel1 == null || m_shpFilePropfrm.panel1.IsDisposed)
                        {
                            m_shpFilePropfrm = new mwIdentifier.Forms.frmShapeFileProp(this);
                        }

                        if (m_UIPanel_LastType != "shapefile" && m_UIPanel_LastType != "")
                        {
                            while (m_UIPanel.Controls.Count > 0)
                            {
                                m_UIPanel.Controls.RemoveAt(0);
                            }
                        }

                        if (m_UIPanel.Controls.Count == 0)
                        {
                            m_UIPanel.Controls.Add(m_shpFilePropfrm.panel1);
                            m_UIPanel_LastType = "shapefile";
                        }
                        else
                        {
                            m_MapWin.UIPanel.SetPanelVisible("Identifier", true);
                        }

                        m_shpFilePropfrm.Hide();
                    }
                    //if the layer is a grid or image
                    else if (LayerType == MapWindow.Interfaces.eLayerType.Grid || LayerType == MapWindow.Interfaces.eLayerType.Image)
                    {
                        if (m_GridPropfrm.panel1 == null || m_GridPropfrm.panel1.IsDisposed)
                        {
                            m_GridPropfrm = new mwIdentifier.Forms.frmGridProp(this);
                        }

                        if (m_UIPanel_LastType != "grid" && m_UIPanel_LastType != "")
                        {
                            while (m_UIPanel.Controls.Count > 0)
                            {
                                m_UIPanel.Controls.RemoveAt(0);
                            }
                        }

                        if (m_UIPanel.Controls.Count == 0)
                        {
                            m_UIPanel.Controls.Add(m_GridPropfrm.panel1);
                            m_UIPanel_LastType = "grid";
                        }
                        else
                        {
                            m_MapWin.UIPanel.SetPanelVisible("Identifier", true);
                        }

                        m_GridPropfrm.Hide();
                    }
                }
                // else Normal identifier with a separate window
            }
            catch (System.Exception ex)
            {
                ShowErrorBox("LoadLayer()", ex.Message);
            }
        }
Ejemplo n.º 8
0
        public void MapMouseUp(int Button, int Shift, int x, int y, ref bool Handled)
        {
            try
            {
                if (Activated)
                {
                    m_MouseDown = false;

                    //exit if their is no layers
                    if (m_MapWin.Layers.NumLayers <= 0)
                    {
                        return;
                    }

                    //if a wms layer is selected and visible, broadcast so position can be checked
                    if (m_OnWMSLayer)
                    {
                        if (m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Visible)
                        {
                            m_MapWin.Plugins.BroadcastMessage("Identifier_Clicked_WMS " + x.ToString() + " " + y.ToString());
                        }
                        else
                        {
                            m_WMSLayerIDReturn = "Error: WMS Data Not Visible. Try Zooming In.";
                            LoadLayer();
                        }
                    }
                    else //Go about the normal selection
                    {
                        MapWinGIS.Extents BoundBox;
                        object            selShapes = new object();
                        double            tolx1 = 0, toly1 = 0, tolx2 = 0, toly2 = 0, tol = 0;
                        object            obj       = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].GetObject();
                        string            layerName = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Name;
                        MapWindow.Interfaces.eLayerType LayerType = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].LayerType;

                        //get the selected region
                        BoundBox = GetBoundBox(m_Bounds);

                        //if layer is a shapefile then do the following
                        if (LayerType == MapWindow.Interfaces.eLayerType.LineShapefile ||
                            LayerType == MapWindow.Interfaces.eLayerType.PointShapefile ||
                            LayerType == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                        {
                            if (m_GridPropfrm.Visible)
                            {
                                m_GridPropfrm.Hide();
                            }

                            Shapefile shpFile = (Shapefile)obj;

                            //clear all the selected shapes
                            m_MapWin.View.SelectedShapes.ClearSelectedShapes();

                            //calculate tolerance
                            double r;
                            if (m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].PointType == MapWinGIS.tkPointType.ptUserDefined)
                            {
                                MapWinGIS.Image image = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].UserPointType;
                                r = (image.Width + image.Height) / 2;
                            }
                            else
                            {
                                r = 3;
                            }

                            m_MapWin.View.PixelToProj(x - r, y - r, ref tolx1, ref toly1);
                            m_MapWin.View.PixelToProj(x + r, y + r, ref tolx2, ref toly2);
                            tol = System.Math.Sqrt(System.Math.Pow((tolx1 - tolx2), 2) + System.Math.Pow((toly1 - toly2), 2));

                            bool SelectedShapes = shpFile.SelectShapes(BoundBox, tol, MapWinGIS.SelectMode.INTERSECTION, ref selShapes);

                            //display the selected shapes
                            if (SelectedShapes)
                            {
                                AddSelectShapes(selShapes);
                                m_shpFilePropfrm.PopulateForm(!m_HavePanel, shpFile, (int[])selShapes, m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Name, false);
                            }
                            else
                            {
                                m_shpFilePropfrm.PopulateForm(!m_HavePanel, shpFile, m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Name, false);
                            }
                        }
                        //if the layer is a grid do the following
                        else if (LayerType == MapWindow.Interfaces.eLayerType.Grid)
                        {
                            if (m_shpFilePropfrm.Visible)
                            {
                                m_WMSPropfrm.Hide();
                                m_shpFilePropfrm.Hide();
                            }

                            //get the grid object
                            Grid grid = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].GetGridObject;

                            if (grid != null)
                            {
                                m_GridPropfrm.PopulateForm(!m_HavePanel, grid, layerName, BoundBox, m_MapWin.Layers.CurrentLayer);
                            }
                            else
                            {
                                m_GridPropfrm.Hide();
                            }
                        }
                        //if the layer is a image do the following
                        else if (LayerType == MapWindow.Interfaces.eLayerType.Image)
                        {
                            if (m_shpFilePropfrm.Visible)
                            {
                                m_WMSPropfrm.Hide();
                                m_shpFilePropfrm.Hide();
                            }

                            Grid grid = FindAssociatedGrid(((MapWinGIS.Image)obj).Filename);

                            if (grid != null)
                            {
                                m_GridPropfrm.PopulateForm(!m_HavePanel, grid, layerName, BoundBox, m_MapWin.Layers.CurrentLayer);
                            }
                            else
                            {
                                // Identify by values -- so just open the first band of the image.
                                // This only works for greyscale of course in this version (one band grids only)

                                Grid tmpGrid = new Grid();
                                try
                                {
                                    // Open as a grid to get values
                                    if (tmpGrid.Open(((MapWinGIS.Image)obj).Filename, GridDataType.UnknownDataType, false, GridFileType.UseExtension, null))
                                    {
                                        m_GridPropfrm.PopulateForm(!m_HavePanel, tmpGrid, layerName, BoundBox, m_MapWin.Layers.CurrentLayer);
                                    }
                                    else
                                    {
                                        MapWinUtility.Logger.Message("No information on this image can be displayed.", "Identifier", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information, DialogResult.OK);
                                        m_GridPropfrm.Hide();
                                    }
                                }
                                catch
                                {
                                    m_GridPropfrm.Hide();
                                }
                            }
                        }
                    }

                    //set handled
                    Handled = true;
                }
            }
            catch (System.Exception ex)
            {
                ShowErrorBox("MapMouseUp()", ex.Message);
            }
        }
Ejemplo n.º 9
0
        private void cmdIdentify_Click(object sender, EventArgs e)
        {
            if (m_MapWin.View.SelectedShapes.NumSelected == 0)
            {
                MapWinUtility.Logger.Msg(resMan.GetString("msgZeroShapesSelected.Text"), resMan.GetString("titleSelectShapes.Text"));
                return;
            }

            if (cmbIdentFrom.SelectedIndex == -1)
            {
                MapWinUtility.Logger.Msg(resMan.GetString("msgIdentFromNotSelected.Text"), resMan.GetString("titleSpecifyLayer.Text"));
                return;
            }

            if (cmbIdentWith.SelectedIndex == -1)
            {
                MapWinUtility.Logger.Msg(resMan.GetString("msgIdentWithNotSelected.Text"), resMan.GetString("titleSpecifyLayer.Text"));
                return;
            }
            if (m_MapWin.View.SelectedShapes.NumSelected == 0)
            {
                return;
            }

            // If it's a polygon layer we're identifying, call SelectByPolygon
            // If it's a grid, extract by mask
            // ...then, open that temporary file (not Add to Map, just "Open"), and summarize all data within that
            // file.
            int fromLayerHandle = -1;
            int maskLayerHandle = -1;

            if (cmbIdentFrom.SelectedIndex != -1)
            {
                string s = cmbIdentFrom.Items[cmbIdentFrom.SelectedIndex].ToString();
                if (s.Contains(")"))
                {
                    s = s.Substring(0, s.IndexOf(")"));
                }
                s = s.Replace("(", "");
                if (!int.TryParse(s, out fromLayerHandle))
                {
                    return;
                }

                if (fromLayerHandle == -1)
                {
                    return;
                }
            }
            if (cmbIdentWith.SelectedIndex != -1)
            {
                string s = cmbIdentWith.Items[cmbIdentWith.SelectedIndex].ToString();
                if (s.Contains(")"))
                {
                    s = s.Substring(0, s.IndexOf(")"));
                }
                s = s.Replace("(", "");
                if (!int.TryParse(s, out maskLayerHandle))
                {
                    return;
                }

                if (maskLayerHandle == -1)
                {
                    return;
                }
            }

            string TempPath = System.IO.Path.GetTempFileName();

            System.IO.File.Delete(TempPath);

            MapWinGIS.Shape     IdentifyBy;
            MapWinGIS.Shapefile sf = (MapWinGIS.Shapefile)m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].GetObject();

            if (m_MapWin.View.SelectedShapes.NumSelected > 1)
            {
                // Get 0 and 1 first to initialize IdentifyBy
                MapWinGIS.Shape shp1 = sf.get_Shape(m_MapWin.View.SelectedShapes[0].ShapeIndex);
                MapWinGIS.Shape shp2 = sf.get_Shape(m_MapWin.View.SelectedShapes[1].ShapeIndex);
                MapWinGeoProc.SpatialOperations.MergeShapes(ref shp1, ref shp2, out IdentifyBy);
                // ...now, the rest
                if (m_MapWin.View.SelectedShapes.NumSelected > 2)
                {
                    for (int i = 2; i < m_MapWin.View.SelectedShapes.NumSelected; i++)
                    {
                        MapWinGIS.Shape tmpResultShp;
                        MapWinGIS.Shape shp3 = sf.get_Shape(m_MapWin.View.SelectedShapes[i].ShapeIndex);
                        MapWinGeoProc.SpatialOperations.MergeShapes(ref IdentifyBy, ref shp3, out tmpResultShp);
                        IdentifyBy   = tmpResultShp;
                        tmpResultShp = null;
                    }
                }
                // Ready to identify based on a single shape now regardless of multiple selected
            }
            else
            {
                IdentifyBy = sf.get_Shape(m_MapWin.View.SelectedShapes[0].ShapeIndex);
            }

            MapWindow.Interfaces.eLayerType layerType = m_MapWin.Layers[fromLayerHandle].LayerType;
            if (layerType == MapWindow.Interfaces.eLayerType.Grid)
            {
                // Grid
                TempPath = System.IO.Path.ChangeExtension(TempPath, ".bgd");
                string fn = m_MapWin.Layers[fromLayerHandle].FileName;
                MapWinGeoProc.SpatialOperations.ClipGridWithPolygon(ref fn, ref IdentifyBy, ref TempPath, chbJustToExtents.Checked);
                MapWinGIS.Grid grd = new MapWinGIS.Grid();
                grd.Open(TempPath, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, null);
                if (grd == null || grd.Header == null)
                {
                    MapWinUtility.Logger.Msg(resMan.GetString("msgNoGridValues.Text"), resMan.GetString("titleNoGridValues.Text"));
                    return;
                }
                m_Plugin.ActivateNoLoad();
                m_Plugin.LoadLayerAlternate(layerType, m_MapWin.Layers[fromLayerHandle].Name);

                MapWinGIS.Extents exts = new MapWinGIS.Extents();
                exts.SetBounds(grd.Header.XllCenter, grd.Header.YllCenter + grd.Header.NumberRows * grd.Header.dY, 0, grd.Header.XllCenter + grd.Header.NumberCols * grd.Header.dX, grd.Header.YllCenter, 0);
                m_MapWin.Layers.CurrentLayer = fromLayerHandle;

                m_Plugin.m_GridPropfrm.PopulateForm(!m_Plugin.m_HavePanel, grd, m_MapWin.Layers[fromLayerHandle].Name, exts, fromLayerHandle);
                this.Close();
            }
            else
            {
                // SF
                if (!chbJustToExtents.Checked)
                {
                    string fn = m_MapWin.Layers[fromLayerHandle].FileName;

                    // 2/14/2008 jk the results ArrayList cannot be null,
                    // when it was null it caused an exception in SpatialOperations.SelectWithPolygon method
                    //System.Collections.ArrayList results = null;
                    System.Collections.ArrayList results = new System.Collections.ArrayList();

                    MapWinGeoProc.SpatialOperations.SelectWithPolygon(ref fn, ref IdentifyBy, ref results);

                    // Switch current layer over to the one we're identifying so that the shapes
                    // can be reselected for visual effect
                    m_MapWin.Layers.CurrentLayer = fromLayerHandle;
                    m_Plugin.ActivateNoLoad();
                    m_Plugin.LoadLayerAlternate(layerType, m_MapWin.Layers[fromLayerHandle].Name);

                    int[] iresults = new int[results.Count];
                    for (int i = 0; i < results.Count; i++)
                    {
                        iresults[i] = (int)results[i];
                        m_MapWin.View.SelectedShapes.AddByIndex((int)results[i], m_MapWin.View.SelectColor);
                    }

                    m_Plugin.m_shpFilePropfrm.PopulateForm(!m_Plugin.m_HavePanel, (MapWinGIS.Shapefile)m_MapWin.Layers[fromLayerHandle].GetObject(), iresults, m_MapWin.Layers[fromLayerHandle].Name, false);

                    this.Close();
                }
                else
                {
                    object rslt = null;
                    m_MapWin.Layers.CurrentLayer = fromLayerHandle;
                    MapWinGIS.Shapefile DestSF = (MapWinGIS.Shapefile)m_MapWin.Layers[fromLayerHandle].GetObject();

                    DestSF.SelectShapes(IdentifyBy.Extents, 0.1, MapWinGIS.SelectMode.INTERSECTION, ref rslt);

                    m_Plugin.ActivateNoLoad();
                    m_Plugin.LoadLayerAlternate(layerType, m_MapWin.Layers[fromLayerHandle].Name);

                    int[] results = (int[])rslt;
                    for (int i = 0; i < results.Length; i++)
                    {
                        m_MapWin.View.SelectedShapes.AddByIndex((int)results[i], m_MapWin.View.SelectColor);
                    }

                    m_Plugin.m_shpFilePropfrm.PopulateForm(!m_Plugin.m_HavePanel, DestSF, results, m_MapWin.Layers[fromLayerHandle].Name, false);

                    this.Close();
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Enables or disables toolbar buttons and menu items depending on the state of the MapWindow.
        /// </summary>
        public void DoEnables()
        {
            MapWin.Toolbar.ButtonItem(c_NewButton).Enabled = true;

            if ((MapWin == null) || (MapWin.Layers == null) || (MapWin.Layers.NumLayers == 0 || MapWin.Layers[MapWin.Layers.CurrentLayer].LayerType == MapWindow.Interfaces.eLayerType.Grid ||
                                                                MapWin.Layers[MapWin.Layers.CurrentLayer].LayerType == MapWindow.Interfaces.eLayerType.Image ||
                                                                MapWin.Layers[MapWin.Layers.CurrentLayer].LayerType == MapWindow.Interfaces.eLayerType.Invalid))
            {
                MapWin.Toolbar.ButtonItem(c_AddShapeButton).Enabled         = false;
                MapWin.Toolbar.ButtonItem(c_MoveShapesButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_AddVertexButton).Enabled        = false;
                MapWin.Toolbar.ButtonItem(c_MoveVertexButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_RemoveShapeButton).Enabled      = false;
                MapWin.Toolbar.ButtonItem(c_RemoveVertexButton).Enabled     = false;
                MapWin.Toolbar.ButtonItem(c_RotateShapeButton).Enabled      = false;
                MapWin.Toolbar.ButtonItem(c_ResizeShapeButton).Enabled      = false;
                MapWin.Toolbar.ButtonItem(c_InsertStockShapeButton).Enabled = false;
                MapWin.Toolbar.ButtonItem(c_CopyShapeButton).Enabled        = false;
                MapWin.Toolbar.ButtonItem(c_PasteShapeButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_UndoDisableButton).Enabled      = false;
                MapWin.Toolbar.ButtonItem(c_UndoEnableButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_UndoLastChangeButton).Enabled   = false;
                MapWin.Toolbar.ButtonItem(c_CleanupButton).Enabled          = false;
                //ARA 04/03/07
                MapWin.Toolbar.ButtonItem(c_MergeShapesButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_EraseWithShapeButton).Enabled    = false;
                MapWin.Toolbar.ButtonItem(c_EraseBeneathShapeButton).Enabled = false;

                return;
            }

            MapWindow.Interfaces.eLayerType lt = MapWin.Layers[MapWin.Layers.CurrentLayer].LayerType;
            if (lt == MapWindow.Interfaces.eLayerType.LineShapefile ||
                lt == MapWindow.Interfaces.eLayerType.PointShapefile ||
                lt == MapWindow.Interfaces.eLayerType.PolygonShapefile)
            {
                MapWin.Toolbar.ButtonItem(c_AddShapeButton).Enabled         = true;
                MapWin.Toolbar.ButtonItem(c_MoveShapesButton).Enabled       = true;
                MapWin.Toolbar.ButtonItem(c_MoveVertexButton).Enabled       = true;
                MapWin.Toolbar.ButtonItem(c_InsertStockShapeButton).Enabled = true;
                //ARA 04/03/07
                MapWin.Toolbar.ButtonItem(c_MergeShapesButton).Enabled = true;

                MapWin.Toolbar.ButtonItem(c_PasteShapeButton).Enabled = true;
                if (!MapWin.Toolbar.ButtonItem(c_UndoEnableButton).Enabled&& !MapWin.Toolbar.ButtonItem(c_UndoDisableButton).Enabled)
                {
                    MapWin.Toolbar.ButtonItem(c_UndoEnableButton).Enabled = true;
                }
                MapWin.Toolbar.ButtonItem(c_CleanupButton).Enabled = true;

                if (lt != MapWindow.Interfaces.eLayerType.PointShapefile)
                {
                    MapWin.Toolbar.ButtonItem(c_AddVertexButton).Enabled    = true;
                    MapWin.Toolbar.ButtonItem(c_RemoveVertexButton).Enabled = true;
                }
                else
                {
                    MapWin.Toolbar.ButtonItem(c_AddVertexButton).Enabled    = false;
                    MapWin.Toolbar.ButtonItem(c_RemoveVertexButton).Enabled = false;
                }

                // Chris Michaelis 12/28/2006
                // Resize and Rotate button only valid for polygons
                // Predefined shapes button only valid for polygons
                if (lt == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                {
                    MapWin.Toolbar.ButtonItem(c_RotateShapeButton).Enabled      = true;
                    MapWin.Toolbar.ButtonItem(c_ResizeShapeButton).Enabled      = true;
                    MapWin.Toolbar.ButtonItem(c_InsertStockShapeButton).Enabled = true;
                    //ARA 03/05/07
                    MapWin.Toolbar.ButtonItem(c_EraseWithShapeButton).Enabled    = true;
                    MapWin.Toolbar.ButtonItem(c_EraseBeneathShapeButton).Enabled = true;
                }
                else
                {
                    MapWin.Toolbar.ButtonItem(c_RotateShapeButton).Enabled       = false;
                    MapWin.Toolbar.ButtonItem(c_ResizeShapeButton).Enabled       = false;
                    MapWin.Toolbar.ButtonItem(c_InsertStockShapeButton).Enabled  = false;
                    MapWin.Toolbar.ButtonItem(c_EraseWithShapeButton).Enabled    = false;
                    MapWin.Toolbar.ButtonItem(c_EraseBeneathShapeButton).Enabled = false;
                }
            }
            else
            {
                MapWin.Toolbar.ButtonItem(c_AddShapeButton).Enabled         = false;
                MapWin.Toolbar.ButtonItem(c_MoveShapesButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_AddVertexButton).Enabled        = false;
                MapWin.Toolbar.ButtonItem(c_MoveVertexButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_RemoveShapeButton).Enabled      = false;
                MapWin.Toolbar.ButtonItem(c_RemoveVertexButton).Enabled     = false;
                MapWin.Toolbar.ButtonItem(c_RotateShapeButton).Enabled      = false;
                MapWin.Toolbar.ButtonItem(c_ResizeShapeButton).Enabled      = false;
                MapWin.Toolbar.ButtonItem(c_InsertStockShapeButton).Enabled = false;
                MapWin.Toolbar.ButtonItem(c_CopyShapeButton).Enabled        = false;
                MapWin.Toolbar.ButtonItem(c_PasteShapeButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_UndoDropdownButton).Enabled     = false;
                MapWin.Toolbar.ButtonItem(c_UndoDisableButton).Enabled      = false;
                MapWin.Toolbar.ButtonItem(c_UndoEnableButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_UndoLastChangeButton).Enabled   = false;
                MapWin.Toolbar.ButtonItem(c_CleanupButton).Enabled          = false;
                //ARA 04/03/07
                MapWin.Toolbar.ButtonItem(c_MergeShapesButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_EraseWithShapeButton).Enabled    = false;
                MapWin.Toolbar.ButtonItem(c_EraseBeneathShapeButton).Enabled = false;
            }

            if (MapWin.Layers[MapWin.Layers.CurrentLayer].Shapes.NumShapes == 0)
            {
                MapWin.Toolbar.ButtonItem(c_MoveShapesButton).Enabled   = false;
                MapWin.Toolbar.ButtonItem(c_RemoveShapeButton).Enabled  = false;
                MapWin.Toolbar.ButtonItem(c_RemoveVertexButton).Enabled = false;
                MapWin.Toolbar.ButtonItem(c_MoveVertexButton).Enabled   = false;
                MapWin.Toolbar.ButtonItem(c_AddVertexButton).Enabled    = false;
                MapWin.Toolbar.ButtonItem(c_RotateShapeButton).Enabled  = false;
                MapWin.Toolbar.ButtonItem(c_ResizeShapeButton).Enabled  = false;
                //ARA 04/03/07
                MapWin.Toolbar.ButtonItem(c_MergeShapesButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_EraseWithShapeButton).Enabled    = false;
                MapWin.Toolbar.ButtonItem(c_EraseBeneathShapeButton).Enabled = false;

                MapWin.Toolbar.ButtonItem(c_CopyShapeButton).Enabled = false;
            }

            // Chris Michaelis 12/9/2006 -- Added code to enable or disable
            // the Move Shapes button depending on selected shape count.
            if (MapWin.View.SelectedShapes.NumSelected > 0)
            {
                MapWin.Toolbar.ButtonItem(c_RemoveShapeButton).Enabled = true;
                MapWin.Toolbar.ButtonItem(c_MoveShapesButton).Enabled  = true;
                MapWin.Toolbar.ButtonItem(c_CopyShapeButton).Enabled   = true;

                // Chris Michaelis 12/28/2006
                // Resize and Rotate button only valid for polygons
                if (lt == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                {
                    MapWin.Toolbar.ButtonItem(c_RotateShapeButton).Enabled = true;
                    MapWin.Toolbar.ButtonItem(c_ResizeShapeButton).Enabled = true;

                    //Erase only valid with single selected shape
                    if (MapWin.View.SelectedShapes.NumSelected > 1)
                    {
                        MapWin.Toolbar.ButtonItem(c_EraseWithShapeButton).Enabled    = false;
                        MapWin.Toolbar.ButtonItem(c_EraseBeneathShapeButton).Enabled = false;
                    }
                    else
                    {
                        MapWin.Toolbar.ButtonItem(c_EraseWithShapeButton).Enabled    = true;
                        MapWin.Toolbar.ButtonItem(c_EraseBeneathShapeButton).Enabled = true;
                    }
                }
            }
            else
            {
                MapWin.Toolbar.ButtonItem(c_CopyShapeButton).Enabled         = false;
                MapWin.Toolbar.ButtonItem(c_RemoveShapeButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_MoveShapesButton).Enabled        = false;
                MapWin.Toolbar.ButtonItem(c_RotateShapeButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_ResizeShapeButton).Enabled       = false;
                MapWin.Toolbar.ButtonItem(c_EraseWithShapeButton).Enabled    = false;
                MapWin.Toolbar.ButtonItem(c_EraseBeneathShapeButton).Enabled = false;
            }
        }