/// <summary> /// 在指定的层上更新选择的shapes /// 别的层上的选择将保持 /// </summary> /// <param name="sf">要更新的Shapefile</param> /// <param name="shpIndices">所有相关的Shape的索引集合</param> /// <param name="mode">选择操作</param> /// <returns></returns> public MapWinGIS.Interfaces.SelectInfo UpdateSelection(int layerHandle, ref int[] shpIndices, Interfaces.SelectionOperation mode) { //清空原来存储的 m_selection = null; Interfaces.Layer layer = Program.frmMain.m_Layers[layerHandle]; if (layer == null) { return(null); } MapWinGIS.Shapefile sf = layer.GetObject() as MapWinGIS.Shapefile; if (sf == null) { return(null); } if (mode == Interfaces.SelectionOperation.SelectNew) { sf.SelectNone(); } if (shpIndices != null && shpIndices.Length > 0) { int i; int shpIndicesLen = shpIndices.Length; if (mode == Interfaces.SelectionOperation.SelectNew) { for (i = 0; i < shpIndicesLen; i++) { sf.ShapeSelected[shpIndices[i]] = true; } } else if (mode == Interfaces.SelectionOperation.SelectAdd) { for (i = 0; i < shpIndicesLen; i++) { sf.ShapeSelected[shpIndices[i]] = true; } } else if (mode == Interfaces.SelectionOperation.SelectExclude) { for (i = 0; i < shpIndicesLen; i++) { sf.ShapeSelected[shpIndices[i]] = false; } } else if (mode == Interfaces.SelectionOperation.SelectInvert) { for (i = 0; i < shpIndicesLen; i++) { sf.ShapeSelected[shpIndices[i]] = !sf.ShapeSelected[shpIndices[i]]; } } } Program.frmMain.UpdateButtons(); bool handled = false; Program.frmMain.FireLayerSelectionChanged(layerHandle, ref handled); return(layer.SelectedShapes); }
/// <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); }