//双击则创建该线,并弹出缓冲窗体 public override void OnDblClick() { //获取折线 并获取当前视图的屏幕显示 if (m_pNewPolygonFeedback == null) { return; } IPolygon pPolygon = m_pNewPolygonFeedback.Stop(); m_pNewPolygonFeedback = null; //不存在,为空。尺寸不够均退出 if (pPolygon == null || pPolygon.IsEmpty) { return; } if (pPolygon.Envelope.Width < 0.01 || pPolygon.Envelope.Height < 0.01) { return; } //创建Topo对象,简化后统一空间参考 ITopologicalOperator pTopo = (ITopologicalOperator)pPolygon; pTopo.Simplify(); pPolygon.Project(m_MapControl.Map.SpatialReference); if (m_frmQuery == null) { m_frmQuery = new frmQuery(m_MapControl, m_enumQueryMode); m_frmQuery.Owner = m_mainFrm; m_frmQuery.FormClosed += new FormClosedEventHandler(frmQuery_FormClosed); } frmBufferSet pFrmBufSet = new frmBufferSet(pPolygon as IGeometry, m_MapControl.Map, m_frmQuery); IGeometry pGeometry = pFrmBufSet.GetBufferGeometry(); if (pGeometry == null || pFrmBufSet.Res == false) { return; } // m_frmQuery.Show(); //m_frmQuery.FillData(m_MapControl.ActiveView.FocusMap, pGeometry); _QuerBar.m_pMapControl = m_MapControl; _QuerBar.EmergeQueryData(m_MapControl.ActiveView.FocusMap, pGeometry, pFrmBufSet.pesriSpatialRelEnum); try { DevComponents.DotNetBar.Bar pBar = _QuerBar.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 { } m_frmQuery = null; }
/// <summary> /// 创建要素 /// </summary> /// <param name="pGeometry"></param> private void CreateFeature(IGeometry pGeometry) { try { if (m_EngineEditLayers == null) return; IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer; if (pFeatLyr == null) return; IFeatureClass pFeatCls = pFeatLyr.FeatureClass; if (pFeatCls == null) return; if (m_EngineEditor == null) return; if (pGeometry == null) return; ITopologicalOperator pTop = pGeometry as ITopologicalOperator; pTop.Simplify(); IGeoDataset pGeoDataset = pFeatCls as IGeoDataset; if (pGeoDataset.SpatialReference != null) { pGeometry.Project(pGeoDataset.SpatialReference); } m_EngineEditor.StartOperation(); IFeature pFeature = null; pFeature = pFeatCls.CreateFeature(); pFeature.Shape = SupportZMFeatureClass.ModifyGeomtryZMValue(pFeatCls, pGeometry); pFeature.Store(); m_EngineEditor.StopOperation("添加要素"); m_Map.SelectFeature(pFeatLyr, pFeature); m_activeView.Refresh(); } catch (Exception ex) { } }
void ESRI.ArcGIS.Display.IMarkerMask.QueryMarkerMask(int hDC, ITransformation Transform, IGeometry Geometry, IPolygon Boundary) { if (!(Geometry == null | Boundary == null)) { if (Transform is IDisplayTransformation) { if (Geometry is IPoint) { Boundary.SetEmpty(); IPoint geometry = Geometry as IPoint; IDisplayTransformation transform = (IDisplayTransformation)Transform; this.QueryBoundsFromGeom(hDC, ref transform, ref Boundary, ref geometry); ITopologicalOperator boundary = Boundary as ITopologicalOperator; if (!boundary.IsKnownSimple) { if (!boundary.IsSimple) { boundary.Simplify(); } } } } } }
public static IGeometry GetExample3() { const double FromZ = 0; const double ToZ = 9.5; //Extrusion: Square Shaped 2D Polygon Extruded To Generate 3D Building Via ConstructExtrudeFromTo() IPointCollection polygonPointCollection = new PolygonClass(); polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-2, 2), ref _missing, ref _missing); polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(2, 2), ref _missing, ref _missing); polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(2, -2), ref _missing, ref _missing); polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-2, -2), ref _missing, ref _missing); IPolygon polygon = polygonPointCollection as IPolygon; polygon.Close(); IGeometry polygonGeometry = polygonPointCollection as IGeometry; ITopologicalOperator topologicalOperator = polygonGeometry as ITopologicalOperator; topologicalOperator.Simplify(); IConstructMultiPatch constructMultiPatch = new MultiPatchClass(); constructMultiPatch.ConstructExtrudeFromTo(FromZ, ToZ, polygonGeometry); return(constructMultiPatch as IGeometry); }
/// <summary> /// 鼠标移动时运行 /// </summary> /// <param name="movePT">鼠标地图点</param> public void OnMouseMoveRun(IPoint movePT) { if (polygonFeedback != null) { polygonFeedback.MoveTo(movePT); } // 点集合 IPointCollection pointColTemp = new Polygon(); for (int i = 0; i < pointCollection.PointCount; i++) { pointColTemp.AddPoint(pointCollection.get_Point(i), Type.Missing, Type.Missing); } // 添加当前点 pointColTemp.AddPoint(movePT); if (pointColTemp.PointCount < 3) { return; } // 获得图形 IPolygon polygon = pointColTemp as IPolygon; if (polygon != null) { polygon.Close(); IGeometry geo = polygon as IGeometry; ITopologicalOperator topo = geo as ITopologicalOperator; topo.Simplify(); geo.Project(mapControl.SpatialReference); // 获得面积 IArea area = geo as IArea; totalArea = area.Area; } }
/// <summary> /// 创建要素 /// </summary> /// <param name="pGeometry"></param> private void CreateFeature(IGeometry pGeometry) { try { if (m_EngineEditLayers == null) { return; } IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer; if (pFeatLyr == null) { return; } IFeatureClass pFeatCls = pFeatLyr.FeatureClass; if (pFeatCls == null) { return; } if (m_EngineEditor == null) { return; } if (pGeometry == null) { return; } ITopologicalOperator pTop = pGeometry as ITopologicalOperator; pTop.Simplify(); IGeoDataset pGeoDataset = pFeatCls as IGeoDataset; if (pGeoDataset.SpatialReference != null) { pGeometry.Project(pGeoDataset.SpatialReference); } m_EngineEditor.StartOperation(); IFeature pFeature = null; pFeature = pFeatCls.CreateFeature(); IZAware ipZAware = pGeometry as IZAware; if (ipZAware.ZAware == true) { ipZAware.ZAware = false; } if (pGeometry.GeometryType == esriGeometryType.esriGeometryPoint) { pFeature.Shape = pGeometry; } else { pFeature.Shape = SupportZMFeatureClass.ModifyGeomtryZMValue(pFeatCls, pGeometry); } pFeature.Store(); m_EngineEditor.StopOperation("添加要素"); m_Map.SelectFeature(pFeatLyr, pFeature); m_activeView.Refresh(); } catch (Exception ex) { //SysLogHelper.WriteOperationLog("要素添加错误", ex.Source, "数据编辑"); } }
//得到与线相交地物的交叉点 private IPointCollection GetIntersection(IGeometry pGeo, IPolyline pPolyline) { ITopologicalOperator topoOper = (ITopologicalOperator)pGeo; topoOper.Simplify(); IGeometry pResultGeo = topoOper.Intersect(pPolyline, esriGeometryDimension.esriGeometry0Dimension); if (pResultGeo == null) { return(null); } if (pResultGeo is IPointCollection) { IPointCollection pPtCol = pResultGeo as IPointCollection; if (pPtCol.PointCount > 0) { return(pPtCol); } else { return(null); } } return(null); }
/// <summary> /// 计算每个数据点相邻的数据点,找出核心点 /// </summary> private void FindNeighborPoints() { for (int i = 0; i < m_DBSCANPnts.Count; i++) { List <DBSCANPoint> neighborPnts = new List <DBSCANPoint>(); IPoint point = m_DBSCANPnts[i].GetPoint(); ITopologicalOperator topologicalOperator = point as ITopologicalOperator; IGeometry pointBuffer = topologicalOperator.Buffer(m_dEps);//缓冲距离 topologicalOperator.Simplify(); ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = pointBuffer; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; IFeatureLayer featurelayer = m_dataInfo.GetInputLayer() as IFeatureLayer; IFeatureCursor featureCursor = featurelayer.FeatureClass.Search(spatialFilter, false); IFeature feature = featureCursor.NextFeature(); while (feature != null) { neighborPnts.Add(GetDBSCANPointByOID(feature.OID)); feature = featureCursor.NextFeature(); } m_DBSCANPnts[i].SetNeighborPoints(neighborPnts); //标记核心点 if (m_DBSCANPnts[i].GetNeighborPoints().Count >= m_nMinPts) { m_DBSCANPnts[i].SetPointType(1); } System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor); } }
public static void ExtractSpecifyHRegFeatures(IWorkspaceName iworkspaceName_0, IMap imap_0, IGeometry igeometry_0, IMap imap_1) { (new SelectionEnvironment()).CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; IWorkspace workspace = (iworkspaceName_0 as IName).Open() as IWorkspace; for (int i = imap_0.LayerCount - 1; i >= 0; i--) { ILayer layer = imap_0.Layer[i]; if ((!layer.Visible ? false : layer is IFeatureLayer)) { try { IEnvelope areaOfInterest = layer.AreaOfInterest; ITopologicalOperator topologicalOperator = (ITopologicalOperator)((IClone)igeometry_0).Clone(); topologicalOperator.Simplify(); if (topologicalOperator.IsSimple) { topologicalOperator.Clip(areaOfInterest); } } catch (Exception exception) { } if (!igeometry_0.IsEmpty) { ClipHelper.ExtractSelectFeatureFormFeatureCursor(layer, ClipHelper.searchFeatureFormLayer(layer, igeometry_0), (IFeatureWorkspace)workspace, igeometry_0, imap_1); } } } Marshal.ReleaseComObject(workspace); workspace = null; }
/// <summary> /// 多部分(多外环)的多边形转成多个单部分的多边形 /// </summary> /// <param name="polygon"></param> /// <returns></returns> public static IPolygon[] MultiPartToSinglePart(this IPolygon4 polygon) { List <IPolygon> polygons = new List <IPolygon>(); //外部环 IGeometryBag exteriorRingGeometryBag = polygon.ExteriorRingBag; IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection; for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++) { IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i); IRing ring = exteriorRingGeometry as IRing; ring.Close(); IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(ring); //内部环 IGeometryBag interiorRingGeometryBag = polygon.get_InteriorRingBag(exteriorRingGeometry as IRing); IGeometryCollection interiorRingGeometryCollection = interiorRingGeometryBag as IGeometryCollection; for (int k = 0; k < interiorRingGeometryCollection.GeometryCount; k++) { IGeometry interiorRingGeometry = interiorRingGeometryCollection.get_Geometry(k); IRing ring2 = interiorRingGeometry as IRing; ring2.Close(); pGeometryColl.AddGeometry(ring2); } ITopologicalOperator pTopological = pGeometryColl as ITopologicalOperator; pTopological.Simplify(); IPolygon p = pGeometryColl as IPolygon; polygons.Add(p); } return(polygons.ToArray()); }
/// <summary> /// 创建指定图形的缓冲区 /// </summary> /// <param name="shape">要缓冲区的图形</param> /// <param name="tolerance">缓冲间隔</param> /// <returns>生成的缓冲区图形</returns> public static IGeometry GetBuffer(this IGeometry shape, double tolerance) { ITopologicalOperator topo = shape as ITopologicalOperator; if (topo == null || (tolerance < 0 && shape.GeometryType != esriGeometryType.esriGeometryPolygon)) { return(null); } if (!topo.IsSimple)//若是不是简单图形,进行简化处理 { topo.Simplify(); } int iTry = 0;//测验测验10次 IGeometry buffer = null; while (buffer == null && iTry <= 10) { try { //若是调用不成功,将缓冲间隔加0.01倍再试(若是第10次成功,则缓冲间隔比本来大了0.09倍) //若是对缓冲间隔请求更严格,可以削减增量的倍数 //按照测试经验,一般最多测验测验三次就可以成功 buffer = topo.Buffer(tolerance * (1.0 + 0.01 * iTry)); } catch { buffer = null; iTry = iTry + 1; } } return(buffer); }
public static IGeometry GetExample2() { const double FromZ = -0.1; const double ToZ = -8; //Extrusion: Multiple Point 2D Polyline Extruded To Generate 3D Wall Via ConstructExtrudeFromTo() IPointCollection polylinePointCollection = new PolylineClass(); polylinePointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-10, -10), ref _missing, ref _missing); polylinePointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-8, -7), ref _missing, ref _missing); polylinePointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-5, -5), ref _missing, ref _missing); polylinePointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-3, -2), ref _missing, ref _missing); polylinePointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(0, 0), ref _missing, ref _missing); polylinePointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(3, 2), ref _missing, ref _missing); polylinePointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(5, 5), ref _missing, ref _missing); polylinePointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(8, 7), ref _missing, ref _missing); polylinePointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(10, 10), ref _missing, ref _missing); IGeometry polylineGeometry = polylinePointCollection as IGeometry; ITopologicalOperator topologicalOperator = polylineGeometry as ITopologicalOperator; topologicalOperator.Simplify(); IConstructMultiPatch constructMultiPatch = new MultiPatchClass(); constructMultiPatch.ConstructExtrudeFromTo(FromZ, ToZ, polylineGeometry); return(constructMultiPatch as IGeometry); }
/// 合并列表中所有多边形 /// </summary> /// <param name="orifeature">保留源对象</param> /// <param name="geolist">图形列表</param> /// <returns></returns> public void CreatePolygonFromExistingGeometries(IFeatureLayer lyr, IFeature orifeature, List <IGeometry> geolist) { int i = 0; IGeometry geometry = null; IFeatureClass Featureclass = lyr.FeatureClass; IWorkspaceEdit workspace = (IWorkspaceEdit)(Featureclass as IDataset).Workspace; workspace.StartEditing(false); workspace.StartEditOperation(); //合并图形 ITopologicalOperator2 topologicalOperator2 = orifeature.ShapeCopy as ITopologicalOperator2; for (i = 0; i < geolist.Count; i++) { IGeometry geo = geolist[i]; if (geometry != null) { topologicalOperator2 = geometry as ITopologicalOperator2; } ITopologicalOperator opertor = geo as ITopologicalOperator; opertor.Simplify(); topologicalOperator2.IsKnownSimple_2 = false; topologicalOperator2.Simplify(); geometry = topologicalOperator2.Union(geo); } //更新图形对象 IGeometry geoCombined = (IGeometry)geometry; orifeature.Shape = geoCombined as IGeometry; orifeature.Store(); workspace.StopEditOperation(); workspace.StopEditing(true); }
/// <summary> /// 获得总范围 /// </summary> /// <param name="dgView"></param> /// <returns></returns> private IGeometry GetUnionGeo(DevComponents.DotNetBar.Controls.DataGridViewX dgView) { IGeometry UnionGeo = null; for (int i = 0; i < dgView.RowCount; i++) { if (dgView.Rows[i].Cells[0].FormattedValue.ToString() == "") { continue; } bool b = Convert.ToBoolean(dgView.Rows[i].Cells[0].FormattedValue.ToString()); if (b) { IGeometry pGeo = dgView.Rows[i].Cells[1].Tag as IGeometry; if (pGeo == null) { continue; } if (UnionGeo == null) { UnionGeo = pGeo; } else { ITopologicalOperator pTop = UnionGeo as ITopologicalOperator; UnionGeo = pTop.Union(pGeo); pTop.Simplify(); } } } return(UnionGeo); }
/// <summary> /// 裁剪输入的几何要素,保留相交的要素部分 /// </summary> /// <param name="SrcGeo"></param> /// <param name="ClipGeo"></param> /// <returns></returns> public static IGeometry seek_InnerGeometry(IGeometry SrcGeo, IGeometry ClipGeo) { try { if (ClipGeo.GeometryType != esriGeometryType.esriGeometryPolygon) { MessageBox.Show("请检查覆盖区域!"); return(null); } //统一参考系 if (SrcGeo.SpatialReference != null && ClipGeo.SpatialReference != null) { ClipGeo.Project(SrcGeo.SpatialReference); } IGeometry geometry = null; ITopologicalOperator topo = SrcGeo as ITopologicalOperator; topo.Simplify();//是拓扑关系最简化 geometry = topo.Intersect(ClipGeo, esriGeometryDimension.esriGeometry2Dimension); return(geometry); } catch (Exception) { return(null); } }
/// <summary> /// 转换geometry为坐标串 /// </summary> /// <param name="geometry"></param> /// <param name="message">输出消息(目前是错误消息)</param> /// <returns>返回坐标串</returns> public static string ConvertGeometryToJson(IGeometry geometry, out string message) { string geomJsonStr = null; message = string.Empty; try { ITopologicalOperator topoGeom = geometry as ITopologicalOperator; topoGeom.Simplify(); if (topoGeom is IPolygon polygon) { polygon.Generalize(1); } if (geometry.SpatialReference == null || geometry.SpatialReference.Name == "Unknown") { geometry.SpatialReference = SpatialRefUtil.GetProjectedCoordinate(esriSRProjCS4Type.esriSRProjCS_Xian1980_3_Degree_GK_CM_120E); } ESRI.ArcGIS.esriSystem.IJSONWriter jsonWriter = new ESRI.ArcGIS.esriSystem.JSONWriterClass(); jsonWriter.WriteToString(); ESRI.ArcGIS.Geometry.JSONConverterGeometryClass jsonCon = new ESRI.ArcGIS.Geometry.JSONConverterGeometryClass(); jsonCon.WriteGeometry(jsonWriter, null, geometry, false); geomJsonStr = Encoding.UTF8.GetString(jsonWriter.GetStringBuffer()); } catch (Exception ex) { LOG.Error(ex); message = ex.ToString(); } return(geomJsonStr); }
public IGeometry Erase(IGeometry source, IGeometry other) { ITopologicalOperator @operator = source as ITopologicalOperator; if ([email protected]) { @operator.Simplify(); } IGeometry geometry = @operator.Difference(other); @operator = geometry as ITopologicalOperator; if ([email protected]) { @operator.Simplify(); } return(geometry); }
/// <summary> /// 字符串生成面,并拓扑简化 /// </summary> /// <param name="polygonString"></param> /// <returns></returns> public static IPolygon StringToPolygon(string polygonString) { IPolygon pPolygon = Core.Generic.Convertor.ToPolygon(polygonString); ITopologicalOperator topo = pPolygon as ITopologicalOperator; topo.Simplify(); return(pPolygon); }
/// <summary> /// 算出量测计算结果,并在FormDis上进行显示 /// </summary> /// <param name="ipGeo">人机交互生成的实体</param> public void WriteLabelText(IGeometry ipGeo) { switch (m_MeasureType) { case MeasureType.Length: //量测长度 { string strUnit = " " + (this.m_Tool as ToolMeasureLength).m_hookHelper.FocusMap.MapUnits.ToString().Substring(4); //this.m_LabelMeasureType.Text = "Line Measurement"; this.m_LabelMeasureType.Text = "长度量测"; this.m_labelArea.Visible = true; if (ipGeo != null) { IGeometryCollection ipGeoCol = ipGeo as IGeometryCollection; ISegmentCollection ipSegmentColl = ipGeoCol.get_Geometry(0) as ISegmentCollection; ILine ipLine = ipSegmentColl.get_Segment(ipSegmentColl.SegmentCount - 1) as ILine; //this.m_labelSegment.Text = "段长度:" + ipLine.Length.ToString() + strUnit; //this.m_labelLength.Text = "长度:" + (ipGeoCol.get_Geometry(0) as ICurve).Length.ToString() + "米"; this.m_labelArea.Text = "长度:" + (ipGeoCol.get_Geometry(0) as ICurve).Length.ToString("f3") + "米"; } else { this.m_labelArea.Text = "长度:" + "0" + "米"; //this.m_labelLength.Text = "总长度:" + "0" + strUnit; } } break; case MeasureType.Area: //量测面积 { string strUnit = " " + (this.m_Tool as ToolMeasureArea).m_hookHelper.FocusMap.MapUnits.ToString().Substring(4); //this.m_LabelMeasureType.Text = "Area Measurement"; this.m_LabelMeasureType.Text = "面积量测"; this.m_labelArea.Visible = true; if (ipGeo != null) { IGeometryCollection ipGeoCol = ipGeo as IGeometryCollection; ISegmentCollection ipSegmentColl = ipGeoCol.get_Geometry(0) as ISegmentCollection; ILine ipLine = ipSegmentColl.get_Segment(ipSegmentColl.SegmentCount - 1) as ILine; //this.m_labelSegment.Text = "Segment:" + ipLine.Length.ToString() + strUnit; //this.m_labelLength.Text = "Perimeter:" + (ipGeoCol.get_Geometry(0) as IRing).Length.ToString() + strUnit; //this.m_labelSegment.Text = "段长度:" + ipLine.Length.ToString() + strUnit; //this.m_labelLength.Text = "周长:" + (ipGeoCol.get_Geometry(0) as IRing).Length.ToString() + strUnit; IClone ipClone = ipGeo as IClone; IGeometry ipGeo1 = ipClone.Clone() as IGeometry; ITopologicalOperator ipTopo = ipGeo1 as ITopologicalOperator; ipTopo.Simplify(); this.m_labelArea.Text = "面积:" + ((ipGeo1 as IPolygon) as IArea).Area.ToString(".###") + "平方米"; } else { this.m_labelArea.Text = "面积:" + "0" + "平方米"; } } break; } }
private IPointCollection method_4(IPolyline ipolyline_0, IPolygon ipolygon_0) { IMultipoint multipoint = null; ITopologicalOperator @operator = ipolygon_0 as ITopologicalOperator; @operator.Simplify(); multipoint = @operator.Intersect(ipolyline_0, esriGeometryDimension.esriGeometry0Dimension) as IMultipoint; return(multipoint as IPointCollection); }
/// <summary> /// 鼠标移动事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void mapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { if (listMapPoints.Count != 0) { MapLngLat moveLnglat = new MapLngLat(e.mapX, e.mapY); if (!isControl)//若没有按下空格 { listMapPoints.Add(moveLnglat); switch (measureType) { case "distance": measureLine.UpdatePosition(listMapPoints); segmentLength = MapFrame.Core.Common.Utils.GetDistance(downPoint, moveLnglat); toltalLength += segmentLength; ResultEventArgs(string.Format("当前线段长度为:{0} 千米 \n总线段长度为:{1}千米", segmentLength, toltalLength)); toltalLength -= segmentLength; break; case "area": measurePolygon.UpdatePosition(listMapPoints); IPolygon polygon = new PolygonClass(); IGeometry geometry = null; ITopologicalOperator topo = null; IPointCollection pointCollec = new PolygonClass(); for (int i = 0; i < listMapPoints.Count; i++) { pointCollec.AddPoint(new PointClass() { X = listMapPoints[i].Lng, Y = listMapPoints[i].Lat }); } polygon = pointCollec as IPolygon; if (polygon != null) { polygon.Close(); geometry = polygon as IGeometry; topo = geometry as ITopologicalOperator; topo.Simplify(); geometry.Project(mapControl.Map.SpatialReference); IArea area = geometry as IArea; if (area != null) { measureArea = area.Area; ResultEventArgs(string.Format("面积为:{0} 万平方千米", measureArea)); polygon = null; } } break; } listMapPoints.Remove(moveLnglat); } } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button != 1 || m_hookHelper.FocusMap.LayerCount <= 0) { return; } IActiveView activeView = m_hookHelper.ActiveView; IGraphicsContainer graphicsContainer = activeView as IGraphicsContainer; // 删除地图上添加的所有Element graphicsContainer.DeleteAllElements(); // 获得点击位置并转化为点图形要素 IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); // 获取地图中的图层 IFeatureLayer featureLayer = m_hookHelper.FocusMap.get_Layer(0) as IFeatureLayer; if (featureLayer == null) { return; } IFeatureClass featureClass = featureLayer.FeatureClass; // 进行点击,查询图层要素 ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = point; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false); // 获得点击查询的要素 IFeature feature = featureCursor.NextFeature(); if (feature != null && feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) { IGeometry geometry = feature.Shape as IGeometry; // 通过ITopologicalOperator接口进行多边行的简单化处理 ITopologicalOperator topologicalOperator = geometry as ITopologicalOperator; topologicalOperator.Simplify(); // 创建缓冲区 IGeometry bufferGeometry = topologicalOperator.Buffer(5000); // 创建多边形符号样式并添加到地图上 IScreenDisplay screenDisplay = activeView.ScreenDisplay; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSCross; IRgbColor rgbColor = ColorTool.GetRgbColor(211, 100, 200); simpleFillSymbol.Color = rgbColor; // 创建多边行渲染效果的Element IFillShapeElement fillShapElement = new PolygonElementClass(); IElement element = fillShapElement as IElement; element.Geometry = bufferGeometry; fillShapElement.Symbol = simpleFillSymbol; // 将渲染之后的多边形element添加到地图IGraphicsContainer中 graphicsContainer.AddElement(fillShapElement as IElement, 0); } // 刷新地图 activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <summary> /// source与other 对象比较不同的地方 /// return source-other; /// </summary> /// <param name="source"></param> /// <param name="other"></param> /// <returns></returns> public virtual IGeometry[] Erase(IGeometry source, IGeometry other) { ITopologicalOperator topoOper = source as ITopologicalOperator; if (!topoOper.IsSimple) { topoOper.Simplify(); } IGeometry geo = topoOper.Difference(other); topoOper = geo as ITopologicalOperator; if (!topoOper.IsSimple) { topoOper.Simplify(); } return(new IGeometry[] { geo }); }
private void axMapcontrol_OnDoubleClick(object sender, IMapControlEvents2_OnDoubleClickEvent e) { IPoint dblpnt = new PointClass(); dblpnt.PutCoords(e.mapX, e.mapY); switch (pMouseOperate) { case "MeasureLength": if (m_newline != null) { if (dblpnt.IsEmpty || dblpnt == null) { return; } IPolyline polyline = m_newline.Stop(); //绘制路径 DrawElement(polyline as IGeometry); m_newline = null; //显示长度 if (frmMeasureResult != null && !frmMeasureResult.IsDisposed) { //double deltaX = dblpnt.X - Dwnpoint.X; //double deltaY = dblpnt.Y - Dwnpoint.Y; //SegmentLength = Math.Round(Math.Sqrt(deltaX * deltaX + deltaY * deltaY)); ShowResultEvent(new double[] { SegmentLength, TotalLength }, sMapunits, pMouseOperate); //清除绘制要素 this.axMapcontrol.ActiveView.GraphicsContainer.DeleteAllElements(); } } break; case "MeasureArea": if (m_newpolygon != null) { Area_Pocoll.AddPoint(dblpnt, missing, missing); IPolygon polygon = m_newpolygon.Stop() as IPolygon; if (Area_Pocoll.PointCount < 3 || polygon.IsEmpty) { return; } polygon.Close(); IGeometry pGeo = polygon as IGeometry; ITopologicalOperator topo = pGeo as ITopologicalOperator; topo.Simplify(); pGeo.Project(this.axMapcontrol.SpatialReference); IArea area = pGeo as IArea; if (frmMeasureResult != null && !frmMeasureResult.IsDisposed) { ShowResultEvent(new double[] { area.Area, polygon.Length }, sMapunits, pMouseOperate); } } break; } }
/// <summary> /// Converts the geometry to WKB. /// </summary> /// <param name="geometry">The geometry</param> /// <returns>WKB byte array</returns> private static byte[] ConvertGeometryToWKB(IGeometry geometry) { IWkb wkb = geometry as IWkb; ITopologicalOperator oper = geometry as ITopologicalOperator; oper.Simplify(); IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3; byte[] b = factory.CreateWkbVariantFromGeometry(geometry) as byte[]; return(b); }
public IGeometry GetBufferByGeometry(IGeometry pGeometry, double distance) { IGeometry oGeo = null; if (pGeometry is ITopologicalOperator) { ITopologicalOperator TopOper = pGeometry as ITopologicalOperator; TopOper.Simplify(); oGeo = TopOper.Buffer(distance); } return(oGeo); }
public void EraseOper() { ISpatialFilter tSF = new SpatialFilterClass(); tSF.Geometry = _Envelope; tSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; //求出与裁切框相交要素 IFeatureCursor tFeatureCursor = _FeatureClass.Search(tSF, false); IFeature tFeature = tFeatureCursor.NextFeature(); while (tFeature != null) { IGeometry tGeo2 = tFeature.ShapeCopy; ITopologicalOperator tTope2 = tGeo2 as ITopologicalOperator; tTope2.Simplify(); IGeometry tGeo = tFeature.ShapeCopy; ITopologicalOperator tTope = tGeo as ITopologicalOperator; tTope.Simplify(); //用Envelope对要素进行裁切 tTope.Clip(this._Envelope); IGeometry tGeoClip = (IGeometry)tTope; //用裁切出来的要素,再与其源要素进行求差处理,即得到外围要素 IGeometry tGeoDe = tTope2.Difference(tGeoClip); //把外围要素赋予源要素 tFeature.Shape = tGeoDe; tFeature.Store(); tFeature = tFeatureCursor.NextFeature(); } ReleaseCom(tFeatureCursor); }
private IGeometry CombineFence(IGeometryArray geometryArray) { IGeometry firstGeometry = geometryArray.Element[0]; ITopologicalOperator topo = firstGeometry as ITopologicalOperator; if (!topo.IsKnownSimple) { topo.Simplify(); } for (int i = 1; i < geometryArray.Count; i++) { IGeometry newGeom = topo.Union(geometryArray.Element[i]); topo = newGeom as ITopologicalOperator; if (!topo.IsKnownSimple) { topo.Simplify(); } } topo.Simplify(); return(topo as IGeometry); }
/// <summary> /// 合并两个面 /// </summary> /// <param name="a1"></param> /// <param name="a2"></param> /// <returns></returns> private static IPolygon MergePolygon(IPolygon a1, IPolygon a2) { ITopologicalOperator pTopoOp; pTopoOp = a1 as ITopologicalOperator; pTopoOp.Simplify(); ITopologicalOperator pTopoOp2 = a2 as ITopologicalOperator; pTopoOp2.Simplify(); IGeometry a3 = pTopoOp.Union(a2 as IGeometry); pTopoOp = a3 as ITopologicalOperator; pTopoOp.Simplify(); return(a3 as IPolygon); }
/// <summary> /// 从坐标字符串得到范围Polygon /// </summary> /// <param name="strCoor">坐标字符串,格式为X@Y,以逗号分割</param> /// <returns></returns> public static IPolygon GetPolygonByCol(string strCoor) { try { object after = Type.Missing; object before = Type.Missing; IPolygon polygon = new PolygonClass(); IPointCollection pPointCol = (IPointCollection)polygon; string[] strTemp = strCoor.Split(','); for (int index = 0; index < strTemp.Length; index++) { string CoorLine = strTemp[index]; string[] coors = CoorLine.Split('@'); double X = Convert.ToDouble(coors[0]); double Y = Convert.ToDouble(coors[1]); IPoint pPoint = new PointClass(); pPoint.PutCoords(X, Y); pPointCol.AddPoint(pPoint, ref before, ref after); } polygon = (IPolygon)pPointCol; polygon.Close(); ITopologicalOperator pTopo = (ITopologicalOperator)polygon; pTopo.Simplify(); return(polygon); } catch (Exception e) { //******************************************************************* //guozheng added if (ModData.SysLog != null) { ModData.SysLog.Write(e, null, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write(e, null, DateTime.Now); } //******************************************************************** return(null); } }