private static List <IPolyline> GetFeatureIntersection(IFeature feature, IPolyline polyline) { var resultPolylines = new List <IPolyline>(); var multipoint = new Multipoint(); IGeometry geometry = feature.ShapeCopy; geometry.Project(polyline.SpatialReference); ITopologicalOperator pTopo = geometry as ITopologicalOperator; var result = pTopo.Intersect(polyline, esriGeometryDimension.esriGeometry0Dimension); var firstLinePointOnLayer = (IPoint)pTopo.Intersect(polyline.FromPoint, esriGeometryDimension.esriGeometry0Dimension); var lastLinePointOnLayer = (IPoint)pTopo.Intersect(polyline.ToPoint, esriGeometryDimension.esriGeometry0Dimension); if (!result.IsEmpty) { multipoint = (Multipoint)result; IPoint firstPoint = null; IPoint lastPoint = null; if (!firstLinePointOnLayer.IsEmpty) { if (firstLinePointOnLayer.Y > multipoint.Point[0].Y) { firstPoint = firstLinePointOnLayer; } else { lastPoint = firstLinePointOnLayer; } } if (!lastLinePointOnLayer.IsEmpty) { if (lastLinePointOnLayer.Y > multipoint.Point[0].Y) { firstPoint = lastLinePointOnLayer; } else { lastPoint = lastLinePointOnLayer; } } if (firstPoint != null) { var buff = new Multipoint(); buff.AddPointCollection(multipoint); multipoint.RemovePoints(0, multipoint.PointCount); multipoint.AddPoint(firstPoint); multipoint.AddPointCollection(buff); } if (lastPoint != null) { multipoint.AddPoint(lastPoint); } } if (result.IsEmpty && !firstLinePointOnLayer.IsEmpty) { if (!firstLinePointOnLayer.IsEmpty) { multipoint.AddPoint((IPoint)firstLinePointOnLayer); } if (!lastLinePointOnLayer.IsEmpty) { multipoint.AddPoint((IPoint)lastLinePointOnLayer); } } if (multipoint.PointCount == 1) { multipoint.Point[0].Project(polyline.SpatialReference); resultPolylines.Add(CreatePolylineFromPoints(multipoint.Point[0], multipoint.Point[0])); } else if (multipoint.PointCount > 0) { for (int i = 0; i < multipoint.PointCount - 1; i++) { multipoint.Point[i].Project(polyline.SpatialReference); multipoint.Point[i + 1].Project(polyline.SpatialReference); resultPolylines.Add(CreatePolylineFromPoints(multipoint.Point[i], multipoint.Point[i + 1])); i++; } } return(resultPolylines); }
public bool Snap(IGeometry igeometry_0, IPoint ipoint_0, double double_0) { bool flag; int i; IHitTest shape; IGeometry geometry; if (!EditorLicenseProviderCheck.Check()) { flag = false; } else if (this.ifeatureCache_0.Count != 0) { bool flag1 = false; double num = 0; int num1 = 0; int num2 = 0; bool flag2 = true; IPoint pointClass = new ESRI.ArcGIS.Geometry.Point(); object value = Missing.Value; IArray arrayClass = new Array(); for (i = 0; i < this.ifeatureCache_0.Count; i++) { shape = (IHitTest)this.ifeatureCache_0.Feature[i].Shape; if ((shape is IPolyline ? true : shape is IPolygon) && shape.HitTest(ipoint_0, double_0, esriGeometryHitPartType.esriGeometryPartBoundary, pointClass, ref num, ref num1, ref num2, ref flag2)) { arrayClass.Add(shape); } } IPointCollection multipointClass = new Multipoint(); IArray arrayClass1 = new Array() as IArray; for (i = 0; i < arrayClass.Count; i++) { ITopologicalOperator2 element = (ITopologicalOperator2)arrayClass.Element[i]; for (int j = 0; j < arrayClass.Count; j++) { if (i != j) { if (((IGeometry)arrayClass.Element[i]).GeometryType != ((IGeometry)arrayClass.Element[j]).GeometryType) { geometry = element.IntersectMultidimension((IGeometry)arrayClass.Element[j]); if (geometry != null) { IGeometryCollection geometryCollection = geometry as IGeometryCollection; if (geometryCollection != null) { for (int k = 0; k < geometryCollection.GeometryCount; k++) { geometry = geometryCollection.Geometry[k]; if (geometry is IPointCollection) { multipointClass.AddPointCollection((IPointCollection)geometry); } else if (geometry is IPointCollection) { multipointClass.AddPoint((IPoint)geometry, ref value, ref value); } } } } } else { geometry = element.Intersect((IGeometry)arrayClass.Element[j], esriGeometryDimension.esriGeometry0Dimension); if (geometry != null) { if (geometry is IPointCollection) { multipointClass.AddPointCollection((IPointCollection)geometry); } else if (geometry is IPointCollection) { multipointClass.AddPoint((IPoint)geometry, ref value, ref value); } } } } } } shape = (IHitTest)multipointClass; if (shape.HitTest(ipoint_0, double_0, esriGeometryHitPartType.esriGeometryPartVertex, pointClass, ref num, ref num1, ref num2, ref flag2)) { ipoint_0.PutCoords(pointClass.X, pointClass.Y); flag1 = true; } flag = flag1; } else { flag = false; } return(flag); }
private IPoint method_8(IPoint ipoint_0, IFeatureCache2 ifeatureCache2_0, double double_0) { int i; IGeometry geometry; double num = 0; int num1 = 0; int num2 = 0; bool flag = true; IPoint point = null; List <IGeometry> geometries = new List <IGeometry>(); for (i = 0; i < ifeatureCache2_0.Count; i++) { IFeature feature = ifeatureCache2_0.Feature[i]; if ((feature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline ? true : feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)) { IPoint pointClass = new ESRI.ArcGIS.Geometry.Point(); IHitTest shape = (IHitTest)feature.Shape; if ( shape.HitTest(ipoint_0, double_0, esriGeometryHitPartType.esriGeometryPartBoundary, pointClass, ref num, ref num1, ref num2, ref flag) && num <= double_0) { IGeometryCollection geometryCollection = shape as IGeometryCollection; if (geometryCollection != null) { ISegmentCollection segmentCollection = geometryCollection.Geometry[num1] as ISegmentCollection; if (segmentCollection != null) { //segmentCollection.Segment[num2] is ICircularArc; } } } } } IPointCollection multipointClass = new Multipoint(); for (i = 0; i < geometries.Count; i++) { ITopologicalOperator2 item = (ITopologicalOperator2)geometries[i]; for (int j = 0; j < geometries.Count; j++) { if (i != j) { if (geometries[i].GeometryType != geometries[j].GeometryType) { geometry = item.IntersectMultidimension(geometries[j]); if (geometry != null) { IGeometryCollection geometryCollection1 = geometry as IGeometryCollection; if (geometryCollection1 != null) { for (int k = 0; k < geometryCollection1.GeometryCount; k++) { geometry = geometryCollection1.Geometry[k]; if (geometry is IPointCollection) { multipointClass.AddPointCollection((IPointCollection)geometry); } else if (geometry is IPoint) { object value = Missing.Value; object obj = Missing.Value; multipointClass.AddPoint((IPoint)geometry, ref value, ref obj); } } } } } else { geometry = item.Intersect(geometries[j], esriGeometryDimension.esriGeometry0Dimension); if (geometry != null) { if (geometry is IPointCollection) { multipointClass.AddPointCollection((IPointCollection)geometry); } else if (geometry is IPoint) { object value1 = Missing.Value; object obj1 = Missing.Value; multipointClass.AddPoint((IPoint)geometry, ref value1, ref obj1); } } } } } } IHitTest hitTest = (IHitTest)multipointClass; IPoint pointClass1 = new ESRI.ArcGIS.Geometry.Point(); if ( hitTest.HitTest(ipoint_0, double_0, esriGeometryHitPartType.esriGeometryPartVertex, pointClass1, ref num, ref num1, ref num2, ref flag) && num < double_0) { point = pointClass1; } return(point); }