private void advTree_NodeDoubleClick(object sender, DevComponents.AdvTree.TreeNodeMouseEventArgs e) { IFeature pfeature = advTree.SelectedNode.Tag as IFeature; if (pfeature != null) { SysCommon.Gis.ModGisPub.ZoomToFeature(m_pMapControl, pfeature); Application.DoEvents(); m_pMapControl.FlashShape(pfeature.Shape, 2, 500, null); } }
//��˸�� public static void FlashLine(IMapControlDefault mapControl, IScreenDisplay iScreenDisplay, IGeometry iGeometry) { ISimpleLineSymbol iLineSymbol; ISymbol iSymbol; IRgbColor iRgbColor; iLineSymbol = new SimpleLineSymbol(); iLineSymbol.Width = 4; iRgbColor = new RgbColor(); iRgbColor.Red = 255; iLineSymbol.Color = iRgbColor; iSymbol = (ISymbol)iLineSymbol; iSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; mapControl.FlashShape(iGeometry, 5, 300, iSymbol); }
//闪烁线 public static void FlashLine(IMapControlDefault mapControl, IScreenDisplay iScreenDisplay, IGeometry iGeometry) { ISimpleLineSymbol iLineSymbol; ISymbol iSymbol; IRgbColor iRgbColor; iLineSymbol = new SimpleLineSymbol(); iLineSymbol.Width = 4; iRgbColor = new RgbColor(); iRgbColor.Red = 255; iLineSymbol.Color = iRgbColor; iSymbol = (ISymbol)iLineSymbol; iSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; mapControl.FlashShape(iGeometry, 5, 300, iSymbol); }
//闪烁点 public static void FlashPoint(IMapControlDefault mapControl, IScreenDisplay iScreenDisplay, IGeometry iGeometry) { ISimpleMarkerSymbol iMarkerSymbol; ISymbol iSymbol; IRgbColor iRgbColor; iMarkerSymbol = new SimpleMarkerSymbol(); iMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; iRgbColor = new RgbColor(); iRgbColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb(); iMarkerSymbol.Color = iRgbColor; iSymbol = (ISymbol)iMarkerSymbol; iSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; mapControl.FlashShape(iGeometry, 5, 300, iSymbol); }
//闪烁面 public static void FlashPolygon(IMapControlDefault mapControl, IScreenDisplay iScreenDisplay, IGeometry iGeometry) { ISimpleFillSymbol iFillSymbol; ISymbol iSymbol; IRgbColor iRgbColor; iFillSymbol = new SimpleFillSymbol(); iFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; iFillSymbol.Outline.Width = 12; iRgbColor = new RgbColor(); iRgbColor.RGB = System.Drawing.Color.FromArgb(100, 180, 180).ToArgb(); iFillSymbol.Color = iRgbColor; iSymbol = (ISymbol)iFillSymbol; iSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; iScreenDisplay.SetSymbol(iSymbol); mapControl.FlashShape(iGeometry, 5, 300, iSymbol); }
private void FlashFeatrue(IFeatureClass pFeatrueClass, int FeatureOID) { IFeature pFeature = null; IEnvelope pEnvelop = null; IActiveView pActiveView = null; pActiveView = vMapControl.ActiveView; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = pFeatrueClass.OIDFieldName + "=" + FeatureOID; IFeatureCursor pFeatrueCursor = null; pFeatrueCursor = pFeatrueClass.Search(pQueryFilter, false); pFeature = pFeatrueCursor.NextFeature(); if (pFeature == null) { return; } if (pFeatrueClass.ShapeType == esriGeometryType.esriGeometryPoint) { ITopologicalOperator pTopo = null; pTopo = pFeature.ShapeCopy as ITopologicalOperator; IGeometry TempGeometry = null; TempGeometry = pTopo.Buffer(0.5); pEnvelop = TempGeometry.Envelope; pEnvelop.Expand(20, 20, true); } else { pEnvelop = pFeature.Extent; pEnvelop.Expand(1.5, 1.5, true); } Application.DoEvents(); pActiveView.Extent = pEnvelop; Application.DoEvents(); pActiveView.Refresh(); Application.DoEvents(); vMapControl.FlashShape(pFeature.ShapeCopy, 3, 200, null); }
/// <summary> /// Occurs when this tool is clicked /// </summary> public override void OnClick() { OpenFileDialog dlg = new OpenFileDialog(); //dlg.Filter = "个人数据库(*.mdb)|*.mdb|shp数据|*.shp|文本文件|*.txt"; dlg.Filter = "shp数据|*.shp|个人数据库(*.mdb)|*.mdb|文件数据库(*.gdb)|gdb"; if (dlg.ShowDialog() == DialogResult.Cancel) { return; } IPolygon pGon = new PolygonClass(); pGon = GetPolyGonFromFile(dlg.FileName); if (pGon == null) { return; } ITopologicalOperator pTopo = pGon as ITopologicalOperator; if (pTopo != null) { pTopo.Simplify(); } if (this.WriteLog) { Plugin.LogTable.Writelog("导入范围查询,范围文件路径为" + dlg.FileName);//xisheng 日志记录 0928; } //Zq 20111011 add 将当前视图定位到导入的范围并闪烁显示 m_MapControl.Extent = pGon.Envelope; (m_MapControl.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null); m_MapControl.ActiveView.ScreenDisplay.UpdateWindow(); m_MapControl.FlashShape(pGon as IGeometry, 3, 200, null); ///ZQ 2011 1129 modify drawgeometryXOR(pGon as IGeometry); if (m_frmQuery == null) { m_frmQuery = new frmQuery(m_MapControl, m_enumQueryMode); m_frmQuery.Owner = m_mainFrm; m_frmQuery.FormClosed += new FormClosedEventHandler(frmQuery_FormClosed); } ///ZQ 2011 1128 将绘制事件插入口袋中 SysCommon.ScreenDraw.list.Add(ImportPolygonQueryAfterDraw); //m_frmQuery.Show(); ///ZQ 20111119 modify // m_frmQuery.FillData(m_MapControl.ActiveView.FocusMap, pGon as IGeometry,esriSpatialRelEnum.esriSpatialRelIntersects ); _QueryBar.m_pMapControl = m_MapControl; _QueryBar.EmergeQueryData(m_MapControl.ActiveView.FocusMap, pGon as IGeometry, esriSpatialRelEnum.esriSpatialRelIntersects); try { DevComponents.DotNetBar.Bar pBar = _QueryBar.Parent.Parent as DevComponents.DotNetBar.Bar; if (pBar != null) { pBar.AutoHide = false; //pBar.SelectedDockTab = 1; int tmpindex = pBar.Items.IndexOf("dockItemDataCheck"); pBar.SelectedDockTab = tmpindex; } } catch { } }
public override void OnClick() { if (_AppHk == null) { return; } if (_AppHk.MapControl.Map == null) { return; } m_MapControl = _AppHk.MapControl; m_Map = m_MapControl.Map; m_ActiveView = m_MapControl.ActiveView; if (m_Map.LayerCount == 0) { return; } try { if (this.WriteLog) { Plugin.LogTable.Writelog("执行导入范围统计"); } /// 判断数据字典是否初始化 if (SysCommon.ModField._DicFieldName.Count == 0) { SysCommon.ModField.InitNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicFieldName, "属性对照表"); } ///存储导入shp文件的所有面要素 List <IFeature> pLst = new List <IFeature>(); OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "shape文件(*.shp)|*.shp"; //openFileDialog1.InitialDirectory = @"E:\test\文档和数据\Data"; openFileDialog1.Multiselect = false; DialogResult pDialogResult = openFileDialog1.ShowDialog(); if (pDialogResult != DialogResult.OK) { return; } IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory(); // 1 string pPath = openFileDialog1.FileName; string pFolder = System.IO.Path.GetDirectoryName(pPath); //文件夹 string pFileName = System.IO.Path.GetFileName(pPath); //文件名 IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pFolder, 0); // 2 IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IFeatureClass pFC = null; try { pFC = pFeatureWorkspace.OpenFeatureClass(pFileName); //3 } catch { MessageBox.Show("请导入有效范围数据!", "提示!"); if (this.WriteLog) { Plugin.LogTable.Writelog("导入范围数据无效"); } return; } if (pFC == null) { MessageBox.Show("请导入有效范围数据!", "提示!"); if (this.WriteLog) { Plugin.LogTable.Writelog("导入范围数据无效"); } return; } IFeatureClass pPolygonFeaCls = GetPolygoneFeatureClass(pFC); if (pPolygonFeaCls == null) { MessageBox.Show("请导入有效范围数据!", "提示!"); if (this.WriteLog) { Plugin.LogTable.Writelog("导入范围数据无效"); } return; } //获得整个图层的游标 IFeatureCursor pFeatureCursor = GetFeatureCursor(pPolygonFeaCls, null, null, esriSpatialRelEnum.esriSpatialRelUndefined); IFeature pFeature = pFeatureCursor.NextFeature(); while (pFeature != null) { pLst.Add(pFeature); pFeature = pFeatureCursor.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor); pFeatureCursor = null; m_Geometry = GetLyrUnionPlygon(pLst); if (m_Geometry == null) { return; } //DrawGeometry(m_Geometry); //m_Envelope = GetLyrUnionEnvelope(pLst); m_Envelope = m_Geometry.Envelope; m_Envelope.Expand(2.0, 2.0, true); m_MapControl.Extent = m_Envelope; //(m_MapControl.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, mElement, m_Envelope); m_MapControl.ActiveView.ScreenDisplay.UpdateWindow(); m_MapControl.FlashShape(m_Geometry as IGeometry, 3, 200, null); frm = new frmAreaStatistics(); frm.CurGeometry = m_Geometry; frm.FormClosed += new FormClosedEventHandler(frm_FormClosed); frm.CurMap = m_MapControl; frm.InitFrm(); frm.SetSliderValue(true); frm.ShowDialog(); if (this.WriteLog) { Plugin.LogTable.Writelog("导入范围统计操作完成"); } } catch (Exception err) { if (this.WriteLog) { Plugin.LogTable.Writelog("导入范围统计操作异常"); } } }
private void SearchFeature(ISpatialFilter pSpatialFilter, IFeatureLayer pFeatureLyr) { ISpatialFilter pFilter; pFilter = pSpatialFilter; IFeatureLayer pFeatureLayer; pFeatureLayer = pFeatureLyr; IFeatureClass pFC = pFeatureLayer.FeatureClass; IFeatureCursor pFeatureCursor; pFeatureCursor = pFeatureLayer.Search(pFilter, true); IFeature pFeature; pFeature = pFeatureCursor.NextFeature(); IGeometry pShape; switch (pFC.ShapeType) { case esriGeometryType.esriGeometryPolyline: while (pFeature != null) { ISimpleLineSymbol pFillsyl; pFillsyl = new SimpleLineSymbolClass(); pFillsyl.Color = getRGB(220, 100, 50); object oFillsyl; oFillsyl = pFillsyl; pShape = pFeature.Shape as IPolyline; m_mapControl.FlashShape(pShape, 15, 20, pFillsyl); m_mapControl.DrawShape(pShape, ref oFillsyl); pFeature = pFeatureCursor.NextFeature(); } break; case esriGeometryType.esriGeometryPolygon: while (pFeature != null) { ISimpleFillSymbol pFillsyl; pFillsyl = new SimpleFillSymbolClass(); pFillsyl.Color = getRGB(220, 100, 50); object oFillsyl; oFillsyl = pFillsyl; pShape = pFeature.Shape as IPolygon; m_mapControl.FlashShape(pShape, 15, 20, pFillsyl); m_mapControl.DrawShape(pShape, ref oFillsyl); pFeature = pFeatureCursor.NextFeature(); } break; case esriGeometryType.esriGeometryPoint: while (pFeature != null) { ISimpleMarkerSymbol pFillsyl; pFillsyl = new SimpleMarkerSymbolClass(); pFillsyl.Color = getRGB(220, 100, 50); object oFillsyl; oFillsyl = pFillsyl; pShape = pFeature.Shape as IPoint; m_mapControl.FlashShape(pShape, 15, 20, pFillsyl); m_mapControl.DrawShape(pShape, ref oFillsyl); pFeature = pFeatureCursor.NextFeature(); } break; } }
//分割要素 private bool splitFeature(IGeometry pGeometry) { IFeatureLayer curLayer = getEditLayer.isExistLayer(m_MapControl.Map) as IFeatureLayer; if (curLayer == null) { return(false); } IFeatureSelection curLayerSn = curLayer as IFeatureSelection; bool hasCut = false; //空间查询,找出被切割要素 ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = pGeometry; if (curLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelRelation; spatialFilter.SpatialRelDescription = "TTTFFTTTT"; } else if (curLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; } IFeatureClass featureClass = curLayer.FeatureClass; IWorkspaceEdit iWE = (featureClass as IDataset).Workspace as IWorkspaceEdit; if (!iWE.IsBeingEdited()) { iWE.StartEditing(false); } System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; try { IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false); IFeature origFeature = featureCursor.NextFeature(); if (origFeature != null) { //检查第一个要素是否Z敏感则将切割线设成Z敏感 IZAware zAware = origFeature.Shape as IZAware; if (zAware.ZAware) { zAware = pGeometry as IZAware; zAware.ZAware = true; } ArrayList comErrors = new ArrayList(); //开始操作 iWE.StartEditOperation(); //循环空间查询的要素,执行切割 while (origFeature != null) { try { //切割要素,IFeatureEdit.Split此方法可自动处理属性 IFeatureEdit featureEdit = origFeature as IFeatureEdit; ISet newFeaturesSet = null; //保存切割生成的新要素的集合 //若源要素是线,则切割图形是交点 if (curLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { ITopologicalOperator iTo = pGeometry as ITopologicalOperator; IGeometry pTmpG = iTo.Intersect(origFeature.ShapeCopy, esriGeometryDimension.esriGeometry0Dimension); IPointCollection pTmpPc = pTmpG as IPointCollection; for (int i = pTmpPc.PointCount - 1; i >= 0; i--) { //newFeaturesSet = featureEdit.Split(pTmpG); newFeaturesSet = featureEdit.Split(pTmpPc.get_Point(pTmpPc.PointCount - 1)); //新要素已经生成 if (newFeaturesSet != null) { newFeaturesSet.Reset(); IFeature pSplitFeature = null; pSplitFeature = newFeaturesSet.Next() as IFeature; //IFeatureEdit tmpFE = pSplitFeature as IFeatureEdit; while (pSplitFeature != null) { //闪烁新要素 m_MapControl.FlashShape(pSplitFeature.ShapeCopy, 1, 300, Type.Missing); pSplitFeature = newFeaturesSet.Next() as IFeature; } hasCut = true; } } } //如果是面,切割图形是线 else { newFeaturesSet = featureEdit.Split(pGeometry); //新要素已经生成 if (newFeaturesSet != null) { newFeaturesSet.Reset(); IFeature pSplitFeature = null; pSplitFeature = newFeaturesSet.Next() as IFeature; while (pSplitFeature != null) { //闪烁新要素 m_MapControl.FlashShape(pSplitFeature.ShapeCopy, 1, 300, Type.Missing); pSplitFeature = newFeaturesSet.Next() as IFeature; } hasCut = true; } } } catch (COMException comExc) { comErrors.Add(String.Format("OID: {0}, 错误: {1} , {2}", origFeature.OID.ToString(), comExc.ErrorCode, comExc.Message)); } finally { //当前的失败,则继续下一个 origFeature = featureCursor.NextFeature(); } } //如果有切割动作,则刷新视图并保存 if (hasCut) { //清除地图选择集 m_MapControl.Map.ClearSelection(); //刷新视图 m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection, null, m_MapControl.ActiveView.Extent); //完成编辑操作 iWE.StopEditOperation(); } else { iWE.AbortEditOperation(); } //报告错误 if (comErrors.Count > 0) { StringBuilder stringBuilder = new StringBuilder("以下要素不能被切割: \n", 200); foreach (string comError in comErrors) { stringBuilder.AppendLine(comError); } MessageBox.Show(stringBuilder.ToString(), "切割错误"); } } } catch (Exception ex) { ErrorHandle.ShowFrmErrorHandle("提示", "切割失败!\r\n" + ex.Message); iWE.AbortEditOperation(); } finally { System.Windows.Forms.Cursor.Current = Cursors.Default; } return(hasCut); }
//��˸�� public static void FlashPoint(IMapControlDefault mapControl, IScreenDisplay iScreenDisplay, IGeometry iGeometry) { ISimpleMarkerSymbol iMarkerSymbol; ISymbol iSymbol; IRgbColor iRgbColor; iMarkerSymbol = new SimpleMarkerSymbol(); iMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; iRgbColor = new RgbColor(); iRgbColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb(); iMarkerSymbol.Color = iRgbColor; iSymbol = (ISymbol)iMarkerSymbol; iSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; mapControl.FlashShape(iGeometry, 5, 300, iSymbol); }
//��˸�� public static void FlashPolygon(IMapControlDefault mapControl, IScreenDisplay iScreenDisplay, IGeometry iGeometry) { ISimpleFillSymbol iFillSymbol; ISymbol iSymbol; IRgbColor iRgbColor; iFillSymbol = new SimpleFillSymbol(); iFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; iFillSymbol.Outline.Width = 12; iRgbColor = new RgbColor(); iRgbColor.RGB = System.Drawing.Color.FromArgb(100, 180, 180).ToArgb(); iFillSymbol.Color = iRgbColor; iSymbol = (ISymbol)iFillSymbol; iSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; iScreenDisplay.SetSymbol(iSymbol); mapControl.FlashShape(iGeometry, 5, 300, iSymbol); }
public void FlashFeature(IFeature pFeature, IMapControlDefault pMapControl) { IActiveView pActiveView = pMapControl.ActiveView; IEnvelope pEnvSmall = pFeature.Shape.Envelope; IEnvelope pEnvScreen = pActiveView.Extent; IPoint pPointCenter = new PointClass(); pPointCenter.PutCoords((pEnvSmall.XMax + pEnvSmall.XMin) / 2, (pEnvSmall.YMax + pEnvSmall.YMin) / 2); IPoint pPointXMax = new PointClass(); pPointXMax.PutCoords(pEnvScreen.XMax, pPointCenter.Y); IPoint pPointXMaxSmall = new PointClass(); pPointXMaxSmall.PutCoords(pEnvSmall.XMax, pPointCenter.Y); IPoint pPointXMin = new PointClass(); pPointXMin.PutCoords(pEnvScreen.XMin, pPointCenter.Y); IPoint pPointXMinSmall = new PointClass(); pPointXMinSmall.PutCoords(pEnvSmall.XMin, pPointCenter.Y); IPoint pPointYMax = new PointClass(); pPointYMax.PutCoords(pPointCenter.X, pEnvScreen.YMax); IPoint pPointYMaxSmall = new PointClass(); pPointYMaxSmall.PutCoords(pPointCenter.Y, pEnvSmall.YMax); IPoint pPointYMin = new PointClass(); pPointYMin.PutCoords(pPointCenter.X, pEnvScreen.YMin); IPoint pPointYMinSmall = new PointClass(); pPointYMinSmall.PutCoords(pPointCenter.Y, pEnvSmall.YMin); for (int i = 0; i < 13; i++) { IPolyline pLineXMax = new PolylineClass(); pLineXMax.FromPoint = pPointXMax; IPoint pPointTo = new PointClass(); double xMax = pPointXMax.X + Convert.ToInt32((pPointXMaxSmall.X - pPointXMax.X) * i / 13); pPointTo.PutCoords(xMax, pPointCenter.Y); pLineXMax.ToPoint = pPointTo; IPolyline pLineXMin = new PolylineClass(); pLineXMin.FromPoint = pPointXMin; double xMin = pPointXMin.X + (pPointXMinSmall.X - pPointXMin.X) * i / 13; pPointTo.PutCoords(xMin, pPointCenter.Y); pLineXMin.ToPoint = pPointTo; IPolyline pLineYMin = new PolylineClass(); pLineYMin.FromPoint = pPointYMin; double yMin = pPointYMin.Y + (pPointYMinSmall.Y - pPointYMin.Y) * i / 13; pPointTo.PutCoords(pPointYMin.X, yMin); pLineYMin.ToPoint = pPointTo; IPolyline pLineYMax = new PolylineClass(); pLineYMax.FromPoint = pPointYMax; double yMax = pPointYMax.Y + (pPointYMaxSmall.Y - pPointYMax.Y) * i / 13; pPointTo.PutCoords(pPointYMax.X, yMax); pLineYMax.ToPoint = pPointTo; IGeometryCollection pGeoColl = new PolylineClass(); object obj = Type.Missing; IPath pPath = new PathClass(); pPath.FromPoint = pLineXMax.FromPoint; pPath.ToPoint = pLineXMax.ToPoint; pGeoColl.AddGeometry(pPath, ref obj, ref obj); pPath = new PathClass(); pPath.FromPoint = pLineXMin.FromPoint; pPath.ToPoint = pLineXMin.ToPoint; pGeoColl.AddGeometry(pPath, ref obj, ref obj); pPath = new PathClass(); pPath.FromPoint = pLineYMax.FromPoint; pPath.ToPoint = pLineYMax.ToPoint; pGeoColl.AddGeometry(pPath, ref obj, ref obj); pPath = new PathClass(); pPath.FromPoint = pLineYMin.FromPoint; pPath.ToPoint = pLineYMin.ToPoint; pGeoColl.AddGeometry(pPath, ref obj, ref obj); FlashFeature(pGeoColl as IGeometry, pActiveView, 5); } pMapControl.FlashShape(pFeature.Shape, 2, 500, null); }