public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { try { if (button == 1) { Color color = ColorTranslator.FromHtml(SystemInfo.Instance.TextColor); IColor pColor = new RgbColorClass(); pColor.RGB = color.B * 65536 + color.G * 256 + color.R; ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; IRubberBand pRubberBand; pRubberBand = new RubberLineClass(); IGeometry pLine = pRubberBand.TrackNew(m_Display, null); ILineElement lineElement = new LineElementClass(); lineElement.Symbol = pLineSym; IElement element = lineElement as IElement; element.Geometry = pLine; pGraphicsContainer.AddElement(element, 0); m_ActiveView.Refresh(); } } catch (System.Exception ex) { } }
///<summary> ///Create a polyline geometry object using the RubberBand.TrackNew method when a user click the mouse on the map control. ///</summary> ///<param name="activeView">An ESRI.ArcGIS.Carto.IActiveView interface that will user will interact with to draw a polyline.</param> ///<returns>An ESRI.ArcGIS.Geometry.IPolyline interface that is the polyline the user drew</returns> ///<remarks>Double click the left mouse button to end tracking the polyline.</remarks> public IPolyline GetPolylineFromMouseClicks(IActiveView activeView) { IScreenDisplay screenDisplay = activeView.ScreenDisplay; IRubberBand rubberBand = new RubberLineClass(); IGeometry geometry = rubberBand.TrackNew(screenDisplay, null); IPolyline polyline = (IPolyline)geometry; return(polyline); }
/// <summary> /// 绘制线要素 /// </summary> /// <param name="view">活动视图</param> /// <param name="symbol">线样式SimpleSymbolHelper</param> /// <returns></returns> public static IGeometry DreawPolyLine(IActiveView view, ISymbol symbol) { //初始rubberband IRubberBand band = new RubberLineClass(); IGeometry newGeo = band.TrackNew(view.ScreenDisplay, symbol); if (newGeo == null) { return(null); } return(newGeo); }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { if (button == 1) { int dis; IRubberBand pRubberBand; pRubberBand = new RubberLineClass(); IGeometry pLine; pLine = pRubberBand.TrackNew(m_Display, null); dis = Class.SelectionEnv.System_Selection_Environment(m_ActiveView).SearchTolerance; IFeatureSelection pFeaSel = m_pCurEditLayer as IFeatureSelection; IGeometry pGeoSel = Class.Common.DoBuffer(pLine, dis); ISpatialFilter pSpaFilter = new SpatialFilter(); pSpaFilter.Geometry = pGeoSel; pSpaFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; if (shift == 1) { pFeaSel.CombinationMethod = esriSelectionResultEnum.esriSelectionResultAdd; //Class.SelectionEnv.System_Selection_Environment(m_ActiveView).CombinationMethod = esriSelectionResultEnum.esriSelectionResultAdd; } if (Class.SelectionEnv.System_Selection_Environment(m_ActiveView).CombinationMethod == 0)//new selection { this.m_ActiveView.FocusMap.ClearSelection(); } else { pFeaSel.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; this.m_ActiveView.FocusMap.ClearSelection(); } pFeaSel.SelectFeatures(pSpaFilter, pFeaSel.CombinationMethod, false); //m_ActiveView.FocusMap.SelectByShape(Class.Common.DoBuffer(pLine, dis), Class.SelectionEnv.System_Selection_Environment(m_ActiveView), false); m_App.Workbench.UpdateMenu(); if (m_ActiveView.FocusMap.SelectionCount > 0) { m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } else { m_ActiveView.Refresh(); } } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { m_ActiveView = m_hookHelper.ActiveView; m_Map = m_hookHelper.FocusMap; IScreenDisplay pScreenDisplay = m_ActiveView.ScreenDisplay; IRubberBand pRubberPolyline = new RubberLineClass(); ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass(); pLineSymbol.Color = getRGB(255, 255, 0); IPolyline pPolyline = pRubberPolyline.TrackNew(pScreenDisplay, (ISymbol)pLineSymbol) as IPolyline; pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; pLineSymbol.Color = getRGB(0, 255, 255); ILineElement pPolylineEle = new LineElementClass(); pPolylineEle.Symbol = pLineSymbol; IElement pEle = pPolylineEle as IElement; pEle.Geometry = pPolyline; IGraphicsContainer pGraphicsContainer = m_Map as IGraphicsContainer; pGraphicsContainer.AddElement(pEle, 0); m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { IScreenDisplay pScr = m_pActiveView.ScreenDisplay; if (m_pArrPipes.Count != 0 || m_pArrIntersectPnt.Count != 0) { m_pArrPipes.Clear(); m_pArrIntersectPnt.Clear(); } //跟踪画线 IRubberBand pRB = new RubberLineClass(); m_pGeoTrack = pRB.TrackNew(pScr, null); if ((m_pGeoTrack as IPointCollection).PointCount != 2) { XtraMessageBox.Show("请使用鼠标制定两点确定扯旗的管线"); return; } Element.DeleteElement(m_pActiveView.GraphicsContainer, "cq"); Element.AddGraphics(m_pActiveView.GraphicsContainer, m_pGeoTrack, GetDefaultSymbol(esriGeometryType.esriGeometryPolyline), "dmx"); IElement pElement = Element.GetElementByName(m_pMapControl.ActiveView.GraphicsContainer, "cq"); if (pElement != null) { m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } base.OnMouseDown(button, shift, x, y, mapX, mapY); GetArrPipe(); if (m_pArrPipes.Count <= 0) { return; } DrawPipeLabels(); DoAnalysis(); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { IRubberBand ipRubber = new RubberLineClass(); IGeometry ipGeo = ipRubber.TrackNew(m_hookHelper.ActiveView.ScreenDisplay, null); IFeatureLayer layer = null; for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++) { layer = (IFeatureLayer)m_hookHelper.FocusMap.get_Layer(i); if (layer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { break; } layer = null; } if (layer != null) { IFeature feature = layer.FeatureClass.CreateFeature(); feature.Shape = ipGeo; feature.Store(); m_hookHelper.ActiveView.Refresh(); } }
public void points() { string strs = "Marker"; switch (strs) { case "Marker": IMarkerElement pMarkerElement;//对于点,线,面的element定义这里都不一样,他是可实例化的类,而IElement是实例化的类,必须通过 IMarkerElement 初始化负值给 IElement 。 IElement pMElement; IPoint pPoint=new PointClass();//你画的图形式什么就是什么,特别的是LINE则需要定义为POLYLINE pMarkerElement = new MarkerElementClass(); pMElement = pMarkerElement as IElement; //RubberPointClass pRubberBand = new RubberPointClass();//你的RUBBERBAND随着你的图形耳边 //pPoint = pRubberBand.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPoint; ////pPoint = pRubberBand.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPoint; //pPoint.X = 101; //pPoint.Y = 37; // pPoint.PutCoords(Convert.ToDouble(101), Convert.ToDouble(37)); //pPoint = axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(200, 200); // pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)); // pPoint = axMapControl.ToMapPoint(334, 344); //pPoint.X = pPoint.X; //pPoint.Y = pPoint.Y; /*00000000000000000000000000000000000经纬度转换坐标*/ //IGlobeDisplay m_globeDisplay = axGlobeControl1.GlobeDisplay; //// IGlobeDisplay pGlobeDisplay = axGlobeControl1.GlobeDisplay; ////axGlobeControl1.GlobeDisplay.ActiveViewer; //ISceneViewer sceneViewer = m_globeDisplay.ActiveViewer; //IGlobeViewUtil globeViewUtil = (IGlobeViewUtil)sceneViewer.Camera; //int winX, winY; ////globeViewUtil.GeographicToWindow(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text), 0, out winX, out winY); ////pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));//x,y地理坐标 //pPoint=axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(0, 0);//x,y为屏幕坐标 ////pPoint.X = Convert.ToDouble(textBox1.Text); ////pPoint.Y = Convert.ToDouble(textBox2.Text); //pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));//x,y地理坐标 //axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(pPoint, out winX, out winY); // int mx = winX; //int my = winY; //pPoint=axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(200, 400);//x,y为屏幕坐标 pPoint.PutCoords(Convert.ToDouble(textBox3.Text), Convert.ToDouble(textBox4.Text)); /*00000000000000000000000000000000000*/ // pPoint = axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(mx, my); //pPoint.PutCoords(mx, my); //pPoint.X = mx; //pPoint.Y = my; //ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass(); //pPoint.SpatialReference = pSRF.CreateProjectedCoordinateSystem(2414); //pPoint.Project(pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954)); pMElement.Geometry = pPoint;//把你在屏幕中画好的图形付给 IElement 储存 IGraphicsContainer pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器 pGraphicsContainer.AddElement(pMElement, 0);//显示储存在 IElement 中图形,这样就持久化了。 axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //axMapControl.Refresh(); break; case "Line": ILineElement pLineElement; IElement pLElement; IPolyline pLine; pLineElement = new LineElementClass(); pLElement = pLineElement as IElement; RubberLineClass pRubberBandd = new RubberLineClass(); pLine = pRubberBandd.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPolyline; pLElement.Geometry = pLine; pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器 pGraphicsContainer.AddElement(pLElement, 0);//把刚刚的element转到容器上 axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); break; case "Fill": IFillShapeElement pFillShapeElement; IElement pgonElemnt; IPolygon pPolygon; pFillShapeElement = new PolygonElementClass(); pgonElemnt = pFillShapeElement as IElement;//Element RubberPolygonClass pRubberBand3 = new RubberPolygonClass();//在屏幕上画个多边形 pPolygon = pRubberBand3.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPolygon; pgonElemnt.Geometry = pPolygon;//把这个多边形转成Element pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器 //pGraphicsContainer.DeleteAllElements (); pGraphicsContainer.AddElement(pgonElemnt, 0);//把刚刚的element转到容器上 axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); break; } }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; if (app == null || app.Current2DMapControl == null) { return; } IActiveView m_ActiveView = app.Current2DMapControl.ActiveView; IScreenDisplay m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay; IGeometry pGeo = null; try { if (button == 1) { ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pColor.Blue = 0; pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; IRubberBand pRubberBand; pRubberBand = new RubberLineClass(); IGeometry pLine = pRubberBand.TrackNew(m_Display, null); object symbol = pLineSym as object; app.Current2DMapControl.DrawShape(pLine, ref symbol); if ((pLine as IPolyline).Length > 500) { XtraMessageBox.Show("横断面线超过500米,分析效率很低,请重新绘制", "提示"); return; } WaitForm.Start("正在进行横断面分析...", "请稍后"); pGeo = pLine; if (pGeo == null) { return; } string road1 = ""; string road2 = ""; bool bAlert = false; double hmax = double.MinValue; double hmin = double.MaxValue; List <PPLine2D> pplines = new List <PPLine2D>(); IFeatureCursor pFeatureCursor = null; IFeature pFeature = null; foreach (MajorClass mc in LogicDataStructureManage2D.Instance.GetAllMajorClass()) { foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible2D) { continue; } string[] arrFc2DId = mc.Fc2D.Split(';'); if (arrFc2DId == null) { continue; } foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null) { continue; } FacilityClass facc = dffc.GetFacilityClass(); if (facc.Name != "PipeLine") { continue; } //查找管径长宽字段,获得该要素类下字段索引值,若为圆管,则长宽相等 DFDataConfig.Class.FieldInfo fiDia = facc.GetFieldInfoBySystemName("Diameter"); DFDataConfig.Class.FieldInfo fiDia1 = facc.GetFieldInfoBySystemName("Diameter1"); DFDataConfig.Class.FieldInfo fiDia2 = facc.GetFieldInfoBySystemName("Diameter2"); int indexDia = fc.Fields.FindField(fiDia.Name); int indexDiaWith = fc.Fields.FindField(fiDia1.Name); int indexDiaHeight = fc.Fields.FindField(fiDia2.Name); if (indexDiaWith == -1 || indexDiaHeight == -1 || indexDia == -1) { continue; } //查找道路字段索引 DFDataConfig.Class.FieldInfo fiRoad = facc.GetFieldInfoBySystemName("Road"); int indexRoad = fc.Fields.FindField(fiRoad.Name); //查找管线高类别索引 DFDataConfig.Class.FieldInfo fiHLB = facc.GetFieldInfoBySystemName("HLB"); int indexHLB = fc.Fields.FindField(fiHLB.Name); //二级分类名索引 int indexClassify = fc.Fields.FindField(mc.ClassifyField); ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = pGeo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.WhereClause = UpOrDown.DecorateWhereClasuse(fc) + mc.ClassifyField + " = '" + sc.Name + "'"; int count = fc.FeatureCount(pSpatialFilter); if (count == 0) { continue; } pFeatureCursor = fc.Search(pSpatialFilter, true); while ((pFeature = pFeatureCursor.NextFeature()) != null) { if (indexRoad != -1) { if (road2 == "") { road1 = pFeature.get_Value(indexRoad).ToString(); road2 = pFeature.get_Value(indexRoad).ToString(); } else { road1 = pFeature.get_Value(indexRoad).ToString(); if (road1 != road2) { if (!bAlert) { XtraMessageBox.Show("横断面线跨越多条道路,当前只绘制在【" + road2 + "】上的管线横断面图。", "提示"); bAlert = true; } continue; } } } //查找管线的起点终点地面高 double startSurfHeight = double.MaxValue; double endSurfHeight = double.MaxValue; DFDataConfig.Class.FieldInfo fiStartSurfHeight = facc.GetFieldInfoBySystemName("StartSurfH"); if (fiStartSurfHeight == null) { continue; } int indexStartSurfHeight = pFeature.Fields.FindField(fiStartSurfHeight.Name); if (indexStartSurfHeight == -1) { continue; } DFDataConfig.Class.FieldInfo fiEndSurfHeight = facc.GetFieldInfoBySystemName("EndSurfH"); if (fiEndSurfHeight == null) { continue; } int indexEndSurfHeight = pFeature.Fields.FindField(fiEndSurfHeight.Name); if (indexEndSurfHeight == -1) { continue; } //若管线属性地面高字段为null,则从DEM取值 if (pFeature.get_Value(indexStartSurfHeight).ToString() == "" || pFeature.get_Value(indexEndSurfHeight).ToString() == "") { startSurfHeight = ReadDemRaster.GetH((pFeature.Shape as IPolyline).FromPoint); endSurfHeight = ReadDemRaster.GetH((pFeature.Shape as IPolyline).ToPoint); } else { startSurfHeight = Convert.ToDouble(pFeature.get_Value(indexStartSurfHeight).ToString()); endSurfHeight = Convert.ToDouble(pFeature.get_Value(indexEndSurfHeight).ToString()); } //查找管线起点高程和终点高程 double startDepthHeight = double.MaxValue; double endDepthHeight = double.MaxValue; DFDataConfig.Class.FieldInfo fiStartDepthHeight = facc.GetFieldInfoBySystemName("StartHeight2D"); if (fiStartDepthHeight == null) { continue; } int indexStartDepthHeight = pFeature.Fields.FindField(fiStartDepthHeight.Name); if (indexStartDepthHeight == -1) { continue; } DFDataConfig.Class.FieldInfo fiEndDepthHeight = facc.GetFieldInfoBySystemName("EndHeight"); if (fiEndDepthHeight == null) { continue; } int indexEndDepthHeight = pFeature.Fields.FindField(fiEndDepthHeight.Name); if (indexEndDepthHeight == -1) { continue; } startDepthHeight = Convert.ToDouble(pFeature.get_Value(indexStartDepthHeight).ToString()); endDepthHeight = Convert.ToDouble(pFeature.get_Value(indexEndDepthHeight).ToString()); //计算管线和断面的交点 IGeometry ppGeo = pFeature.Shape; ITopologicalOperator pTopo = ppGeo as ITopologicalOperator; IGeometry geoIntersect = pTopo.Intersect(pGeo, esriGeometryDimension.esriGeometry0Dimension); if (geoIntersect == null) { continue; } PPLine2D ppline = new PPLine2D(); if (indexClassify == -1) { ppline.facType = mc.Name; } else { ppline.facType = pFeature.get_Value(indexClassify).ToString(); } //查找管线的管径,判断其是方管还是圆管 string diameter = pFeature.get_Value(indexDia).ToString(); string diameter1 = pFeature.get_Value(indexDiaWith).ToString(); string diameter2 = pFeature.get_Value(indexDiaHeight).ToString(); if (diameter.Trim() == "") { continue; } ppline.dia = diameter; int indexSplit = diameter.IndexOf('*'); if (indexSplit != -1) { ppline.isrect = true; int iDia1; bool bDia1 = int.TryParse(diameter.Substring(0, indexSplit), out iDia1); if (!bDia1) { continue; } int iDia2; bool bDia2 = int.TryParse(diameter.Substring(indexSplit + 1, diameter.Length - indexSplit - 1), out iDia2); if (!bDia2) { continue; } ppline.gj.Add(iDia1); ppline.gj.Add(iDia2); } else { ppline.isrect = false; int iDia; bool bDia = int.TryParse(diameter, out iDia); if (!bDia) { continue; } ppline.gj.Add(iDia); ppline.gj.Add(iDia); } //判断管线高方式 int hlb = 0; if (indexHLB != -1) { string strhlb = pFeature.get_Value(indexHLB).ToString(); if (strhlb.Contains("内")) { hlb = 1; } else if (strhlb.Contains("外")) { hlb = -1; } else { hlb = 0; } ppline.hlb = hlb; } #region 交点为一个 if (geoIntersect.GeometryType == esriGeometryType.esriGeometryPoint) { IPolyline polyline = pFeature.Shape as IPolyline; IPoint ptIntersect = geoIntersect as IPoint; ppline.interPoint = new PPPoint(ptIntersect.X, ptIntersect.Y); ppline.clh = GetInterPointHeight(ptIntersect, polyline, startDepthHeight, endDepthHeight); if (ppline.clh > hmax) { hmax = ppline.clh; } if (ppline.clh < hmin) { hmin = ppline.clh; } ppline.cgh = startSurfHeight + (endSurfHeight - startSurfHeight) * Math.Sqrt((polyline.FromPoint.X - ptIntersect.X) * (polyline.FromPoint.X - ptIntersect.X) + (polyline.FromPoint.Y - ptIntersect.Y) * (polyline.FromPoint.Y - ptIntersect.Y)) / polyline.Length; if (ppline.cgh > hmax) { hmax = ppline.cgh; } if (ppline.cgh < hmin) { hmin = ppline.cgh; } // 辅助画图 IPolyline l = pGeo as IPolyline; ppline.startPt = new PPPoint(l.FromPoint.X, l.FromPoint.Y); pplines.Add(ppline); } #endregion #region 交点为多个 else if (geoIntersect.GeometryType == esriGeometryType.esriGeometryMultipoint) { IPolyline polyline = pFeature.Shape as IPolyline; IPointCollection geoCol = geoIntersect as IPointCollection; for (int i = 0; i < geoCol.PointCount; i++) { IPoint ptIntersect = geoCol.get_Point(i); ppline.interPoint = new PPPoint(ptIntersect.X, ptIntersect.Y); ppline.clh = GetInterPointHeight(ptIntersect, polyline, startDepthHeight, endDepthHeight); if (ppline.clh > hmax) { hmax = ppline.clh; } if (ppline.clh < hmin) { hmin = ppline.clh; } ppline.cgh = startSurfHeight + (endSurfHeight - startSurfHeight) * Math.Sqrt((polyline.FromPoint.X - ptIntersect.X) * (polyline.FromPoint.X - ptIntersect.X) + (polyline.FromPoint.Y - ptIntersect.Y) * (polyline.FromPoint.Y - ptIntersect.Y)) / polyline.Length; if (ppline.cgh > hmax) { hmax = ppline.cgh; } if (ppline.cgh < hmin) { hmin = ppline.cgh; } // 辅助画图 IPolyline l = pGeo as IPolyline; ppline.startPt = new PPPoint(l.FromPoint.X, l.FromPoint.Y); pplines.Add(ppline); } } else { continue; } #endregion } } } } WaitForm.Stop(); if (pplines.Count < 2) { XtraMessageBox.Show("相交管线少于2个", "提示"); return; } pplines.Sort(new PPLineCompare2D()); double spacesum = 0.0; for (int i = 1; i < pplines.Count; i++) { PPLine2D line1 = pplines[i - 1]; PPLine2D line2 = pplines[i]; line2.space = Math.Sqrt((line1.interPoint.X - line2.interPoint.X) * (line1.interPoint.X - line2.interPoint.X) + (line1.interPoint.Y - line2.interPoint.Y) * (line1.interPoint.Y - line2.interPoint.Y)); spacesum += line2.space; } ; var str1 = (pplines[0].interPoint.X / 1000).ToString("0.00"); var str2 = (pplines[0].interPoint.Y / 1000).ToString("0.00"); string mapNum = str2 + "-" + str1; string mapName = SystemInfo.Instance.SystemFullName + "横断面图"; FrmSectionAnalysis dialog = new FrmSectionAnalysis("横断面分析结果", 0); dialog.SetInfo(mapName, mapNum, pplines, hmax, hmin, spacesum, road2); dialog.Show(); } } catch { WaitForm.Stop(); } }
private void CutSelectedPolygon() { bool isSuccess = false; if (m_selectedFeature == null) { MessageBox.Show("请先选择要分割的面要素!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); m_toolPhase = ToolPhase.SelectFeature; return; } //在屏幕上绘制用于分割的线要素 IScreenDisplay screenDisplay = m_activeView.ScreenDisplay; ISimpleLineSymbol sym = new SimpleLineSymbolClass(); IRgbColor color = new RgbColorClass(); color.Red = 255; color.Green = 128; color.Blue = 128; sym.Color = color; sym.Style = esriSimpleLineStyle.esriSLSSolid; sym.Width = 2; IRubberBand cutBand = new RubberLineClass(); IGeometry reshaprGeometry = cutBand.TrackNew(screenDisplay, sym as ISymbol); screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); screenDisplay.SetSymbol(sym as ISymbol); screenDisplay.DrawPolyline(reshaprGeometry); screenDisplay.FinishDrawing(); IFeatureClass featureClass = m_selectedFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } //分割选择的面要素 if (reshaprGeometry.IsEmpty == true) { return; } try { IPolyline reshapePolyline, sourcePolyline = null; IPolygon4 polygon = null; IRing ring = null, innerRing = null, outRing = null; IPath reshapePath = null; IGeometryCollection pathCollection = null; IGeometry geometry = m_selectedFeature.Shape; switch (geometry.GeometryType) { case esriGeometryType.esriGeometryPolygon: bool outerSuccess = false, innerSuccess = false; IGeometryBag innerRingGeometryBag = null; IGeometryCollection innerRingGeometryCollection = null; reshapePolyline = reshaprGeometry as IPolyline; pathCollection = reshapePolyline as IGeometryCollection; //只可能产生一条polyline,直接写死 reshapePath = pathCollection.Geometry[0] as IPath; polygon = geometry as IPolygon4; IGeometryBag exteriorRingGeometryBag = polygon.ExteriorRingBag; IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection; for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++) { outRing = exteriorRingGeometryCollection.Geometry[i] as IRing; bool a = outRing.Reshape(reshapePath); outerSuccess = outerSuccess || a; innerRingGeometryBag = polygon.get_InteriorRingBag(outRing); innerRingGeometryCollection = innerRingGeometryBag as IGeometryCollection; for (int j = 0; j < innerRingGeometryCollection.GeometryCount; j++) { innerRing = innerRingGeometryCollection.Geometry[j] as IRing; bool b = innerRing.Reshape(reshapePath); innerSuccess = innerSuccess || b; } } isSuccess = innerSuccess || outerSuccess; break; case esriGeometryType.esriGeometryPolyline: sourcePolyline = geometry as IPolyline; reshapePolyline = reshaprGeometry as IPolyline; pathCollection = reshapePolyline as IGeometryCollection; //只可能产生一条polyline,直接写死 reshapePath = pathCollection.Geometry[0] as IPath; isSuccess = sourcePolyline.Reshape(reshapePath); break; } if (isSuccess) { workspaceEdit.StartEditOperation(); m_selectedFeature.Shape = geometry;//如果没加这句gdb无法编辑 m_selectedFeature.Store(); m_activeView.Refresh(); workspaceEdit.StopEditOperation(); } else { throw new Exception("重塑要素失败!"); } m_activeView.Refresh(); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); MessageBox.Show("分割面要素失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent); m_toolPhase = ToolPhase.SelectFeature; }
public void points() { string strs = "Marker"; switch (strs) { case "Marker": IMarkerElement pMarkerElement; //对于点,线,面的element定义这里都不一样,他是可实例化的类,而IElement是实例化的类,必须通过 IMarkerElement 初始化负值给 IElement 。 IElement pMElement; IPoint pPoint = new PointClass(); //你画的图形式什么就是什么,特别的是LINE则需要定义为POLYLINE pMarkerElement = new MarkerElementClass(); pMElement = pMarkerElement as IElement; //RubberPointClass pRubberBand = new RubberPointClass();//你的RUBBERBAND随着你的图形耳边 //pPoint = pRubberBand.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPoint; ////pPoint = pRubberBand.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPoint; //pPoint.X = 101; //pPoint.Y = 37; // pPoint.PutCoords(Convert.ToDouble(101), Convert.ToDouble(37)); //pPoint = axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(200, 200); // pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)); // pPoint = axMapControl.ToMapPoint(334, 344); //pPoint.X = pPoint.X; //pPoint.Y = pPoint.Y; /*00000000000000000000000000000000000经纬度转换坐标*/ //IGlobeDisplay m_globeDisplay = axGlobeControl1.GlobeDisplay; //// IGlobeDisplay pGlobeDisplay = axGlobeControl1.GlobeDisplay; ////axGlobeControl1.GlobeDisplay.ActiveViewer; //ISceneViewer sceneViewer = m_globeDisplay.ActiveViewer; //IGlobeViewUtil globeViewUtil = (IGlobeViewUtil)sceneViewer.Camera; //int winX, winY; ////globeViewUtil.GeographicToWindow(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text), 0, out winX, out winY); ////pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));//x,y地理坐标 //pPoint=axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(0, 0);//x,y为屏幕坐标 ////pPoint.X = Convert.ToDouble(textBox1.Text); ////pPoint.Y = Convert.ToDouble(textBox2.Text); //pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));//x,y地理坐标 //axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(pPoint, out winX, out winY); // int mx = winX; //int my = winY; //pPoint=axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(200, 400);//x,y为屏幕坐标 pPoint.PutCoords(Convert.ToDouble(textBox3.Text), Convert.ToDouble(textBox4.Text)); /*00000000000000000000000000000000000*/ // pPoint = axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(mx, my); //pPoint.PutCoords(mx, my); //pPoint.X = mx; //pPoint.Y = my; //ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass(); //pPoint.SpatialReference = pSRF.CreateProjectedCoordinateSystem(2414); //pPoint.Project(pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954)); pMElement.Geometry = pPoint; //把你在屏幕中画好的图形付给 IElement 储存 IGraphicsContainer pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer; //把地图的当前view作为图片的容器 pGraphicsContainer.AddElement(pMElement, 0); //显示储存在 IElement 中图形,这样就持久化了。 axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //axMapControl.Refresh(); break; case "Line": ILineElement pLineElement; IElement pLElement; IPolyline pLine; pLineElement = new LineElementClass(); pLElement = pLineElement as IElement; RubberLineClass pRubberBandd = new RubberLineClass(); pLine = pRubberBandd.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPolyline; pLElement.Geometry = pLine; pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer; //把地图的当前view作为图片的容器 pGraphicsContainer.AddElement(pLElement, 0); //把刚刚的element转到容器上 axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); break; case "Fill": IFillShapeElement pFillShapeElement; IElement pgonElemnt; IPolygon pPolygon; pFillShapeElement = new PolygonElementClass(); pgonElemnt = pFillShapeElement as IElement;//Element RubberPolygonClass pRubberBand3 = new RubberPolygonClass(); //在屏幕上画个多边形 pPolygon = pRubberBand3.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPolygon; pgonElemnt.Geometry = pPolygon; //把这个多边形转成Element pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer; //把地图的当前view作为图片的容器 //pGraphicsContainer.DeleteAllElements (); pGraphicsContainer.AddElement(pgonElemnt, 0); //把刚刚的element转到容器上 axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); break; } }
///<summary> ///Create a polyline geometry object using the RubberBand.TrackNew method when a user click the mouse on the map control. ///</summary> ///<param name="activeView">An ESRI.ArcGIS.Carto.IActiveView interface that will user will interace with to draw a polyline.</param> ///<returns>An ESRI.ArcGIS.Geometry.IPolyline interface that is the polyline the user drew</returns> ///<remarks>Double click the left mouse button to end tracking the polyline.</remarks> public IPolyline GetPolylineFromMouseClicks(IActiveView activeView) { IScreenDisplay screenDisplay = activeView.ScreenDisplay; IRubberBand rubberBand = new RubberLineClass(); IGeometry geometry = rubberBand.TrackNew(screenDisplay, null); IPolyline polyline = (IPolyline)geometry; return polyline; }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { IScreenDisplay pScr = m_pActiveView.ScreenDisplay; //跟踪画线 IRubberBand pRB = new RubberLineClass(); m_pGeoTrack = pRB.TrackNew(pScr, null); if ((m_pGeoTrack as IPointCollection).PointCount != 2) { XtraMessageBox.Show("请使用鼠标制定两点确定扯旗的管线"); return; } Element.DeleteElement(m_pActiveView.GraphicsContainer, "cq"); Element.AddGraphics(m_pActiveView.GraphicsContainer, m_pGeoTrack, GetDefaultSymbol(esriGeometryType.esriGeometryPolyline), "dmx"); IElement pElement = Element.GetElementByName(m_pMapControl.ActiveView.GraphicsContainer, "cq"); if (pElement != null) { m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } IFeature pFeature; IGeometry pGeo; IGeometry pPipeLineGeo; IFeatureClass pFeatureClass; IFeatureCursor pFeaCur; ITopologicalOperator pTopo; string classify = ""; string startNo = ""; string endNo = ""; string material = ""; string coverstyle = ""; string diameter = ""; string road = ""; double distance; m_IntersectPipes = new List <IntersectPipe>(); string[] sysFields = new string[] { "Classify", "StartNo", "EndNo", "Material", "CoverStyle", "Diameter", "Road" }; string[] fields = new string[] { "类别", "起点号", "终点号", "材质", "埋设方式", "管径", "所在道路" }; try { foreach (MajorClass mc in LogicDataStructureManage2D.Instance.GetAllMajorClass()) { WaitForm.Start("正在查询...", "请稍后"); string[] arrFc2DId = mc.Fc2D.Split(';');//将二级大类所对应的要素类ID转换为数组 if (arrFc2DId == null) { continue; } foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible2D) { continue; } foreach (string fc2DId in arrFc2DId) //遍历二级子类所对应的要素类ID { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); //根据要素类ID得到DF2DFC if (dffc == null) { continue; } FacilityClass fcc = dffc.GetFacilityClass(); if (fcc.Name != "PipeLine") { continue; } IFeatureLayer fl = dffc.GetFeatureLayer(); ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = m_pGeoTrack; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.WhereClause = "SMSCODE = '" + sc.Name + "'"; IFeatureClass fc = dffc.GetFeatureClass(); pFeaCur = fc.Search(pSpatialFilter, false); while ((pFeature = pFeaCur.NextFeature()) != null) { foreach (string field in sysFields) { DFDataConfig.Class.FieldInfo fi = fcc.GetFieldInfoBySystemName(field); if (fi == null) { continue; } int index = fc.Fields.FindField(fi.Name); object obj = pFeature.get_Value(index); switch (field) { case "Classify": classify = obj.ToString(); break; case "StartNo": startNo = obj.ToString(); break; case "EndNo": endNo = obj.ToString(); break; case "Material": material = obj.ToString(); break; case "CoverStyle": coverstyle = obj.ToString(); break; case "Diameter": diameter = obj.ToString(); break; case "Road": road = obj.ToString(); break; } } IPolyline pline = m_pGeoTrack as IPolyline; IPoint point1 = pline.ToPoint; ITopologicalOperator topo = pFeature.Shape as ITopologicalOperator; IGeometry geo = topo.Intersect(m_pGeoTrack, esriGeometryDimension.esriGeometry0Dimension); IPointCollection pointCol = geo as IPointCollection; IPoint point2 = pointCol.get_Point(pointCol.PointCount - 1); distance = GetDistanceOfTwoPoints(point1, point2); IntersectPipe interPipe = new IntersectPipe(pFeature, fl, distance, classify, startNo, endNo, material, coverstyle, diameter, road); m_IntersectPipes.Add(interPipe); } } } } if (m_IntersectPipes.Count == 0) { return; } List <IntersectPipe> orderList = m_IntersectPipes.OrderBy(i => i.Distance).ToList <IntersectPipe>(); DrawPipeLabels(); int n = 0; foreach (IntersectPipe interPipe in orderList) { WaitForm.SetCaption("正在输出属性,请稍后..."); DrawPipeInfo(interPipe, n); ++n; } WaitForm.Stop(); } catch (System.Exception ex) { WaitForm.Stop(); } }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { IScreenDisplay pScr = m_pActiveView.ScreenDisplay; if (m_pArrPipes.Count != 0) { m_pArrPipes.Clear(); //清除上一步操作的要素 } IRubberBand pRB = new RubberLineClass(); Geo = pRB.TrackNew(pScr, null); Element.DeleteElement(m_pActiveView.GraphicsContainer, "gx"); Element.AddGraphics(m_pActiveView.GraphicsContainer, Geo, GetDefaultSymbol(esriGeometryType.esriGeometryPolyline), "dmx"); IElement pElement = Element.GetElementByName(m_pMapControl.ActiveView.GraphicsContainer, "gx"); if (pElement != null) { m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } base.OnMouseDown(button, shift, x, y, mapX, mapY); //得到相交的管线 GetPipeInfo(); if (m_pArrPipes.Count != 1) { XtraMessageBox.Show("请重新获取单个管线"); m_pArrPipes.Clear(); return; } if (m_pArrText.Count > 0 && m_pArrFeature.Count > 0) { m_pArrText.Clear(); m_pArrFeature.Clear(); } for (int i = 0; i < m_pArrPipes.Count; i++) { pFeature = m_pArrPipes[i] as IFeature; if (pFeature == null) { return; } if (pFeature.get_Value(pFeature.Fields.FindField(fi.Name)).ToString() != "") { str1 = pFeature.get_Value(pFeature.Fields.FindField(fi.Name)).ToString(); m_pArrText.Add(fi.SystemAlias); m_pArrFeature.Add(str1); } if (pFeature.get_Value(pFeature.Fields.FindField(fi1.Name)).ToString() != "") { str2 = pFeature.get_Value(pFeature.Fields.FindField(fi1.Name)).ToString(); m_pArrText.Add(fi1.SystemAlias); m_pArrFeature.Add(str2); } if (pFeature.get_Value(pFeature.Fields.FindField(fi2.Name)).ToString() != "") { str3 = pFeature.get_Value(pFeature.Fields.FindField(fi2.Name)).ToString(); m_pArrText.Add(fi2.SystemAlias); m_pArrFeature.Add(str3); } if (pFeature.get_Value(pFeature.Fields.FindField(fi3.Name)).ToString() != "") { str4 = pFeature.get_Value(pFeature.Fields.FindField(fi3.Name)).ToString(); m_pArrText.Add(fi3.SystemAlias); m_pArrFeature.Add(str4); } if (pFeature.get_Value(pFeature.Fields.FindField(fi4.Name)).ToString() != "") { str5 = pFeature.get_Value(pFeature.Fields.FindField(fi4.Name)).ToString(); m_pArrText.Add(fi4.SystemAlias); m_pArrFeature.Add(str5); } if (pFeature.get_Value(pFeature.Fields.FindField(fi5.Name)).ToString() != "") { str6 = pFeature.get_Value(pFeature.Fields.FindField(fi5.Name)).ToString(); m_pArrText.Add(fi5.SystemAlias); m_pArrFeature.Add(str6); } if (pFeature.get_Value(pFeature.Fields.FindField(fi6.Name)).ToString() != "") { str7 = pFeature.get_Value(pFeature.Fields.FindField(fi6.Name)).ToString(); m_pArrText.Add(fi6.SystemAlias); m_pArrFeature.Add(str7); } } //管线属性标注 DrawPipeLabels(); }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { interPoints = new List <IntersectPoint>(); DF2DApplication app = DF2DApplication.Application; bool ready = true; if (app == null || app.Current2DMapControl == null) { return; } m_ActiveView = app.Current2DMapControl.ActiveView; IScreenDisplay m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay; IGeometry pGeo = null; IPointCollection pIntersectPC; IPointCollection pLandSufPC; double length = 0.0; try { if (button == 1) { ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pColor.Blue = 0; pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; IRubberBand pRubberBand; pRubberBand = new RubberLineClass(); IGeometry pLine; pLine = pRubberBand.TrackNew(m_Display, null); object symbol = pLineSym as object; app.Current2DMapControl.DrawShape(pLine, ref symbol); WaitForm.Start("正在查询...", "请稍后"); //pGeo = PublicFunction.DoBuffer(pLine,PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate)); pGeo = pLine; if (pGeo == null) { return; } length = (pGeo as IPolyline).Length; if (ready) { double distemp = 0.0; IPoint tempPoint = null; foreach (LogicGroup lg in LogicDataStructureManage.Instance.RootLogicGroups) { foreach (MajorClass mc in lg.MajorClasses) { foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible2D) { continue; } string[] arrFc2DId = mc.Fc2D.Split(';'); if (arrFc2DId == null) { continue; } IFeatureCursor pFeatureCursor = null; IFeature pFeature = null; foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass facc = dffc.GetFacilityClass(); if (facc.Name != "PipeLine") { continue; } if (fc == null || pGeo == null) { continue; } ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = pGeo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.WhereClause = "SMSCODE = '" + sc.Name + "'"; int count = fc.FeatureCount(pSpatialFilter); if (count == 0) { continue; } pFeatureCursor = fc.Search(pSpatialFilter, false); string fcName = mc.Name; if (pFeatureCursor == null) { continue; } double distance; while ((pFeature = pFeatureCursor.NextFeature()) != null) { IGeometry pPipeLineGeo = pFeature.Shape; ITopologicalOperator pTopo = pPipeLineGeo as ITopologicalOperator; IGeometry geo = pTopo.Intersect(pGeo, esriGeometryDimension.esriGeometry0Dimension); IPoint intersect; if (geo is IPoint) { double distanceF = double.MaxValue; intersect = geo as IPoint; if (pGeo is IPolyline) { IPolyline line = pGeo as IPolyline; IPoint fromPoint = line.FromPoint; distanceF = GetDistanceOfTwoPoints(intersect, fromPoint); } if (distemp == 0.0) { distance = distanceF; distemp = distanceF; } else { distance = Math.Abs(distanceF - distemp); } IntersectPoint interPoint = new IntersectPoint(pFeature, intersect, fcName, distance, distanceF); interPoints.Add(interPoint); } if (geo is IPointCollection) { IPointCollection geoCol = geo as IPointCollection; for (int i = 0; i < geoCol.PointCount; i++) { intersect = geoCol.get_Point(i) as IPoint; double distanceF = double.MaxValue; if (pGeo is IPolyline) { IPolyline line = pGeo as IPolyline; IPoint fromPoint = line.FromPoint; IPoint toPoint = line.ToPoint; if (distemp == 0.0) { double distance1 = GetDistanceOfTwoPoints(intersect, fromPoint); double distance2 = GetDistanceOfTwoPoints(intersect, toPoint); distanceF = distance1 < distance2 ? distance1 : distance2; tempPoint = distance1 < distance2 ? fromPoint:toPoint; } else { if (tempPoint == null) { return; } distanceF = GetDistanceOfTwoPoints(intersect, tempPoint); } } if (distemp == 0.0) { distance = distanceF; distemp = distanceF; } else { distance = Math.Abs(distanceF - distemp); } IntersectPoint interPoint = new IntersectPoint(pFeature, intersect, fcName, distance, distanceF); interPoints.Add(interPoint); } } } } } } } } } DrawPipeTransection(interPoints, length); } catch (System.Exception ex) { } }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; this._dict.Clear(); bool ready = true; if (app == null || app.Current2DMapControl == null || app.Workbench == null) { return; } app.Workbench.SetMenuEnable(true); m_ActiveView = app.Current2DMapControl.ActiveView; IScreenDisplay m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay; IGeometry pGeo = null; try { if (button == 1) { ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pColor.Blue = 0; pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; //pColor = Convert.ToUInt32(SystemInfo.Instance.LineColor, 16); IRubberBand pRubberBand; pRubberBand = new RubberLineClass(); IGeometry pLine; pLine = pRubberBand.TrackNew(m_Display, null); //IPolyline pLine = app.Current2DMapControl.TrackLine() as IPolyline; object symbol = pLineSym as object; app.Current2DMapControl.DrawShape(pLine, ref symbol); WaitForm.Start("正在查询...", "请稍后"); //if (GlobalValue.System_Selection_Environment(m_ActiveView).CombinationMethod == 0)//new selection //{ // this.m_ActiveView.FocusMap.ClearSelection(); //} pGeo = PublicFunction.DoBuffer(pLine, PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate)); if (pGeo == null) { return; } //m_ActiveView.FocusMap.SelectByShape(pGeo, GlobalValue.System_Selection_Environment(m_ActiveView), false); //if (m_ActiveView.FocusMap.SelectionCount > 0) //{ // ready = true; // m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); //} //else //{ // m_ActiveView.Refresh(); //} if (ready) { //foreach (LogicGroup lg in LogicDataStructureManage2D.Instance.RootLogicGroups) //{ foreach (MajorClass mc in FrmMajorClass.Instance.MajorClasses) { foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible2D) { continue; } string[] arrFc2DId = mc.Fc2D.Split(';'); if (arrFc2DId == null) { continue; } IFeatureCursor pFeatureCursor = null; IFeature pFeature = null; foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass facc = dffc.GetFacilityClass(); if (facc.Name != "PipeLine") { continue; } if (fc == null || pGeo == null) { continue; } ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = pGeo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; string whereClause = UpOrDown.DecorateWhereClasuse(fc) + mc.ClassifyField + " = '" + sc.Name + "'"; pSpatialFilter.WhereClause = whereClause; pFeatureCursor = fc.Search(pSpatialFilter, false); if (pFeatureCursor == null) { continue; } DataTable dt = new DataTable(); dt.TableName = facc.Name; DataColumn oidcol = new DataColumn(); oidcol.ColumnName = "oid"; oidcol.Caption = "ID"; dt.Columns.Add(oidcol); foreach (DFDataConfig.Class.FieldInfo fitemp in facc.FieldInfoCollection) { if (!fitemp.CanQuery) { continue; } DataColumn col = new DataColumn(); col.ColumnName = fitemp.Name; col.Caption = fitemp.Alias; dt.Columns.Add(col); } while ((pFeature = pFeatureCursor.NextFeature()) != null) { DataRow dtRow = dt.NewRow(); dtRow["oid"] = pFeature.get_Value(pFeature.Fields.FindField("OBJECTID")); foreach (DataColumn col in dt.Columns) { int index1 = pFeature.Fields.FindField(col.ColumnName); if (index1 < 0) { continue; } object obj1 = pFeature.get_Value(index1); string str = ""; if (obj1 != null) { IField field = pFeature.Fields.get_Field(index1); switch (field.Type) { case esriFieldType.esriFieldTypeBlob: case esriFieldType.esriFieldTypeGeometry: case esriFieldType.esriFieldTypeRaster: continue; case esriFieldType.esriFieldTypeDouble: double d; if (double.TryParse(obj1.ToString(), out d)) { str = d.ToString("0.00"); } break; default: str = obj1.ToString(); break; } } dtRow[col.ColumnName] = str; } dt.Rows.Add(dtRow); } if (dt.Rows.Count > 0) { this._dict.Add(sc.Name, dt); } } } } } } WaitForm.Stop(); try { this._uPanel = new UIDockPanel("查询结果", "查询结果", this.Location, this._width, this._height); this._dockPanel = FloatPanelManager.Instance.Add(ref this._uPanel, DockingStyle.Right); this._dockPanel.Visibility = DockVisibility.Visible; this._dockPanel.FloatSize = new System.Drawing.Size(this._width, this._height); this._dockPanel.Width = this._width; this._dockPanel.Height = this._height; if (this._ucPropInfo2D == null) { this._ucPropInfo2D = new UCPropertyInfo2D(); } this._ucPropInfo2D.Dock = System.Windows.Forms.DockStyle.Fill; this._uPanel.RegisterEvent(new PanelClose(this.Close)); this._dockPanel.Controls.Add(this._ucPropInfo2D); this._ucPropInfo2D.Init(); this._ucPropInfo2D.SetPropertyInfo(this._dict); } catch { } //} } catch { } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button != 1) { return; } IWorkspace workspace = null; #region……分割面 //根据已选择的要分割的要素的类型绘制分割线 if (((IFeatureLayer)mLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) {//分割线的样式 IScreenDisplay pScreenDisplay = pMapControl.ActiveView.ScreenDisplay; ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass(); IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 255; pLineSymbol.Color = pRgbColor; IRubberBand pRubberBand = new RubberLineClass(); IPolyline pPolyline = (IPolyline)pRubberBand.TrackNew(pScreenDisplay, (ISymbol)pLineSymbol); pScreenDisplay.StartDrawing(pScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); pScreenDisplay.SetSymbol((ISymbol)pLineSymbol); pScreenDisplay.DrawPolyline(pPolyline); pScreenDisplay.FinishDrawing(); //清理将被分割的要素 ITopologicalOperator pTopoOpo; pTopoOpo = pPolyline as ITopologicalOperator; pTopoOpo.Simplify();//确保几何体的拓扑正确 //开始编辑 IFeatureLayer featureLayer = mLayer as IFeatureLayer; IFeatureClass pFeatureClass = featureLayer.FeatureClass; IEngineEditor mEngineEditor = mEngineEditor = new EngineEditorClass(); if (pFeatureClass.FeatureDataset != null) { workspace = pFeatureClass.FeatureDataset.Workspace; mEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned; mEngineEditor.StartEditing(workspace, mMap); ((IEngineEditLayers)mEngineEditor).SetTargetLayer(featureLayer, -1); mEngineEditor.StartOperation(); } //分割方法 SplitPolygon(pFeatureClass, pPolyline); ReBackStates();//刷新返回修改工具 pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, pMapControl.ActiveView.Extent); // mEngineEditor.StopEditing(true); } #endregion #region……鼠标画线分割线 //根据分割要素的类型绘制分割线 if (((IFeatureLayer)mLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { IScreenDisplay pScreenDisplay = pMapControl.ActiveView.ScreenDisplay; ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass(); IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 255; pLineSymbol.Color = pRgbColor; IRubberBand pRubberBand = new RubberLineClass(); IPolyline pPolyline = (IPolyline)pRubberBand.TrackNew(pScreenDisplay, (ISymbol)pLineSymbol); pScreenDisplay.StartDrawing(pScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); pScreenDisplay.SetSymbol((ISymbol)pLineSymbol); pScreenDisplay.DrawPolyline(pPolyline); pScreenDisplay.FinishDrawing(); // mEngineEditor.StartOperation();//开启编辑 IFeatureLayer featureLayer = mLayer as IFeatureLayer; IFeatureClass pFeatureClass = featureLayer.FeatureClass; IEngineEditor mEngineEditor = mEngineEditor = new EngineEditorClass(); if (pFeatureClass.FeatureDataset != null) { workspace = pFeatureClass.FeatureDataset.Workspace; mEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned; mEngineEditor.StartEditing(workspace, mMap); ((IEngineEditLayers)mEngineEditor).SetTargetLayer(featureLayer, -1); mEngineEditor.StartOperation(); } ISelectionSet pSelectionSet = pFeatureClass.Select(null, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, workspace); //分割方法 SplitPolyline(pSelectionSet, pPolyline); ReBackStates(); pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, pMapControl.ActiveView.Extent); } #endregion if (workspace != null) { mEngineEditor.StopEditing(true); } //mEngineEditor.StopOperation("ControlToolsEditing_CreateNewFeatureTask"); }
private void mapCtlMain_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (this.m_rasterMeasureDis) //距离量算 { IPolyline polyline = null; IGraphicsContainer graCont = (IGraphicsContainer)mapCtlMain.ActiveView; if (e.button == 1) { double Dis = 0; IRubberBand rubberPoly = new RubberLineClass(); polyline = (IPolyline)rubberPoly.TrackNew(mapCtlMain.ActiveView.ScreenDisplay, null); IElement elem; if (polyline != null) { elem = new LineElementClass(); elem.Geometry = polyline; graCont.AddElement(elem, 0); } mapCtlMain.ActiveView.Refresh(); Dis = polyline.Length; Dis = Dis / 1000; frmDis frmdis = new frmDis("测量长度是:" + Dis.ToString("f3") + "公里", "距离量测"); frmdis.ShowDialog(); //MessageBox.Show("测量长度是:" + Dis.ToString("f3") + "公里", "确认"); graCont = (IGraphicsContainer)mapCtlMain.ActiveView; graCont.DeleteAllElements(); mapCtlMain.ActiveView.Refresh(); } } if (this.m_rasterMeasureArea) //面积量算 { double Area = 0; double Area1 = 0; ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); IRgbColor color = new RgbColorClass(); color.Red = 0; color.Green = 0; color.Blue = 225; lineSymbol.Width = 1; lineSymbol.Color = color; lineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; //Dim pPolySymbol As ISimpleFillSymbol ISimpleFillSymbol polySymbol = new SimpleFillSymbolClass(); polySymbol.Color = color; polySymbol.Outline = lineSymbol; polySymbol.Style = esriSimpleFillStyle.esriSFSHollow; //Dim pSymbol As ISymbol ISymbol symbol = (ISymbol)polySymbol; //设置结束 IGraphicsContainer graCont = (IGraphicsContainer)mapCtlMain.ActiveView; IRubberBand rubberPoly = new RubberPolygonClass(); IPolygon polygon = (IPolygon)rubberPoly.TrackNew(mapCtlMain.ActiveView.ScreenDisplay, symbol); IElement elem; if (polygon != null) { elem = new PolygonElementClass(); elem.Geometry = polygon; IFillShapeElement fillShapeElement = (IFillShapeElement)elem; fillShapeElement.Symbol = (IFillSymbol)symbol; graCont.AddElement(elem, 0); } mapCtlMain.ActiveView.Refresh(); IArea area = (IArea)polygon; Area = Math.Abs(area.Area) / 1000000; Area1 = Area * 100; frmDis frmdis = new frmDis("测量面积是:" + Area.ToString("f3") + "平方公里" + "\n (合" + Area1.ToString("f3") + "公顷)","面积量测"); frmdis.ShowDialog(); //MessageBox.Show("测量面积是:" + Area.ToString("f3") + "平方公里" + "(合" + Area1.ToString("f3") + "公顷)", "确认"); graCont = (IGraphicsContainer)mapCtlMain.ActiveView; graCont.DeleteAllElements(); mapCtlMain.ActiveView.Refresh(); } if (this.m_bEditNode) { m_editor.EditFeatureMouseDown(e.x, e.y); } if(this.m_out) { IFeatureLayer featureLayer = this.mapCtlMain.get_Layer(0) as IFeatureLayer; IFeatureClass featureClass = featureLayer.FeatureClass; IPoint point = mapCtlMain.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); IGeometry geometry = point as IGeometry; ITopologicalOperator pTopo = geometry as ITopologicalOperator; IGeometry buffer = pTopo.Buffer(200); geometry = buffer.Envelope as IGeometry; ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = geometry; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; spatialFilter.GeometryField = featureClass.ShapeFieldName; IQueryFilter filter = spatialFilter as IQueryFilter; IFeatureCursor cursor = featureClass.Search(filter, false); IFeature pfeature = cursor.NextFeature(); if (pfeature!= null) { frmTip tip = new frmTip(pfeature.get_Value(3).ToString(), pfeature.get_Value(4).ToString(),this.m_oraCmd); tip.ShowDialog(); } } }
private void CutSelectedPolygon() { if (m_selectedFeature == null) { MessageBox.Show("请先选择要分割的面要素!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); m_toolPhase = ToolPhase.SelectFeature; return; } //在屏幕上绘制用于分割的线要素 IScreenDisplay screenDisplay = m_activeView.ScreenDisplay; ISimpleLineSymbol sym = new SimpleLineSymbolClass(); IRgbColor color = new RgbColorClass(); color.Red = 255; color.Green = 128; color.Blue = 128; sym.Color = color; sym.Style = esriSimpleLineStyle.esriSLSSolid; sym.Width = 2; IRubberBand cutBand = new RubberLineClass(); IGeometry cutGeometry = cutBand.TrackNew(screenDisplay, sym as ISymbol); screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); screenDisplay.SetSymbol(sym as ISymbol); screenDisplay.DrawPolyline(cutGeometry); screenDisplay.FinishDrawing(); IFeatureClass featureClass = m_selectedFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } //分割选择的面要素 if (cutGeometry.IsEmpty == true) { return; } try { workspaceEdit.StartEditOperation(); IFeatureEdit featureEdit = m_selectedFeature as IFeatureEdit; //分割产生新的面要素 ISet newFeaturesSet = featureEdit.Split(cutGeometry); //亮闪新要素 if (newFeaturesSet != null) { newFeaturesSet.Reset(); for (int featureCount = 0; featureCount < newFeaturesSet.Count; featureCount++) { IFeature newFeature = newFeaturesSet.Next() as IFeature; FlashGeometry(newFeature.Shape, 3, 20); } } workspaceEdit.StopEditOperation(); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); //SysLogHelper.WriteOperationLog("要素分割错误", ex.Source, "数据编辑"); MessageBox.Show("分割面要素失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent); m_toolPhase = ToolPhase.SelectFeature; }