private List <IRing> method_6(IPolygon ipolygon_0) { IPolygon4 polygon = ipolygon_0 as IPolygon4; List <IRing> list = new List <IRing>(); IEnumGeometry exteriorRingBag = polygon.ExteriorRingBag as IEnumGeometry; exteriorRingBag.Reset(); for (IRing ring = exteriorRingBag.Next() as IRing; ring != null; ring = exteriorRingBag.Next() as IRing) { list.Add(ring); } return(list); }
private List <IRing> method_7(IRing iring_0, IPolygon ipolygon_0) { List <IRing> list = new List <IRing>(); IPolygon4 polygon = ipolygon_0 as IPolygon4; IEnumGeometry geometry = polygon.get_InteriorRingBag(iring_0) as IEnumGeometry; geometry.Reset(); for (IRing ring = geometry.Next() as IRing; ring != null; ring = geometry.Next() as IRing) { list.Add(ring); } return(list); }
/// <summary> /// Converts an Esri enumerable interface to a DotNet IEnumerable. /// </summary> /// <param name="esriEnum">An enumerable Esri interface.</param> /// <returns>The adapted dotnet enumeration.</returns> public static IEnumerable <IGeometry> Enumerate(this IEnumGeometry esriEnum) { if (esriEnum != null) { esriEnum.Reset(); IGeometry esriEnumItem = esriEnum.Next(); while (esriEnumItem != null) { yield return(esriEnumItem); esriEnumItem = esriEnum.Next(); } } }
private static bool HasOnlyEmptyElements([NotNull] IEnumGeometry enumGeometry) { if (enumGeometry.Count == 0) { return(true); } enumGeometry.Reset(); try { IGeometry geometry; while ((geometry = enumGeometry.Next()) != null) { if (!geometry.IsEmpty) { return(false); } } return(true); } finally { enumGeometry.Reset(); } }
private IGeometry BufferExtAndIntBoundary(IPolygon4 polygon, double bufferDistance, bool draw) { IGeometry bndBuffer; object obj = Type.Missing; IGeometryCollection bufferGeometries = new GeometryBagClass() as IGeometryCollection; IGeometryBag exteriorRings = polygon.ExteriorRingBag; IEnumGeometry exteriorRingsEnum = exteriorRings as IEnumGeometry; exteriorRingsEnum.Reset(); IRing currentExteriorRing = exteriorRingsEnum.Next() as IRing; while (currentExteriorRing != null) { bndBuffer = BufferBoundary(currentExteriorRing, bufferDistance, false); bufferGeometries.AddGeometry(bndBuffer, ref obj, ref obj); //IPolygon4.get_InteriorRingBag should be used instead of IPolygon.QueryInteriorRings, //which does not work in .NET because of C-Style Arrays IGeometryBag interiorRings = polygon.get_InteriorRingBag(currentExteriorRing); IEnumGeometry interiorRingsEnum = interiorRings as IEnumGeometry; interiorRingsEnum.Reset(); IRing currentInteriorRing = interiorRingsEnum.Next() as IRing; while (currentInteriorRing != null) { bndBuffer = BufferBoundary(currentInteriorRing, bufferDistance, false); bufferGeometries.AddGeometry(bndBuffer, ref obj, ref obj); currentInteriorRing = interiorRingsEnum.Next() as IRing; } currentExteriorRing = exteriorRingsEnum.Next() as IRing; } ITopologicalOperator topoBufferGeometries = bufferGeometries as ITopologicalOperator; topoBufferGeometries.Simplify(); IPolygon buffPolygon = new PolygonClass(); ITopologicalOperator topoPolygon = buffPolygon as ITopologicalOperator; IEnumGeometry enumGeometry = bufferGeometries as IEnumGeometry; topoPolygon.ConstructUnion(enumGeometry); if (draw) { DrawGraphics(buffPolygon as IGeometry); } return(buffPolygon as IGeometry); }
public static ISegmentCollection GetSegmentCollectionOfPolygon(IGeometry pGeometry) { IPolygon4 pPolygon = pGeometry as IPolygon4; IGeometryBag exteriorRings = pPolygon.ExteriorRingBag; IEnumGeometry exteriorRingsEnum = exteriorRings as IEnumGeometry; IRing currentExteriorRing = exteriorRingsEnum.Next() as IRing; return(currentExteriorRing as ISegmentCollection); }
/// <summary> /// 获取多边形的所有外环 /// </summary> /// <param name="polygon">多边形</param> /// <returns></returns> public static IRing[] GetExteriorRings(IPolygon polygon) { IPolygon4 polygon4 = polygon as IPolygon4; List <IRing> exteriorRingList = new List <IRing>(); IGeometryBag exteriorRings = polygon4.ExteriorRingBag; IEnumGeometry exteriorRingEnum = exteriorRings as IEnumGeometry; //exteriorRingEnum.Reset(); IRing ring = exteriorRingEnum.Next() as IRing; while (ring != null) { exteriorRingList.Add(ring); ring = exteriorRingEnum.Next() as IRing; } return(exteriorRingList.ToArray()); }
/// <summary> /// 根据外环获取到内环 /// </summary> /// <param name="ring">外环</param> /// <param name="polygon">多边形</param> /// <returns></returns> public static IRing[] GetInteriorRingsByExterior(IRing ring, IPolygon polygon) { List <IRing> interRingList = new List <IRing>(); IPolygon4 polygon4 = polygon as IPolygon4; IGeometryBag interRings = polygon4.get_InteriorRingBag(ring); IEnumGeometry interRingsEnum = interRings as IEnumGeometry; interRingsEnum.Reset(); IRing tmpring = interRingsEnum.Next() as IRing; while (tmpring != null) { interRingList.Add(tmpring); tmpring = interRingsEnum.Next() as IRing; } return(interRingList.ToArray()); }
/// <summary> /// chenyafei 20110420 add :获得要素的坐标串 /// </summary> /// <param name="pFea"></param> /// <returns></returns> private string GetCoor(IGeometry pInGeo) { if (pInGeo.IsEmpty) { return(""); } string CoorStr = ""; if (pInGeo.GeometryType == esriGeometryType.esriGeometryPoint) { IPoint mPnt = pInGeo as IPoint; CoorStr = mPnt.X + "," + mPnt.Y; } else if (pInGeo.GeometryType == esriGeometryType.esriGeometryPolyline) { IPointCollection pPntColl = pInGeo as IPointCollection; for (int i = 0; i < pPntColl.PointCount; i++) { IPoint pPnt = pPntColl.get_Point(i); CoorStr += pPnt.X + "," + pPnt.Y + ";"; } if (CoorStr != "") { CoorStr = CoorStr.Substring(0, CoorStr.Length - 1); } } else if (pInGeo.GeometryType == esriGeometryType.esriGeometryPolygon) { IPolygon4 pPolygon4 = pInGeo as IPolygon4; int pRingCount = pPolygon4.ExteriorRingCount; if (pRingCount > 0) { IGeometryBag pGeoBag = pPolygon4.ExteriorRingBag; IEnumGeometry pEnumGeo = pGeoBag as IEnumGeometry; pEnumGeo.Reset(); IGeometry mGeo = pEnumGeo.Next(); IPointCollection pPntColl = mGeo as IPointCollection; for (int i = 0; i < pPntColl.PointCount; i++) { IPoint pPnt = pPntColl.get_Point(i); CoorStr += pPnt.X + "," + pPnt.Y + ";"; } if (CoorStr != "") { CoorStr = CoorStr.Substring(0, CoorStr.Length - 1); } } } return(CoorStr); }
private IList <IGeometry> GetGeometrys(IGeometry pGeo) { IList <IGeometry> list = new List <IGeometry>(); try { if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline) { IGeometryCollection geometrys = pGeo as IGeometryCollection; int geometryCount = geometrys.GeometryCount; for (int i = 0; i < geometryCount; i++) { IGeometry inGeometry = geometrys.get_Geometry(i); if (!inGeometry.IsEmpty) { IGeometryCollection geometrys2 = new PolylineClass(); object missing = System.Type.Missing; geometrys2.AddGeometry(inGeometry, ref missing, ref missing); IGeometry item = geometrys2 as IGeometry; item.SpatialReference = pGeo.SpatialReference; list.Add(item); } } return(list); } if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon) { IPolygon4 polygon = pGeo as IPolygon4; if (polygon.ExteriorRingCount < 2) { list.Add(pGeo); return(list); } IEnumGeometry exteriorRingBag = polygon.ExteriorRingBag as IEnumGeometry; exteriorRingBag.Reset(); for (IRing ring = exteriorRingBag.Next() as IRing; ring != null; ring = exteriorRingBag.Next() as IRing) { IGeometryBag bag2 = polygon.get_InteriorRingBag(ring); object before = System.Type.Missing; IGeometryCollection geometrys3 = null; geometrys3 = new PolygonClass(); geometrys3.AddGeometry(ring, ref before, ref before); IPolygon polygon2 = geometrys3 as IPolygon; polygon2.SpatialReference = pGeo.SpatialReference; ITopologicalOperator2 @operator = (ITopologicalOperator2)polygon2; @operator.IsKnownSimple_2 = false; @operator.Simplify(); if (!bag2.IsEmpty) { IGeometryCollection geometrys4 = new PolygonClass(); IEnumGeometry geometry4 = bag2 as IEnumGeometry; geometry4.Reset(); for (IRing ring2 = geometry4.Next() as IRing; ring2 != null; ring2 = geometry4.Next() as IRing) { geometrys4.AddGeometry(ring2, ref before, ref before); } IPolygon other = geometrys4 as IPolygon; other.SpatialReference = pGeo.SpatialReference; ITopologicalOperator2 operator2 = (ITopologicalOperator2)other; operator2.IsKnownSimple_2 = false; operator2.Simplify(); IGeometry geometry5 = @operator.Difference(other); list.Add(geometry5); } else { list.Add(polygon2); } } } return(list); } catch { return(null); } return(list); }
/// <summary> /// 获取VCT面实体节点 /// </summary> public override EntityNode GetEntityNode() { try { m_PolygonNode = new PolygonNode(); IFeature pFeature = this.Feature as IFeature; ///标识码赋值 int dBSMIndex = -1; dBSMIndex = this.Feature.Fields.FindField(m_strEntityIDFiled); if (dBSMIndex != -1) m_PolygonNode.EntityID = Convert.ToInt32(this.Feature.get_Value(dBSMIndex)); ///图形表现赋值 //m_PolygonNode.Representation = pFeature.Class.AliasName; ///要素代码赋值 //int dSYDMIndex = -1; //dSYDMIndex = this.Feature.Fields.FindField(m_strYSDMField); //if (dSYDMIndex != -1) // m_PolygonNode.FeatureCode = this.Feature.get_Value(dSYDMIndex).ToString(); //string sAttriTableName = (pFeature.Class as IDataset).Name; //m_PolygonNode.FeatureCode = MetaDataFile.GetFeatureCodeByName(sAttriTableName); m_PolygonNode.FeatureCode = this.FeatureCode; //设置间接坐标面构成类型、面特征类型、图形表现代码 m_PolygonNode.PolygonType = 100; //m_PolygonNode.Representation = pFeature.Class.AliasName; ///add by 曾平 2011-9-7 添加裁切 IGeometry pFeatureGeometry = null; if (m_bCut) { pFeatureGeometry = GetSubGeometry(); if (pFeatureGeometry == null) { pFeatureGeometry = pFeature.Shape; } } else { pFeatureGeometry = pFeature.Shape; } IPolygon4 pGeoPolygon = pFeatureGeometry as IPolygon4; List<LineNodeEx> pListNodeEx = new List<LineNodeEx>(); IGeometryBag pExteriorRings = pGeoPolygon.ExteriorRingBag; ///获取外环集合 IEnumGeometry pExteriorRingsEnum = pExteriorRings as IEnumGeometry; pExteriorRingsEnum.Reset(); IRing pCurrentExteriorRing = pExteriorRingsEnum.Next() as IRing; ////构面的线段要素代码都是面的要素代码 string strLineFeatureCode =m_PolygonNode.FeatureCode; string strRepresentation = m_PolygonNode.Representation; ///遍历所有外环及关联的内环 while (pCurrentExteriorRing != null) { ///设置当前外环数据 //List<LineNodeEx> pListExLine = GetLineByRing(pCurrentExteriorRing, strLineFeatureCode,strRepresentation, m_PolygonNode.EntityID); List<LineNodeEx> pListExLine = GetLineNodeExsByRing(pCurrentExteriorRing, strLineFeatureCode, strRepresentation, m_PolygonNode.EntityID); if (pListExLine != null) { pListNodeEx.AddRange(pListExLine); ///不相连的环添加标识码为0的空数据 LineNodeEx pOutTempLineNodeEx = new LineNodeEx(); pOutTempLineNodeEx.EntityID = 0; pOutTempLineNodeEx.PolygonID = m_PolygonNode.EntityID; pListNodeEx.Add(pOutTempLineNodeEx); ///获取当前外环的关联内环 IGeometryBag pInteriorRings = pGeoPolygon.get_InteriorRingBag(pCurrentExteriorRing); IEnumGeometry pInteriorRingsEnum = pInteriorRings as IEnumGeometry; pInteriorRingsEnum.Reset(); IRing pCurrentInteriorRing = pInteriorRingsEnum.Next() as IRing; ////遍历内环 while (pCurrentInteriorRing != null) { List<LineNodeEx> pListInLine = GetLineByRing(pCurrentInteriorRing, strLineFeatureCode, strRepresentation, m_PolygonNode.EntityID); if (pListInLine != null) { pListNodeEx.AddRange(pListInLine); ///不相连的环添加标识码为0的空数据 LineNodeEx pInTempLineNodeEx = new LineNodeEx(); pInTempLineNodeEx.EntityID = 0; pInTempLineNodeEx.PolygonID = m_PolygonNode.EntityID; pListNodeEx.Add(pInTempLineNodeEx); } //处理下一个内环 pCurrentInteriorRing = pInteriorRingsEnum.Next() as IRing; } } ///处理下一个外环 pCurrentExteriorRing = pExteriorRingsEnum.Next() as IRing; } ///删除集合中最后一位补零线段 if (pListNodeEx.Count>0&& pListNodeEx[pListNodeEx.Count - 1].EntityID == 0) pListNodeEx.RemoveAt(pListNodeEx.Count - 1); m_PolygonNode.LineNodes = pListNodeEx; //获取标志点 IArea pArea = pFeature.Shape as IArea; if (pArea != null) m_PolygonNode.LablePointInfoNode = new PointInfoNode(pArea.LabelPoint.X, pArea.LabelPoint.Y); return m_PolygonNode; } catch (Exception ex) { LogAPI.WriteErrorLog(ex); return null; } }
/// <summary> /// Create a geojson string from the geometry /// </summary> /// <param name="geometry"></param> /// <returns></returns> public static GeoJSONGeometry CreateFromIGeometry(IGeometry geometry) { GeoJSONGeometry jsonGeom = new GeoJSONGeometry(); jsonGeom.Type = geometry.GeometryType.ToString(); StringBuilder sb = new StringBuilder(); if (geometry.GeometryType != esriGeometryType.esriGeometryPoint) { sb.Append("["); } //Need to work out how to easily rip the coords out of the IGeometry switch (geometry.GeometryType) { case esriGeometryType.esriGeometryPoint: IPoint pt = (IPoint)geometry; sb.Append(string.Format("[{0}, {1}]", Math.Round(pt.X, 5), Math.Round(pt.Y, 5))); jsonGeom.Type = "Point"; break; case esriGeometryType.esriGeometryLine: IPolyline line = geometry as IPolyline; if (line == null) { return(null); } line.Densify(-1, -1); //make sure it's all straight line segments line.Weed(20); //weed out some vertices line.SimplifyNetwork(); //make sure it is simple IPointCollection points = line as IPointCollection; for (int i = 0; i < points.PointCount; i++) { IPoint point = points.get_Point(i); if (sb.Length > 1) { sb.Append(","); } sb.Append(string.Format("[{0}, {1}]", Math.Round(point.X, 4), Math.Round(point.Y, 4))); } jsonGeom.Type = "LineString"; break; case esriGeometryType.esriGeometryPolygon: IPolygon4 poly = geometry as IPolygon4; if (poly == null) { return(null); } poly.Densify(-1, -1); //make sure it is all straight line segments poly.Weed(20); //weed out some vertices poly.SimplifyPreserveFromTo(); //make sure it's simple //We aren't gonna deal with interior rings right now (ie - no holes in polygons) IGeometryBag multiRing = poly.ExteriorRingBag; IEnumGeometry exteriorRingsEnum = multiRing as IEnumGeometry; exteriorRingsEnum.Reset(); IRing currentExteriorRing = exteriorRingsEnum.Next() as IRing; while (currentExteriorRing != null) { if (!currentExteriorRing.IsClosed) { currentExteriorRing.Close(); } IPointCollection multiRingPoints = currentExteriorRing as IPointCollection; for (int pointIdx = 0; pointIdx < multiRingPoints.PointCount; pointIdx++) { IPoint multiRingPoint = multiRingPoints.get_Point(pointIdx); //coords.Add(new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(Math.Round(multiRingPoint.X, 5), Math.Round(multiRingPoint.Y, 5))); if (sb.Length > 1) { sb.Append(","); } sb.Append(string.Format("[{0}, {1}]", Math.Round(multiRingPoint.X, 4), Math.Round(multiRingPoint.Y, 4))); } currentExteriorRing = exteriorRingsEnum.Next() as IRing; } jsonGeom.Type = "Polygon"; break; } if (geometry.GeometryType != esriGeometryType.esriGeometryPoint) { sb.Append("]"); } jsonGeom.coordinates = sb.ToString(); return(jsonGeom); }
public static GeoAPI.Geometries.IMultiPolygon ConvertTo(ESRI.ArcGIS.Geometry.IPolygon4 polygon) { GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon output = null; List <GeoAPI.Geometries.IPolygon> list = new List <GeoAPI.Geometries.IPolygon>(); //IPolygon4.ExteriorRingBag should be used instead of IPolygon.QueryExteriorRings, //which does not work in .NET because of C-Style Arrays IGeometryBag exteriorRings = polygon.ExteriorRingBag; //For each exterior rings find the number of interior rings associated with it and print it IEnumGeometry exteriorRingsEnum = exteriorRings as IEnumGeometry; exteriorRingsEnum.Reset(); IRing currentExteriorRing = exteriorRingsEnum.Next() as IRing; while (currentExteriorRing != null) { GeoAPI.Geometries.ILinearRing shell = ConvertTo(currentExteriorRing); List <GeoAPI.Geometries.ILinearRing> holes = null; //IPolygon4.get_InteriorRingBag should be used instead of IPolygon.QueryInteriorRings, //which does not work in .NET because of C-Style Arrays IGeometryBag interiorRings = polygon.get_InteriorRingBag(currentExteriorRing); IGeometryCollection interiorRingCollection = interiorRings as IGeometryCollection; if (interiorRingCollection != null && interiorRingCollection.GeometryCount > 0) { holes = new List <GeoAPI.Geometries.ILinearRing>(); int interiorRingsTotal = interiorRingCollection.GeometryCount; for (int interiorRingIndex = 0; interiorRingIndex < interiorRingsTotal; interiorRingIndex++) { IRing currentInteriorRing = interiorRingCollection.get_Geometry(interiorRingIndex) as IRing; if (currentInteriorRing != null) { holes.Add(ConvertTo(currentInteriorRing)); } } ////Note we do nothing with the interiorRings, but you can use them the same way as the IGeometryBag exteriorRings //IRing currentInteriorRing = exteriorRingsEnum.Next() as IRing; //while (currentInteriorRing != null) //{ // holes.Add(ConvertTo(currentInteriorRing)); // currentInteriorRing = exteriorRingsEnum.Next() as IRing; //} } GeoAPI.Geometries.IPolygon entry; if (holes != null && holes.Count > 0) { entry = new GisSharpBlog.NetTopologySuite.Geometries.Polygon(shell, holes.ToArray()); } else { entry = new GisSharpBlog.NetTopologySuite.Geometries.Polygon(shell, null); } list.Add(entry); currentExteriorRing = exteriorRingsEnum.Next() as IRing; } if (list != null && list.Count > 0) { output = new GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon(list.ToArray()); } return(output); }
public void OtherRule(string idname, string IN_RuleType, IFeatureClass IN_FeatureClass) { if (IN_RuleType == "面多部件检查") { IFeatureCursor cursor = IN_FeatureClass.Search(null, false); int tempCount = 0; IFeature pFeature = cursor.NextFeature(); while (pFeature != null) { IGeometry pGeo = pFeature.ShapeCopy; ITopologicalOperator pTopoOperator = pGeo as ITopologicalOperator; int iCount = 0; if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { iCount = (pGeo as IPolygon).ExteriorRingCount; } else if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { iCount = ((pGeo as IPolyline) as IGeometryCollection).GeometryCount; } else if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryMultipoint) { iCount = ((pGeo as IMultipoint) as IPointCollection).PointCount; } if (iCount > 1) { tempCount++; Console.WriteLine(pFeature.OID); } pFeature = cursor.NextFeature(); } DicTopoError[idname] = tempCount; } else if (IN_RuleType == "面自相交检查") { IFeatureCursor cursor = IN_FeatureClass.Search(null, false); IFeature pFeature = cursor.NextFeature(); int tempCount = 0; while (pFeature != null) { IPolygon4 polygon = pFeature.ShapeCopy as IPolygon4; IGeometryBag bag = polygon.ExteriorRingBag; IEnumGeometry geo = bag as IEnumGeometry; geo.Reset(); int iCount = 0; IRing exRing = geo.Next() as IRing; while (exRing != null) { if (exRing.IsExterior) { iCount++; } exRing = geo.Next() as IRing; } if (iCount > 1) { tempCount++; } pFeature = cursor.NextFeature(); } DicTopoError[idname] = tempCount; } }