Exemplo n.º 1
0
        private void MarkAllVertices(double curX, double curY)
        {
            try
            {
                int handle;

                if (m_globals.CurrentLayer == null)
                {
                    return;
                }
                handle = m_MapWin.Layers.CurrentLayer;
                MapWinGIS.Shapefile shpFile = m_globals.CurrentLayer;
                int numShp = shpFile.NumShapes;
                int shpIndex;

                if (m_prevShape != -1)
                {
                    if (!m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].VerticesVisible)
                    {
                        m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].HideVertices();
                    }
                }

                if (m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].LayerType == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                {
                    shpFile.BeginPointInShapefile();
                    shpIndex = shpFile.PointInShapefile(curX, curY);
                    shpFile.EndPointInShapefile();
                }
                else
                {
                    MapWinGIS.Extents bounds = new MapWinGIS.ExtentsClass();
                    bounds.SetBounds(curX, curY, 0, curX, curY, 0);
                    object resArray = null;
                    if (shpFile.SelectShapes(bounds, m_globals.CurrentTolerance * 2, MapWinGIS.SelectMode.INTERSECTION, ref resArray))
                    {
                        shpIndex = (int)((System.Array)resArray).GetValue(0);
                    }
                    else
                    {
                        shpIndex = -1;
                    }
                }

                if (shpIndex >= 0)
                {
                    m_MapWin.Layers[handle].Shapes[shpIndex].ShowVertices(System.Drawing.Color.Red, m_globals.VertexSize);
                    m_prevShape = shpIndex;
                }
                else
                {
                    m_prevShape = -1;
                }
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }
        }
Exemplo n.º 2
0
        private void SelectExtents(MapWinGIS.Extents ext)
        {
            object[] Shapes = new object[m_Map.NumLayers];
            if (m_CurrentLayer == -1 || m_CurrentLayer >= m_Map.NumLayers)
            {
                for (int lyr = 0; lyr < m_Map.NumLayers; lyr++)
                {
                    object ob = m_Map.get_GetObject(lyr);
                    if (ob.GetType() != typeof(MapWinGIS.Shapefile))
                    {
                        return;
                    }
                    MapWinGIS.Shapefile sf = ob as MapWinGIS.Shapefile;
                    sf.SelectShapes(ext, 0, MapWinGIS.SelectMode.INTERSECTION, ref Shapes[m_CurrentLayer]);
                }
            }
            else
            {
                object ob = m_Map.get_GetObject(m_CurrentLayer);
                if (ob.GetType() != typeof(MapWinGIS.Shapefile))
                {
                    return;
                }
                MapWinGIS.Shapefile sf = ob as MapWinGIS.Shapefile;
                sf.SelectShapes(ext, 0, MapWinGIS.SelectMode.INTERSECTION, ref Shapes[m_CurrentLayer]);
            }

            m_Map.SuspendLayout();
            // If shift is down then we append to the selection
            if (m_ShiftPressed == false)
            {
                // Clear the selection first

                ClearSelectedShapes();
            }

            //Append selected shapes
            for (int lyr = 0; lyr < m_Map.NumLayers; lyr++)
            {
                int[] myShapes = Shapes[lyr] as int[];
                for (int shp = 0; shp <= myShapes.GetUpperBound(0); shp++)
                {
                    if (m_SelectedShapes[lyr].Contains(myShapes[shp]))
                    {
                        continue;
                    }
                    m_SelectedShapes[lyr].Add(myShapes[shp]);
                }
            }

            for (int lyr = 0; lyr < m_SelectedShapes.GetUpperBound(0); lyr++)
            {
                Highlight_Layer(lyr);
            }

            m_Map.ResumeLayout();
        }
Exemplo n.º 3
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();
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据给定的shapefile、范围、容差来将选择的shape存入shapeInfo集合中
        /// </summary>
        internal MapWinGIS.Interfaces.SelectInfo PerformSelection(MapWinGIS.Shapefile sf, MapWinGIS.Extents bounds, double tolerance)
        {
            SelectInfo m_SelectedShapes = new SelectInfo(this.LegendControl.SelectedLayer);

            if (m_SelectedShapes == null)
            {
                m_SelectedShapes = new MainProgram.SelectInfo(this.LegendControl.SelectedLayer);
            }
            m_SelectedShapes.ClearSelectedShapesTemp();

            object arr = null;

            System.Array results = null;
            if (sf.SelectShapes(bounds, tolerance, m_Selectmethod, ref arr))
            {
                results = (System.Array)arr;
            }

            if (m_SelectionOperation == Interfaces.SelectionOperation.SelectNew)
            {
                sf.SelectNone();
            }

            int i;

            //设置选择的shape
            if (results != null && results.Length > 0)
            {
                int len = results.Length;

                if (m_SelectionOperation == Interfaces.SelectionOperation.SelectNew)
                {
                    for (i = 0; i < len; i++)
                    {
                        sf.ShapeSelected[((int)results.GetValue(i))] = true;
                    }
                }
                else if (m_SelectionOperation == Interfaces.SelectionOperation.SelectAdd)
                {
                    for (i = 0; i < len; i++)
                    {
                        sf.ShapeSelected[((int)results.GetValue(i))] = true;
                    }
                }
                else if (m_SelectionOperation == Interfaces.SelectionOperation.SelectExclude)
                {
                    for (i = 0; i < len; i++)
                    {
                        sf.ShapeSelected[((int)results.GetValue(i))] = false;
                    }
                }
                else if (m_SelectionOperation == Interfaces.SelectionOperation.SelectInvert)
                {
                    for (i = 0; i < len; i++)
                    {
                        sf.ShapeSelected[((int)results.GetValue(i))] = !sf.ShapeSelected[((int)results.GetValue(i))];
                    }
                }
            }
            else
            {
                if (m_SelectionOperation == Interfaces.SelectionOperation.SelectNew)
                {
                    sf.SelectNone();
                }
            }

            // 将选择的shape添加到shapeInfo集合中
            for (i = 0; i < sf.NumShapes; i++)
            {
                if (sf.ShapeSelected[i])
                {
                    SelectedShape shape = new SelectedShape();
                    shape.Add(i);
                    m_SelectedShapes.AddSelectedShape(shape);
                }
            }

            m_selection = null;

            this.Redraw();
            return(m_SelectedShapes);
        }