public static void SelectObjsByShape(IMap pMap, IGeometry Geo, bool justOnce) { if (Geo.GeometryType == esriGeometryType.esriGeometryPoint) { IPoint point = (IPoint)Geo; double num = ((IActiveView)pMap).Extent.Width / 200.0; double num2 = point.X - num; double num3 = point.Y - num; double num4 = point.X + num; double num5 = point.Y + num; IEnvelope envelope = new Envelope() as IEnvelope; envelope.PutCoords(num2, num3, num4, num5); pMap.ClearSelection(); pMap.SelectByShape(envelope, new SelectionEnvironment(), justOnce); } else if (Geo.GeometryType == esriGeometryType.esriGeometryPolyline) { IPolyline polyline = (IPolyline)Geo; ISelectionEnvironment selectionEnvironment = new SelectionEnvironment(); pMap.SelectByShape(polyline, selectionEnvironment, justOnce); } if (pMap.SelectionCount > 0) { ((IActiveView)pMap).Refresh(); } }
private static void ExtractSpecifyRegFeatures(IWorkspaceName iworkspaceName_0, IMap imap_0, IGeometry igeometry_0) { ISelectionEnvironment selectionEnvironment = new SelectionEnvironment(); selectionEnvironment.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; try { imap_0.SelectByShape(igeometry_0, selectionEnvironment, false); } catch (COMException ex) { if (ex.ErrorCode == -2147467259) { System.Windows.Forms.MessageBox.Show("执行查询时产生错误。空间索引不存在", "选择"); } } catch (Exception) { } IWorkspace workspace = (iworkspaceName_0 as IName).Open() as IWorkspace; for (int i = 0; i < imap_0.LayerCount; i++) { ILayer layer = imap_0.get_Layer(i); if (layer is IFeatureLayer) { ClipHelper.ExtractSelectFeatureFormLayer((IFeatureLayer)layer, (IFeatureWorkspace)workspace, igeometry_0); } } }
private void StartAnalysis(int num, int num2) { IMap map = this._context.FocusMap; IEnvelope envelope = new Envelope() as IEnvelope; IPoint point = _context.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(num, num2); IActiveView activeView = (IActiveView)map; envelope.PutCoords(point.X, point.Y, point.X, point.Y); double num3 = activeView.Extent.Width / 200.0; IEnvelope expr_67 = envelope; expr_67.XMin = (expr_67.XMin - num3); IEnvelope expr_76 = envelope; expr_76.YMin = (expr_76.YMin - num3); IEnvelope expr_85 = envelope; expr_85.YMax = (expr_85.YMax + num3); IEnvelope expr_94 = envelope; expr_94.XMax = (expr_94.XMax + num3); ISelectionEnvironment selectionEnvironment = new SelectionEnvironment(); map.SelectByShape(envelope, selectionEnvironment, true); activeView = (IActiveView)map; activeView.PartialRefresh((esriViewDrawPhase)4, null, null); }
public void UpdateFeature( IMap pMap ,ILayer pCurrentLayer,IPoint pPoint ) { //处理具体数据 if (pMap == null || pPoint == null ) return; m_pMap = pMap; //如果没有地图图层 ,则不处理 long nLayerCount = pMap.LayerCount; if( nLayerCount == 0 ) return; //删除树结点 FtTreeView.Nodes.Clear(); this.FTtreeList.Nodes.Clear(); //开始选择 IGeometry geom = pPoint; ISpatialReference spatialReference = m_pMap.SpatialReference; geom.SpatialReference = spatialReference; //Refresh the active view IActiveView activeView = (IActiveView)m_pMap; ISelectionEnvironment selEnv = new SelectionEnvironment(); selEnv.PointSelectionMethod = esriSpatialRelEnum.esriSpatialRelWithin; m_pMap.SelectByShape(geom, selEnv, false); activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, activeView.Extent); //如果没有设置 当前图层pCurrentLayer ,则不处理 ESRI.ArcGIS.esriSystem.IPersist pPersist = new FeatureLayer() as ESRI.ArcGIS.esriSystem.IPersist; UID uid = pPersist as UID ; IEnumLayer pEnumlayer = pMap.get_Layers(uid,true ); pEnumlayer.Reset(); ILayer pLayer = pEnumlayer.Next(); while( pLayer != null ) { if( pLayer.Visible == false ) { pLayer = pEnumlayer.Next(); continue; } IFeatureLayer2 pFtLayer = (IFeatureLayer2)pLayer; IFeatureSelection pFtSelect = (IFeatureSelection)pFtLayer; ISelectionSet pSelectset = (ISelectionSet)pFtSelect.SelectionSet; InitTreeView(pSelectset, pLayer); pLayer = pEnumlayer.Next(); } }
//高亮显示 private void HightRight(AxMapControl axMapControl, IGeometry Geometry) { IMap map = axMapControl.Map; ISelectionEnvironment SelectionEnvironment = new SelectionEnvironment(); IRgbColor color = new RgbColor(); color.Red = 233; SelectionEnvironment.DefaultColor = color; map.SelectByShape(Geometry, SelectionEnvironment, false); axMapControl.ActiveView.Refresh(); }
private void SelectByShape(IGeometry geometry, bool justOne = false) { IMap map = _context.FocusMap; IEnvelope envelope = geometry.Envelope; envelope.XMin = (envelope.XMin - _tolerance); envelope.YMin = (envelope.YMin - _tolerance); envelope.YMax = (envelope.YMax + _tolerance); envelope.XMax = (envelope.XMax + _tolerance); ISelectionEnvironment selectionEnvironment = new SelectionEnvironment(); map.SelectByShape(envelope, selectionEnvironment, justOne); _context.ActiveView.Refresh(); }
private void SelectByClick(int x, int y) { IMap map = _context.FocusMap; IEnvelope envelope = new Envelope() as IEnvelope; IPoint point = _context.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); envelope.PutCoords(point.X, point.Y, point.X, point.Y); envelope.XMin = (envelope.XMin - _tolerance); envelope.YMin = (envelope.YMin - _tolerance); envelope.YMax = (envelope.YMax + _tolerance); envelope.XMax = (envelope.XMax + _tolerance); ISelectionEnvironment selectionEnvironment = new SelectionEnvironment(); map.SelectByShape(envelope, selectionEnvironment, true); _context.ActiveView.Refresh(); }
private void SelectByShape(IGeometry geometry) { IMap map = _context.FocusMap; IEnvelope envelope = geometry.Envelope; IActiveView activeView = (IActiveView)map; double num3 = activeView.Extent.Width / 200.0; envelope.XMin = (envelope.XMin - 1); envelope.YMin = (envelope.YMin - 1); envelope.YMax = (envelope.YMax + 1); envelope.XMax = (envelope.XMax + 1); ISelectionEnvironment selectionEnvironment = new SelectionEnvironment(); selectionEnvironment.SearchTolerance = 1; map.SelectByShape(envelope, selectionEnvironment, false); _context.ActiveView.Refresh(); }
private void SelectByClick(int x, int y) { IMap map = _context.FocusMap; IEnvelope envelope = new Envelope() as IEnvelope; IPoint point = _context.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); IActiveView activeView = (IActiveView)map; envelope.PutCoords(point.X, point.Y, point.X, point.Y); double num3 = activeView.Extent.Width / 200.0; envelope.XMin = (envelope.XMin - num3); envelope.YMin = (envelope.YMin - num3); envelope.YMax = (envelope.YMax + num3); envelope.XMax = (envelope.XMax + num3); ISelectionEnvironment selectionEnvironment = new SelectionEnvironment(); map.SelectByShape(envelope, selectionEnvironment, true); }
private static void ExtractSpecifyRegFeatures(IWorkspaceName iworkspaceName_0, IMap imap_0, IGeometry igeometry_0) { ISelectionEnvironment selectionEnvironmentClass = new SelectionEnvironment() { CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew }; try { imap_0.SelectByShape(igeometry_0, selectionEnvironmentClass, false); } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (cOMException.ErrorCode != -2147467259) { Logger.Current.Error("", cOMException, ""); } else { MessageBox.Show("执行查询时产生错误。空间索引不存在", "选择"); } } catch (Exception exception) { Logger.Current.Error("", exception, ""); } IWorkspace workspace = (iworkspaceName_0 as IName).Open() as IWorkspace; for (int i = 0; i < imap_0.LayerCount; i++) { ILayer layer = imap_0.Layer[i]; if (layer is IFeatureLayer) { Clip.ExtractSelectFeatureFormLayer((IFeatureLayer)layer, (IFeatureWorkspace)workspace, igeometry_0); } } }
public void UpdateFeature(IMap pMap, ILayer pCurrentLayer, IPoint pPoint) { //处理具体数据 if (pMap == null || pPoint == null) { return; } m_pMap = pMap; //如果没有地图图层 ,则不处理 long nLayerCount = pMap.LayerCount; if (nLayerCount == 0) { return; } //删除树结点 FtTreeView.Nodes.Clear(); this.FTtreeList.Nodes.Clear(); //开始选择 IGeometry geom = pPoint; ISpatialReference spatialReference = m_pMap.SpatialReference; geom.SpatialReference = spatialReference; //Refresh the active view IActiveView activeView = (IActiveView)m_pMap; ISelectionEnvironment selEnv = new SelectionEnvironment(); selEnv.PointSelectionMethod = esriSpatialRelEnum.esriSpatialRelWithin; m_pMap.SelectByShape(geom, selEnv, false); activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, activeView.Extent); //如果没有设置 当前图层pCurrentLayer ,则不处理 ESRI.ArcGIS.esriSystem.IPersist pPersist = new FeatureLayer() as ESRI.ArcGIS.esriSystem.IPersist; UID uid = pPersist as UID; IEnumLayer pEnumlayer = pMap.get_Layers(uid, true); pEnumlayer.Reset(); ILayer pLayer = pEnumlayer.Next(); while (pLayer != null) { if (pLayer.Visible == false) { pLayer = pEnumlayer.Next(); continue; } IFeatureLayer2 pFtLayer = (IFeatureLayer2)pLayer; IFeatureSelection pFtSelect = (IFeatureSelection)pFtLayer; ISelectionSet pSelectset = (ISelectionSet)pFtSelect.SelectionSet; InitTreeView(pSelectset, pLayer); pLayer = pEnumlayer.Next(); } }
public EditorSettings() { SelectionEnvironment = new SelectionEnvironment(); }
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { //基本功能 if (e.button == 1) { this.axMapControl1.Extent = this.axMapControl1.TrackRectangle(); } else if (e.button == 2) { this.axMapControl1.Extent = this.axMapControl1.FullExtent; } else if (e.button == 4) { this.axMapControl1.Pan(); } switch (mTool) { case "Position": //获取当前视图 ESRI.ArcGIS.Carto.IActiveView pActiveView = this.axMapControl1.ActiveView; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; //获取鼠标点 ESRI.ArcGIS.Geometry.IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); IMap pMap = axMapControl1.Map; IGeometry pGeometry = null; //选择方法 switch (this.mQueryModel) { case 0: //矩形查询 pGeometry = this.axMapControl1.TrackRectangle(); break; case 1: //线查询 pGeometry = this.axMapControl1.TrackLine(); break; case 2: //点查询 ESRI.ArcGIS.Geometry.ITopologicalOperator pTopo; ESRI.ArcGIS.Geometry.IGeometry pBuffer; pGeometry = pPoint; pTopo = pGeometry as ESRI.ArcGIS.Geometry.ITopologicalOperator; //根据点位创建缓冲区,缓冲半径设为0.005,可自行修改 pBuffer = pTopo.Buffer(0.005); pGeometry = pBuffer.Envelope; break; case 3: //圆查询 pGeometry = this.axMapControl1.TrackCircle(); break; } ISelectionEnvironment pSelectionEnv = new SelectionEnvironment(); //新建选择环境 IRgbColor pColor = new RgbColor(); pColor.Red = 255; pSelectionEnv.DefaultColor = pColor; //设置高亮显示的颜色 pMap.SelectByShape(pGeometry, pSelectionEnv, false); //选择图形 axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); break; default: break; } }
//地图控件鼠标点击事件;; private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) { switch (index._tool_lable) { //漫游 case PublicMark.ButtonFunction.roam: axMapControl1.Pan(); break; // 测量 case PublicMark.ButtonFunction.measure: MessageBox.Show("测量功能尚未完善!"); break; //识别 case PublicMark.ButtonFunction.distinguish: if (e.button == 1) { IPoint pt = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); IGeometry Geometry = pt as IGeometry; IMap map = axMapControl1.Map; ISelectionEnvironment SelectionEnvironment = new SelectionEnvironment(); IRgbColor color = new RgbColor(); color.Red = 233; SelectionEnvironment.DefaultColor = color; map.SelectByShape(Geometry, SelectionEnvironment, false); axMapControl1.ActiveView.Refresh(); if (axMapControl1.Map.SelectionCount <= 0) { return; } Form distinguish = new Distinguish(CreateDataTable(axMapControl1)); //显示识别窗体,并把选择属性创建成表; distinguish.Location = Control.MousePosition; //;窗体位置 distinguish.ShowDialog(); } break; //按位置选择 case PublicMark.ButtonFunction.TrackCircle: HightRight(axMapControl1, axMapControl1.TrackCircle()); break; //按位置选择 case PublicMark.ButtonFunction.TrackLine: HightRight(axMapControl1, axMapControl1.TrackLine()); break; //按位置选择 case PublicMark.ButtonFunction.TrackRectangle: HightRight(axMapControl1, axMapControl1.TrackRectangle()); break; //按位置选择 case PublicMark.ButtonFunction.TrackPolygon: HightRight(axMapControl1, axMapControl1.TrackPolygon()); break; //局部放大功能; case PublicMark.ButtonFunction.enlarge: IEnvelope envelope = axMapControl1.TrackRectangle(); axMapControl1.ActiveView.Extent = envelope; axMapControl1.ActiveView.Refresh(); break; case PublicMark.ButtonFunction.narrow: IEnvelope envelope_1 = axMapControl1.TrackRectangle(); double dWidth = Math.Pow(axMapControl1.ActiveView.Extent.Width, 2) / envelope_1.Width; double dHeight = Math.Pow(axMapControl1.ActiveView.Extent.Height, 2) / envelope_1.Height; double dXmin = axMapControl1.ActiveView.Extent.XMin - ((envelope_1.XMin - axMapControl1.ActiveView.Extent.XMin) * axMapControl1.ActiveView.Extent.Width / envelope_1.Width); double dYmin = axMapControl1.ActiveView.Extent.YMin - ((envelope_1.YMin - axMapControl1.ActiveView.Extent.YMin) * axMapControl1.ActiveView.Extent.Height / envelope_1.Height); double dXMax = dWidth + dXmin; double dYMax = dHeight + dYmin; envelope_1.PutCoords(dXmin, dYmin, dXMax, dYMax); axMapControl1.Extent = envelope_1; axMapControl1.ActiveView.Refresh(); break; case PublicMark.ButtonFunction.DrawPoint: IPoint pIPoint = new PointClass(); pIPoint.X = e.mapX; pIPoint.Y = e.mapY; if (SelectLayer != null) { IFeatureLayer pIFeatureLayer = SelectLayer as IFeatureLayer; IFeatureClass pIFeatureClass = pIFeatureLayer.FeatureClass; IFeature pIFeature = pIFeatureClass.CreateFeature(); pIFeature.Shape = pIPoint as IGeometry; pIFeature.Store(); axMapControl1.Refresh(); } break; case HmMap.PublicMark.ButtonFunction.Drawpolyline: IGeometry pIGeometry = axMapControl1.TrackLine(); if (SelectLayer != null) { IFeatureLayer pIFeatureLayer = SelectLayer as IFeatureLayer; IFeatureClass pIFeatureClass = pIFeatureLayer.FeatureClass; IFeature pIFeature = pIFeatureClass.CreateFeature(); pIFeature.Shape = pIGeometry; pIFeature.Store(); axMapControl1.Refresh(); } break; case HmMap.PublicMark.ButtonFunction.DrawPolygon: IGeometry pIGeometr = axMapControl1.TrackPolygon(); if (SelectLayer != null) { IFeatureLayer pIFeatureLayer = SelectLayer as IFeatureLayer; IFeatureClass pIFeatureClass = pIFeatureLayer.FeatureClass; IFeature pIFeature = pIFeatureClass.CreateFeature(); pIFeature.Shape = pIGeometr; pIFeature.Store(); axMapControl1.Refresh(); } break; } }
private bool MapSpatialSelect(string sMinX, string sMinY, string sMaxX, string sMaxY) { IEnvelope pEnv; IMxDocument pDoc; IMap pMap; this.Logger.WriteLine("Map Spatial Select"); try { try { pDoc = GetDoc(); pMap = (IMap)pDoc.FocusMap; pEnv = new EnvelopeClass(); pEnv.PutCoords(System.Convert.ToDouble(sMinX), System.Convert.ToDouble(sMinY), System.Convert.ToDouble(sMaxX), System.Convert.ToDouble(sMaxY)); ISelectionEnvironment pSelEnv = new SelectionEnvironment(); pSelEnv.AreaSelectionMethod = esriSpatialRelEnum.esriSpatialRelIntersects; pSelEnv.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; SW1.Reset(); SW1.Start(); pMap.SelectByShape(pEnv, pSelEnv, false); SW1.Stop(); RecordActionTime("MapSpatialSelect Features (" + pMap.SelectionCount + ")", SW1.ElapsedMilliseconds); return true; } catch (Exception EX) { this.Logger.WriteLine("Failed to open Class:" + EX.Message); return false; } } catch (Exception EX) { this.Logger.WriteLine("Failed:" + EX.Message); return false; } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (m_hookHelper != null) { ClsMapLayer pConvert = new ClsMapLayer(); IGeometry pGeometry; IActiveView pActiveView = m_hookHelper.ActiveView; IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pGeometry = (IGeometry)pPoint; if (ClsDeclare.g_pMap.SelectionCount != 0) { ClsDeclare.g_pMap.ClearSelection(); } pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); ISelectionEnvironment pSelectEnv = new SelectionEnvironment(); double Length; Length = pConvert.ConvertPixelDistanceToMapDistance(pActiveView, pSelectEnv.SearchTolerance); ITopologicalOperator pTopoOpera; IGeometry pBuffer; pTopoOpera = (ITopologicalOperator)pGeometry; pBuffer = pTopoOpera.Buffer(Length); pGeometry = (IGeometry)m_pMapControl.TrackCircle(); Application.DoEvents(); m_pMapControl.MousePointer = esriControlsMousePointer.esriPointerHourglass; if (pGeometry != null) { if (pGeometry.Envelope.IsEmpty) { pGeometry = pBuffer.Envelope; } } esriSelectionResultEnum pselecttype = new esriSelectionResultEnum(); switch (Shift) { case 0: { pselecttype = esriSelectionResultEnum.esriSelectionResultNew; switch (mvarSelectMethod) { case "New": pselecttype = esriSelectionResultEnum.esriSelectionResultNew; break; case "Add": pselecttype = esriSelectionResultEnum.esriSelectionResultAnd; break; case "Sub": pselecttype = esriSelectionResultEnum.esriSelectionResultSubtract; break; case "Xor": pselecttype = esriSelectionResultEnum.esriSelectionResultXOR; break; } break; } case 1: pselecttype = esriSelectionResultEnum.esriSelectionResultAdd; break; case 2: pselecttype = esriSelectionResultEnum.esriSelectionResultXOR; break; case 3: pselecttype = esriSelectionResultEnum.esriSelectionResultNew; break; case 4: pselecttype = esriSelectionResultEnum.esriSelectionResultSubtract; break; } if (m_FeatClsCln == null) { bool blntemp = false; m_pQueryResultCln = new Collection(); ClsSelectQuery.SelectGeometry(ref blntemp, pGeometry, pselecttype, ref m_pQueryResultCln); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); if (m_frmQuery == null) { m_frmQuery = new FrmQuery(); } if (m_frmQuery.IsDisposed) { m_frmQuery = new FrmQuery(); } m_frmQuery.QueryResultCln = m_pQueryResultCln; m_frmQuery.ReLoadQueryResult(); m_frmQuery.Visible = false; m_frmQuery.Show((Form)(ClsDeclare.g_Sys.FrmMain)); } m_pQueryResultCln = null; m_pMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; } else if (m_sceneHookHelper != null) { } else if (m_globeHookHelper != null) { } }
public override void GetSelectedData() { this.method_3(); IMap map = this.m_context.FocusMap; ITopologicalOperator topologicalOperator = (ITopologicalOperator)this.m_pBaseLine; IGeometry geometry = topologicalOperator.Buffer(0.0); map.ClearSelection(); ISelectionEnvironment selectionEnvironment = new SelectionEnvironment(); map.SelectByShape(geometry, selectionEnvironment, false); IEnumFeature enumFeature = (IEnumFeature)map.FeatureSelection; IFeature feature = enumFeature.Next(); while (feature != null) { if (feature.FeatureType == esriFeatureType.esriFTSimpleEdge) { IPolyline egLine = feature.Shape as IPolyline; IPoint newCenter = new PointClass(); egLine.QueryPoint(esriSegmentExtension.esriNoExtension, 0.01, true, newCenter); IEdgeFeature pEgFeature = feature as IEdgeFeature; IFeatureClass pClass = feature.Class as IFeatureClass; INetworkClass pNetworkClass = pClass as INetworkClass; INetElements network = pNetworkClass.GeometricNetwork.Network as INetElements; IPointToEID pntEID = new PointToEIDClass(); pntEID.GeometricNetwork = pNetworkClass.GeometricNetwork; pntEID.SourceMap = m_context.FocusMap; pntEID.SnapTolerance = CommonHelper.ConvertPixelsToMapUnits(m_context.ActiveView, 5.0); double percent; int edgeID; IPoint location; pntEID.GetNearestEdge(newCenter, out edgeID, out location, out percent); if (percent == 0) { feature = enumFeature.Next(); continue; } int userClassID, userID, userSubID; network.QueryIDs(edgeID, esriElementType.esriETEdge, out userClassID, out userID, out userSubID); if (pClass.FeatureClassID == userClassID) { feature = pClass.GetFeature(userID); } else { IEnumDataset dses = pNetworkClass.FeatureDataset.Subsets; dses.Reset(); IDataset ds = dses.Next(); while (ds != null) { if (ds is IFeatureClass) { IFeatureClass pClass2 = ds as IFeatureClass; if (pClass2.FeatureClassID == userClassID) { feature = pClass2.GetFeature(userID); break; } } } } } string smpClassName = CommonUtils.GetSmpClassName(feature.Class.AliasName); IMAware mWAware = feature.Shape as IMAware; bool isMUsing = mWAware.MAware; IBasicLayerInfo lineConfig = PipeConfig.GetBasicLayerInfo(feature.Class.AliasName) as IBasicLayerInfo; if (lineConfig == null && !smpClassName.ToUpper().Contains("JT_JT_L") && !smpClassName.ToUpper().Contains("SY_ZX_L") && !smpClassName.ToUpper().Contains("ZB_LD_R")) { feature = enumFeature.Next(); } else { IGeometry shape = feature.Shape; if (shape.GeometryType != esriGeometryType.esriGeometryPolyline && shape.GeometryType != esriGeometryType.esriGeometryPolygon) { feature = enumFeature.Next(); } else { IPolyline polyline; if (shape.GeometryType == esriGeometryType.esriGeometryPolygon) { polyline = this.PolygonToPolyline((IPolygon)shape); } else { polyline = (IPolyline)shape; } GPoints gPoints = null; if (isMUsing) { gPoints = this.CalculateIntersections(this.m_pBaseLine, polyline); } else { gPoints = this.CalculateIntersections(this.m_pBaseLine, feature, lineConfig); } //string text = "管线性质"; string text = lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GDXZ); string bstrDatasetName = ""; int num = feature.Fields.FindField(text); if (num != -1) { object obj = feature.get_Value(num); if (obj == null || Convert.IsDBNull(obj)) { bstrDatasetName = ""; } else { bstrDatasetName = obj.ToString(); } } if (gPoints == null) { feature = enumFeature.Next(); } else { int num2 = gPoints.Size(); for (int i = 0; i < num2; i++) { GPoint gPoint = gPoints[i]; PipePoint pipePoint = new PipePoint(); if (smpClassName.ToUpper().Contains("JT_JT_L")) { pipePoint.PointType = PipePoint.SectionPointType.sptRoadBorder; } else if (smpClassName.ToUpper().Contains("SY_ZX_L")) { pipePoint.PointType = PipePoint.SectionPointType.sptMidRoadLine; } else if (smpClassName.ToUpper().Contains("ZB_LD_R")) { pipePoint.PointType = PipePoint.SectionPointType.sptMidGreen; } else { pipePoint.PointType = PipePoint.SectionPointType.sptPipe; } pipePoint.x = gPoint.X; pipePoint.y = gPoint.Y; pipePoint.z = gPoint.Z; pipePoint.m = gPoint.M; pipePoint.bstrDatasetName = bstrDatasetName; // int num3 = feature.Fields.FindField(base.PipeConfig.get_Material()); int num3 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GXCZ)); if (num3 == -1) { pipePoint.strMaterial = ""; } else { object obj2 = feature.get_Value(num3); if (obj2 != null) { pipePoint.strMaterial = feature.get_Value(num3).ToString(); } else { pipePoint.strMaterial = ""; } } // num3 = feature.Fields.FindField(base.PipeConfig.get_Diameter()); num3 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GJ)); string text2; if (num3 != -1 && feature.get_Value(num3) != null) { text2 = feature.get_Value(num3).ToString(); } else { text2 = ""; } num3 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.DMCC)); string text3; if (num3 != -1 && feature.get_Value(num3) != null) { text3 = feature.get_Value(num3).ToString(); } else { text3 = ""; } if (text2 != "") { pipePoint.strPipeWidthHeight = text2; } if (text3 != "") { pipePoint.strPipeWidthHeight = text3; } Color featureColor = CommonUtils.GetFeatureColor(map, feature.Class.AliasName, feature); pipePoint.Red = (int)featureColor.R; pipePoint.Green = (int)featureColor.G; pipePoint.Blue = (int)featureColor.B; this.m_arrPipePoints.Add(pipePoint); } feature = enumFeature.Next(); } } } } map.ClearSelection(); IPointCollection pointCollection = (IPointCollection)this.m_pBaseLine; int pointCount = pointCollection.PointCount; if (pointCount != 0) { for (int j = 0; j < pointCount; j++) { IPoint point = pointCollection.get_Point(j); double x = point.X; double y = point.Y; PipePoint pipePoint2 = new PipePoint(); pipePoint2.x = x; pipePoint2.y = y; pipePoint2.PointType = PipePoint.SectionPointType.sptDrawPoint; this.m_arrPipePoints.Add(pipePoint2); } this.fEswZsmwIx((PipePoint)this.m_arrPipePoints[this.m_arrPipePoints.Count - 2]); this.method_1(); if (this.method_2()) { this.method_5(this.m_arrPipePointsDraw, this.m_arrPipePoints); this.method_4(); this.method_7(this.m_arrPipePointsDraw); } } }
//鼠标点击-空间查询 private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) { //1、高亮 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; IActiveView pActiveView; IPoint pPoint; double length; //获取视图范围 pActiveView = this.axMapControl1.ActiveView; //获取鼠标点击屏幕坐标 pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); //屏幕距离转换为地图距离 length = ConvertPixelToMapUnits(pActiveView, 2); ITopologicalOperator pTopoOperator; IGeometry pGeoBuffer; //根据缓冲半径生成空间过滤器 pTopoOperator = pPoint as ITopologicalOperator; pGeoBuffer = pTopoOperator.Buffer(length); ILayer iLayer; //iLayer = Tool.GetLayerByName(axMapControl1.get_Layer(0).Name, axMapControl1); iLayer = axMapControl1.get_Layer(2);//地图图层编号!!! IFeatureLayer iFeatureLayer = (IFeatureLayer)iLayer; iFeatureLayer.Selectable = false;//地图不可选择 IMap pMap = axMapControl1.Map; //IGeometry pGeometry = axMapControl1.TrackRectangle(); //获取几何图框范围 ISelectionEnvironment pSelectionEnv = new SelectionEnvironment(); //新建选择环境 /*选择图层*/ IRgbColor pColor = new RgbColor(); pColor.Red = 200; pColor.Green = 155; pColor.Blue = 180; //调整高亮显示的颜色 pSelectionEnv.DefaultColor = pColor; //设置高亮显示的颜色 pMap.SelectByShape(pGeoBuffer, pSelectionEnv, false); //选择图形SelectByShape方法 //高亮后获得ID /*获取ID*/ ISelection selection = pMap.FeatureSelection; /*获取ID*/ IEnumFeatureSetup enumFeatureSetup = selection as IEnumFeatureSetup; //这里很必要 /*获取ID*/ enumFeatureSetup.AllFields = true; //这里很必要 IEnumFeature enumFeature = enumFeatureSetup as IEnumFeature; enumFeature.Reset(); //feature赋值 IFeature feature = enumFeature.Next(); //IFeatureClass pFeatureClass = pFeature.Class as IFeatureClass; while (feature != null) { stringvalue = feature.get_Value(0).ToString();//就可以得到任意字段的值了 feature = enumFeature.Next(); } axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); // Thread.Sleep(2000); //2、省份查询 this.axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; //记录查询到的要素名称 string strNames = ""; //查询的字段名称 string strFieldName = "NL_NAME_1"; //点查询 //读取shp线 string strFielPath = @"res\RouteShp\" + stringvalue + ".shp";//D:\\NewShp\\line1.shp FileInfo fileInfo = new FileInfo(strFielPath); string fileDirectoryName = fileInfo.DirectoryName; string fileName = fileInfo.Name; //IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass(); IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory(); IWorkspace workspace = workspaceFactory.OpenFromFile(fileDirectoryName, 0); IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace; IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(fileName); IFeatureCursor featureCursor = featureClass.Search(null, false); //访问要素类的一系列要素 对要素类进行查询返回的一个游标(即指向搜素结果集的一个指针) IFeature feature_q = featureCursor.NextFeature(); //将游标移动到结果集下一个要素并返回当前要素,这里将返回结果赋值给了pFeature while (feature_q != null) { IGeometry geoMetry = feature_q.Shape;//得到的每个数据 feature_q = featureCursor.NextFeature(); //提示框 strNames = strNames + QuerySpatial(this.axMapControl1, geoMetry, strFieldName); //提示框显示提示 this.lab_info.Text = strNames; } //3、获取所选路径终点名、花费 switch (stringvalue) { case "0": //七星鲁王宫 endPointname = "七星鲁王宫"; cost = "5542公里"; break; case "1": //西沙海底墓 endPointname = "西沙海底墓"; cost = "3284公里"; break; case "2": //秦岭神树 endPointname = "秦岭神树"; cost = "1867公里"; break; case "3": //西王母宫 endPointname = "西王母宫"; cost = "3433公里"; break; case "4": //张家鼓楼 endPointname = "张家鼓楼"; cost = "7528公里"; break; default: break; } lab_start.Text = startPointname; lab_end.Text = endPointname; lab_costAll.Text = cost; }