Пример #1
0
        private static bool PathRunsAlongTwoPolygons([NotNull] IPath path,
                                                     [NotNull] IList <IGeometry> polygons)
        {
            // For a potential performance improvement, see StickyIntersections
            var touchCount = 0;

            IGeometry highLevelPath = GeometryUtils.GetHighLevelGeometry(path, true);

            // it's a bag of polygons
            foreach (IGeometry polygon in polygons)
            {
                if (GeometryUtils.Touches(highLevelPath, polygon))
                {
                    // filter out those that only touch in the start point and do not run along the boundary
                    IPolyline outline = GeometryFactory.CreatePolyline(polygon);

                    IPolyline lineAlongBoundary = IntersectionUtils.GetIntersectionLines(
                        outline, (IPolycurve)highLevelPath, true, true);

                    if (!lineAlongBoundary.IsEmpty)
                    {
                        touchCount++;

                        if (touchCount == 2)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Пример #2
0
        private static IPointCollection GetPoints(IPointCollection pointCollection,
                                                  IGeometry inArea)
        {
            if (pointCollection == null ||
                pointCollection.PointCount == 0)
            {
                return(null);
            }

            if (inArea == null)
            {
                return(pointCollection);
            }

            if (GeometryUtils.Disjoint(inArea, (IGeometry)pointCollection))
            {
                return(null);
            }

            // because intersecting multipoints with envelope is not implemented:
            var withinPolygon = inArea as IPolygon;

            withinPolygon = withinPolygon ?? GeometryFactory.CreatePolygon(inArea);

            var result =
                (IPointCollection)
                IntersectionUtils.GetIntersection((IGeometry)pointCollection, withinPolygon);

            return(result);
        }
            private static IGeometry GetIntersectionGeometry([NotNull] IGeometry shape1,
                                                             [NotNull] IGeometry shape2)
            {
                IGeometry result = null;

                foreach (IGeometry intersection in
                         IntersectionUtils.GetAllIntersections(shape1, shape2))
                {
                    if (result == null || result.Dimension < intersection.Dimension)
                    {
                        if (result != null)
                        {
                            Marshal.ReleaseComObject(result);
                        }

                        result = intersection;
                    }
                    else
                    {
                        Marshal.ReleaseComObject(intersection);
                    }
                }

                return(Assert.NotNull(result));
            }
Пример #4
0
        private static IEnumerable <IGeometry> GetCrossings([NotNull] IGeometry g1,
                                                            [NotNull] IGeometry g2)
        {
            var polyline1 = g1 as IPolyline;
            var polyline2 = g2 as IPolyline;

            if (polyline1 != null && polyline2 != null)
            {
                // TODO get intersection matrix also?
                // 0********
                // but: dimension restriction needs to be better tested first
                yield return(IntersectionUtils.GetLineCrossings(polyline1, polyline2));
            }
            else
            {
                // TODO for line/polygon it would be more useful to get the
                // locations where the line crosses the polygon boundary (and continues)
                // Probably also for polygon/polygon
                IList <IGeometry> intersections = g1.Dimension <= g2.Dimension
                                                                         ? _crossesMatrixOther.GetIntersections(g1, g2)
                                                                         : _crossesMatrixOther.GetIntersections(g2, g1);

                foreach (IGeometry geometry in intersections)
                {
                    yield return(geometry);
                }
            }
        }
Пример #5
0
        private static IGeometry TryGetIntersection([NotNull] IGeometry sourceGeometry,
                                                    [NotNull] IGeometry targetGeometry)
        {
            IGeometry targetToIntersect =
                targetGeometry.GeometryType == esriGeometryType.esriGeometryMultiPatch
                                        ? GeometryFactory.CreatePolygon(targetGeometry)
                                        : targetGeometry;

            esriGeometryDimension dimension =
                sourceGeometry is IPolygon
                                        ? esriGeometryDimension.esriGeometry2Dimension
                                        : esriGeometryDimension.esriGeometry1Dimension;

            IGeometry intersection = IntersectionUtils.Intersect(
                sourceGeometry, targetToIntersect, dimension);

            _msg.VerboseDebug("Simplifying...");

            GeometryUtils.Simplify(intersection);

            Marshal.ReleaseComObject(targetToIntersect);

            if (!intersection.IsEmpty)
            {
                return(intersection);
            }

            return(null);
        }
        private static bool IsPathFullyCovered(
            [NotNull] IPath path,
            [NotNull] IPolygon insideSourcePolygon,
            [NotNull] IEnumerable <CutSubcurve> bySubCurves)
        {
            IPolyline classicCurvesPolyline = GeometryFactory.CreateEmptyPolyline(path);

            object missing = Type.Missing;

            foreach (IPath classicCurve in bySubCurves.Select(
                         cutSubcurve => cutSubcurve.Path))
            {
                ((IGeometryCollection)classicCurvesPolyline).AddGeometry(classicCurve,
                                                                         ref missing,
                                                                         ref missing);
            }

            IGeometry highLevelPath = GeometryUtils.GetHighLevelGeometry(path);

            IGeometry highLevelPathInside =
                IntersectionUtils.GetIntersectionLines(
                    (IPolyline)highLevelPath, insideSourcePolygon, true, true);

            IGeometry difference =
                ReshapeUtils.GetDifferencePolyline(
                    (IPolyline)highLevelPathInside, classicCurvesPolyline);

            // Test: Simplify required?

            return(difference.IsEmpty);
        }
Пример #7
0
        public static IPolyline GetLinearIntersection([NotNull] IPolyline line,
                                                      [NotNull] IGeometry geometry,
                                                      double?xyTolerance = null)
        {
            // the lines are often very short and close to each other --> xy cluster tolerance workaround is used far too often
            // --> test for IRelationalOperator.Equals at least if lines are very short?
            // --> if equal, return a clone of 'line'?

            if (xyTolerance != null)
            {
                double maxLengthWorkaround = xyTolerance.Value * 6;

                if (line.Length <= maxLengthWorkaround)
                {
                    var otherLine = geometry as IPolyline;

                    if (otherLine != null && otherLine.Length < maxLengthWorkaround)
                    {
                        if (((IRelationalOperator)line).Equals(otherLine))
                        {
                            return(GeometryFactory.Clone(line));
                        }
                    }
                }
            }

            return((IPolyline)IntersectionUtils.Intersect(
                       line, geometry,
                       esriGeometryDimension.esriGeometry1Dimension));
        }
Пример #8
0
        private bool BelongsToLargeGap([NotNull] IPolygon crossingGap)
        {
            Assert.ArgumentNotNull(crossingGap, nameof(crossingGap));

            var gapRelOp  = (IRelationalOperator)crossingGap;
            var gapTopoOp = (ITopologicalOperator)crossingGap;

            foreach (IPolyline intersection in _largeGapCuttingEdgeIntersections)
            {
                if (gapRelOp.Disjoint(intersection))
                {
                    continue;
                }

                IGeometry linearIntersection = IntersectionUtils.Intersect(
                    gapTopoOp, intersection, esriGeometryDimension.esriGeometry1Dimension);

                try
                {
                    if (!linearIntersection.IsEmpty)
                    {
                        return(true);
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(linearIntersection);
                }
            }

            return(false);
        }
Пример #9
0
        public bool CheckBounds(Bounds bounds, List <GameObject> objects, List <GameObject> ignoreList = null)
        {
            var result = false;

            k_Renderers.Clear();
            if (m_SpatialHashContainer.GetIntersections(k_Renderers, bounds))
            {
                for (var i = 0; i < k_Renderers.Count; i++)
                {
                    var renderer = k_Renderers[i];
                    if (ignoreList != null && ignoreList.Contains(renderer.gameObject))
                    {
                        continue;
                    }

                    var transform = renderer.transform;

                    IntersectionUtils.SetupCollisionTester(m_CollisionTester, transform);

                    if (IntersectionUtils.TestBox(m_CollisionTester, transform, bounds.center, bounds.extents, Quaternion.identity))
                    {
                        objects.Add(renderer.gameObject);
                        result = true;
                    }
                }
            }

            return(result);
        }
Пример #10
0
        /// <summary>
        /// Gets the intersection points (also including linear intersection end points) between crossingLine crosses the
        /// and polycurveToCross excluding start and end point of the crossingLine. This is not the same as interior intersection.
        /// </summary>
        /// <param name="crossingLine"></param>
        /// <param name="polycurveToCross"></param>
        /// <returns></returns>
        private static IPointCollection GetCrossingPoints([NotNull] ICurve crossingLine,
                                                          [NotNull] IGeometry
                                                          polycurveToCross)
        {
            // TODO: extracted from GetCrossingPointCount (various copies) -> move to ReshapeUtils

            IGeometry highLevelCrossingLine =
                GeometryUtils.GetHighLevelGeometry(crossingLine);

            // NOTE: IRelationalOperator.Crosses() does not find cases where the start point is tangential and
            //		 neither it finds cases where there is also a 1-dimensional intersection in addition to a point-intersection
            // NOTE: use GeometryUtils.GetIntersectionPoints to find also these cases where some intersections are 1-dimensional
            var intersectionPoints =
                (IPointCollection)
                IntersectionUtils.GetIntersectionPoints(polycurveToCross,
                                                        highLevelCrossingLine);

            // count the points excluding start and end point of the crossing line
            var result =
                (IPointCollection)GeometryFactory.CreateEmptyMultipoint(polycurveToCross);

            foreach (IPoint point in GeometryUtils.GetPoints(intersectionPoints))
            {
                if (GeometryUtils.AreEqualInXY(point, crossingLine.FromPoint) ||
                    GeometryUtils.AreEqualInXY(point, crossingLine.ToPoint))
                {
                    continue;
                }

                result.AddPoint(point);
            }

            return(result);
        }
Пример #11
0
        public bool CheckSphere(Vector3 center, float radius, List <GameObject> objects, List <GameObject> ignoreList = null)
        {
            var result = false;

            k_Renderers.Clear();
            var bounds = new Bounds(center, radius * 2 * Vector3.one);

            if (m_SpatialHashContainer.GetIntersections(k_Renderers, bounds))
            {
                for (var i = 0; i < k_Renderers.Count; i++)
                {
                    var renderer = k_Renderers[i];
                    if (ignoreList != null && ignoreList.Contains(renderer.gameObject))
                    {
                        continue;
                    }

                    var transform = renderer.transform;

                    IntersectionUtils.SetupCollisionTester(m_CollisionTester, transform);

                    if (IntersectionUtils.TestSphere(m_CollisionTester, transform, center, radius))
                    {
                        objects.Add(renderer.gameObject);
                        result = true;
                    }
                }
            }

            return(result);
        }
Пример #12
0
        private static IGeometry GetLineCrossings([NotNull] IFeature feature1,
                                                  [NotNull] IFeature feature2)
        {
            var shape1 = (IPolyline)feature1.Shape;
            var shape2 = (IPolyline)feature2.Shape;

            return(IntersectionUtils.GetLineCrossings(shape1, shape2));
        }
Пример #13
0
        public static int ReportIntersections(
            [NotNull] IRow row1, int tableIndex1,
            [NotNull] IRow row2, int tableIndex2,
            [NotNull] IErrorReporting errorReporting,
            [CanBeNull] IssueCode issueCode,
            [CanBeNull] IValidRelationConstraint validRelationConstraint,
            bool reportIndividualParts,
            [CanBeNull] GeometryConstraint validIntersectionGeometryConstraint = null,
            GeometryComponent geomComponent1 = GeometryComponent.EntireGeometry,
            GeometryComponent geomComponent2 = GeometryComponent.EntireGeometry)
        {
            Assert.ArgumentNotNull(row1, nameof(row1));
            Assert.ArgumentNotNull(row2, nameof(row2));
            Assert.ArgumentNotNull(errorReporting, nameof(errorReporting));

            if (row1 == row2)
            {
                return(_noError);
            }

            string errorDescription;

            if (HasFulfilledConstraint(row1, tableIndex1,
                                       row2, tableIndex2,
                                       validRelationConstraint, "Features intersect",
                                       out errorDescription))
            {
                return(_noError);
            }

            IGeometry shape1 = ((IFeature)row1).Shape;
            IGeometry shape2 = ((IFeature)row2).Shape;

            var g1 = GeometryComponentUtils.GetGeometryComponent(shape1, geomComponent1);
            var g2 = GeometryComponentUtils.GetGeometryComponent(shape2, geomComponent2);

            var errorCount = 0;

            if (g1 != null && g2 != null)
            {
                foreach (IGeometry errorGeometry in
                         IntersectionUtils.GetAllIntersections(g1, g2))
                {
                    if (validIntersectionGeometryConstraint == null ||
                        !validIntersectionGeometryConstraint.IsFulfilled(errorGeometry))
                    {
                        errorCount += errorReporting.Report(errorDescription,
                                                            errorGeometry,
                                                            issueCode, reportIndividualParts,
                                                            row1, row2);
                    }
                }
            }

            return(errorCount);
        }
Пример #14
0
        private IMultipoint CalculateSourceIntersections(
            [NotNull] IEnumerable <IPolycurve> sourceGeometries)
        {
            IMultipoint sourceIntersectionPoints = null;
            IPolyline   sourceIntersectionLines  = null;

            foreach (
                KeyValuePair <IPolycurve, IPolycurve> pair in
                CollectionUtils.GetAllTuples(sourceGeometries))
            {
                IPolycurve polycurve1 = pair.Key;
                IPolycurve polycurve2 = pair.Value;

                IPolyline intersectionLines =
                    GeometryFactory.CreateEmptyPolyline(polycurve1);

                IMultipoint intersectionPoints =
                    IntersectionUtils.GetIntersectionPoints(
                        polycurve1, polycurve2, false,
                        IntersectionPointOptions.IncludeLinearIntersectionEndpoints,
                        intersectionLines);

                if (sourceIntersectionPoints == null)
                {
                    sourceIntersectionPoints = intersectionPoints;
                }
                else
                {
                    ((IPointCollection)sourceIntersectionPoints).AddPointCollection(
                        (IPointCollection)intersectionPoints);
                }

                if (intersectionLines != null && !intersectionLines.IsEmpty)
                {
                    if (sourceIntersectionLines == null)
                    {
                        sourceIntersectionLines = intersectionLines;
                    }
                    else
                    {
                        ((IGeometryCollection)sourceIntersectionLines).AddGeometryCollection(
                            (IGeometryCollection)intersectionLines);
                    }
                }
            }

            Assert.NotNull(sourceIntersectionPoints);

            GeometryUtils.Simplify(sourceIntersectionPoints);

            // un-simplified!
            _sourceIntersectionLines = sourceIntersectionLines;

            return(sourceIntersectionPoints);
        }
Пример #15
0
        public void CanReadWriteSingleExteriorRingWithIslandsPolygonXyz()
        {
            ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            IPolygon outerRing =
                GeometryFactory.CreatePolygon(2600000, 1200000, 2601000, 1201000, 432);

            outerRing.SpatialReference = sr;

            IPolygon innerRing =
                GeometryFactory.CreatePolygon(2600100, 1200100, 2600200, 1200200, 321);

            innerRing.SpatialReference = sr;

            IPolygon polyWithHole = (IPolygon)IntersectionUtils.Difference(outerRing, innerRing);

            WkbGeometryWriter writer = new WkbGeometryWriter();

            byte[] wkb = writer.WritePolygon(polyWithHole);

            // Wkx
            var       ordinates    = Ordinates.Xyz;
            IGeometry exteriorRing = GeometryUtils.GetParts(polyWithHole).First();
            IGeometry interiorRing = GeometryUtils.GetPaths(polyWithHole).Last();

            LinearRing wkxOuterRing = ToWkxLinearRing(exteriorRing, ordinates);
            LinearRing wkxInnerRing = ToWkxLinearRing(interiorRing, ordinates);

            byte[] wkx = ToChristianSchwarzWkb(ToWkxPolygon(wkxOuterRing, new[] { wkxInnerRing }));
            Assert.AreEqual(wkx, wkb);

            // Bonus test: Geom
            WkbGeomWriter geomWriter = new WkbGeomWriter();
            RingGroup     ringGroup  = GeometryConversionUtils.CreateRingGroup(polyWithHole);

            byte[] wkbGeom = geomWriter.WritePolygon(ringGroup, ordinates);
            Assert.AreEqual(wkb, wkbGeom);

            WkbGeometryReader reader = new WkbGeometryReader();

            IPolygon restored = reader.ReadPolygon(new MemoryStream(wkb));

            Assert.IsTrue(GeometryUtils.AreEqual(polyWithHole, restored));

            // Geom:
            WkbGeomReader geomReader = new WkbGeomReader();

            Assert.IsTrue(
                ringGroup.Equals(geomReader.ReadPolygon(new MemoryStream(wkbGeom))));
        }
Пример #16
0
        private static IPath GetSharedBoundaryProlongation([NotNull] ICurve curveToReshape,
                                                           [NotNull] IPath
                                                           sourceReplacementPath,
                                                           bool atSourceReplacementFromPoint,
                                                           [NotNull] IPath reshapePath,
                                                           double tolerance,
                                                           out IPoint targetConnectPoint)
        {
            IPoint sourceConnectPoint = atSourceReplacementFromPoint
                                                            ? sourceReplacementPath.FromPoint
                                                            : sourceReplacementPath.ToPoint;

            // try elongate the curveToReshape's last segment that's not part of the replacement path
            ISegment sourceSegment = GetConnectSegment(sourceReplacementPath, curveToReshape,
                                                       sourceConnectPoint, tolerance);

            IPath result = ReshapeUtils.GetProlongation(curveToReshape, sourceSegment,
                                                        reshapePath,
                                                        out targetConnectPoint);

            if (result == null)
            {
                // check if the reshape path intersects the source segment:
                IGeometry highLevelSourceSegment =
                    GeometryUtils.GetHighLevelGeometry(sourceSegment, true);

                IGeometry highLevelReshapePath = GeometryUtils.GetHighLevelGeometry(reshapePath,
                                                                                    true);

                var intersectionPoints =
                    (IPointCollection)IntersectionUtils.GetIntersectionPoints(
                        highLevelReshapePath,
                        highLevelSourceSegment, false);

                if (intersectionPoints.PointCount == 1)
                {
                    result             = CreateSinglePointPath(intersectionPoints.Point[0]);
                    targetConnectPoint = intersectionPoints.Point[0];
                }
                else
                {
                    _msg.DebugFormat(
                        "The source last shared segment has {0} intersection points with the reshape path. Currently not supported",
                        intersectionPoints.PointCount);
                }
            }

            return(result);
        }
Пример #17
0
        protected static IPolyline GetGeometryAlongBorder(
            [NotNull] IFeature borderFeature,
            [NotNull] IPolyline line)
        {
            IGeometry border = borderFeature.Shape;

            if (border.GeometryType == esriGeometryType.esriGeometryPolygon)
            {
                border = ((ITopologicalOperator)border).Boundary;
            }

            return((IPolyline)IntersectionUtils.Intersect(
                       line, border,
                       esriGeometryDimension.esriGeometry1Dimension));
        }
Пример #18
0
        public bool Raycast(Ray ray, out RaycastHit hit, out GameObject obj, float maxDistance = Mathf.Infinity, List <GameObject> ignoreList = null)
        {
            obj = null;
            hit = new RaycastHit();
            var result   = false;
            var distance = Mathf.Infinity;

            k_Renderers.Clear();
            if (m_SpatialHashContainer.GetIntersections(k_Renderers, ray, maxDistance))
            {
                for (int i = 0; i < k_Renderers.Count; i++)
                {
                    var renderer = k_Renderers[i];
                    if (ignoreList != null && ignoreList.Contains(renderer.gameObject))
                    {
                        continue;
                    }

                    // Skip destroyed objects
                    if (renderer == null)
                    {
                        continue;
                    }

                    var transform = renderer.transform;

                    IntersectionUtils.SetupCollisionTester(m_CollisionTester, transform);

                    RaycastHit tmp;
                    if (IntersectionUtils.TestRay(m_CollisionTester, transform, ray, out tmp, maxDistance))
                    {
                        var point = transform.TransformPoint(tmp.point);
                        var dist  = Vector3.Distance(point, ray.origin);
                        if (dist < distance)
                        {
                            result       = true;
                            distance     = dist;
                            hit.distance = dist;
                            hit.point    = point;
                            hit.normal   = transform.TransformDirection(tmp.normal);
                            obj          = renderer.gameObject;
                        }
                    }
                }
            }

            return(result);
        }
Пример #19
0
        public void CanCutMultipatchWithVerticalWallsThroughVerticalWallsSnapped()
        {
            // {FE286920-3D4C-4CB3-AC22-51056B97A23F} from TLM:
            IFeature mockFeature =
                TestUtils.CreateMockFeature("MultipatchWithVerticalWalls.xml");

            ISpatialReference lv95 = mockFeature.Shape.SpatialReference;

            IPolyline cutLine = GeometryFactory.CreateLine(
                GeometryFactory.CreatePoint(2574923.000, 1196869.000, lv95),
                GeometryFactory.CreatePoint(2574912.000, 1196885.000, lv95));

            IPolygon origFootprint = GeometryFactory.CreatePolygon(mockFeature.Shape);

            cutLine =
                IntersectionUtils.GetIntersectionLines(
                    cutLine, origFootprint, true, true);

            double originalArea = ((IArea3D)mockFeature.Shape).Area3D;

            var cutter = new FeatureCutter(new[] { mockFeature });

            cutter.ZSourceProvider =
                new DatasetSpecificSettingProvider <ChangeAlongZSource>(
                    string.Empty, ChangeAlongZSource.SourcePlane);

            cutter.Cut(cutLine);

            IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature];

            Assert.AreEqual(2, results.Count);

            double areaSum    = 0;
            var    totalParts = 0;

            foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature])
            {
                Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result));

                totalParts += ((IGeometryCollection)result).GeometryCount;

                areaSum += ((IArea3D)result).Area3D;
            }

            Assert.AreEqual(7, totalParts);

            Assert.IsTrue(MathUtils.AreEqual(originalArea, areaSum, 0.01));
        }
Пример #20
0
        private static IPointCollection GetFilteredPoints(IPointCollection inputPoints,
                                                          IGeometry subSelectionPerimeter)
        {
            IPointCollection resultPoints;

            if (subSelectionPerimeter == null)
            {
                resultPoints = (IPointCollection)GeometryFactory.Clone((IGeometry)inputPoints);
            }
            else
            {
                resultPoints = (IPointCollection)IntersectionUtils.GetIntersectionPoints(
                    subSelectionPerimeter, (IGeometry)inputPoints);
            }

            return(resultPoints);
        }
        /// <summary>
        /// Gets the number of times the crossingLine crosses the polylineToCross excluding start and end point
        /// of the crossingLine. This is not the same as interior-intersects.
        /// </summary>
        /// <param name="crossingLine"></param>
        /// <param name="polylineToCross"></param>
        /// <returns></returns>
        private static int GetCrossingPointCount([NotNull] ICurve crossingLine,
                                                 [NotNull] IPolyline polylineToCross)
        {
            // TODO: copy from ConnectLineCalculatorBase -> move to ReshapeUtils
            IGeometry highLevelCrossingLine =
                GeometryUtils.GetHighLevelGeometry(crossingLine, true);

            // NOTE: IRelationalOperator.Crosses() does not find cases where the start point is tangential and
            //		 neither it finds cases where there is also a 1-dimensional intersection in addition to a point-intersection
            // NOTE: use GeometryUtils.GetIntersectionPoints to find also these cases where some intersections are 1-dimensional
            var intersectionPoints =
                (IPointCollection)
                IntersectionUtils.GetIntersectionPoints(polylineToCross,
                                                        highLevelCrossingLine);

            // count the points excluding start and end point of the crossing line
            var crossingPointCount = 0;

            for (var i = 0; i < intersectionPoints.PointCount; i++)
            {
                intersectionPoints.QueryPoint(i, _pointTemplate);

                if (GeometryUtils.AreEqualInXY(_pointTemplate, crossingLine.FromPoint) ||
                    GeometryUtils.AreEqualInXY(_pointTemplate, crossingLine.ToPoint))
                {
                    continue;
                }

                crossingPointCount++;
            }

            if (crossingPointCount > 0 && _msg.IsVerboseDebugEnabled)
            {
                _msg.DebugFormat(
                    "Intersections between crossing line {0} and polylineToCross: {1}",
                    GeometryUtils.ToString(crossingLine),
                    GeometryUtils.ToString((IMultipoint)intersectionPoints));
            }

            if (highLevelCrossingLine != crossingLine)
            {
                Marshal.ReleaseComObject(highLevelCrossingLine);
            }

            return(crossingPointCount);
        }
Пример #22
0
 private static IEnumerable <IGeometry> GetRelevantIntersections(
     [NotNull] IGeometry g1,
     [NotNull] IGeometry g2,
     Dimension maximumDimension)
 {
     foreach (IGeometry geometry in IntersectionUtils.GetAllIntersections(g1, g2))
     {
         if (HasEqualOrLowerDimension(geometry, maximumDimension))
         {
             Simplify(geometry);
             yield return(geometry);
         }
         else
         {
             Marshal.ReleaseComObject(geometry);
         }
     }
 }
Пример #23
0
        private static IPath TrimCutLine([NotNull] IPath cutLine,
                                         [NotNull] IPolygon originalPolygon,
                                         [NotNull] IList <IGeometry> cutGeometries)
        {
            var intersectionPoints =
                (IPointCollection)IntersectionUtils.GetIntersectionPoints(
                    (IPolyline)GeometryUtils.GetHighLevelGeometry(cutLine),
                    originalPolygon, true,
                    IntersectionPointOptions.IncludeLinearIntersectionEndpoints);

            double tolerance = GeometryUtils.GetXyTolerance(originalPolygon);

            var highLevelPath = (IPolyline)GeometryUtils.GetHighLevelGeometry(cutLine);

            List <KeyValuePair <IPoint, double> > orderedIntersections =
                GeometryUtils.GetDistancesAlongPolycurve(
                    intersectionPoints, highLevelPath, tolerance, false);

            // ascending sort order
            orderedIntersections.Sort((x, y) => x.Value.CompareTo(y.Value));

            double fromDistance =
                GetFirstIntersectionTouchingTwoGeometries(
                    orderedIntersections, cutGeometries);

            orderedIntersections.Reverse();

            double toDistance = GetFirstIntersectionTouchingTwoGeometries(
                orderedIntersections, cutGeometries);

            ICurve result;

            if (fromDistance >= 0 && toDistance >= 0)
            {
                cutLine.GetSubcurve(fromDistance, toDistance, false, out result);
            }
            else
            {
                result = cutLine;
            }

            return((IPath)result);
        }
        protected IPolyline RemoveVerticesBeyondBarrier([NotNull] IPolyline originalPolyline,
                                                        [NotNull] IPolyline
                                                        polylineWithUpdatedEnd,
                                                        [NotNull] IPoint newEndPoint,
                                                        bool newEndAtFromPoint)
        {
            var intersectionPoints =
                (IPointCollection)IntersectionUtils.GetIntersectionPoints(
                    originalPolyline, BarrierGeometryChanged, true,
                    IntersectionPointOptions.IncludeLinearIntersectionEndpoints);

            if (intersectionPoints.PointCount != 0)
            {
                IPolyline cracked = GeometryFactory.Clone(polylineWithUpdatedEnd);

                const bool createParts = true;
                const bool projectPointsOntoPathToSplit = true;
                GeometryUtils.CrackPolycurve(cracked, intersectionPoints,
                                             projectPointsOntoPathToSplit, createParts);

                IPoint unChangedPoint = newEndAtFromPoint
                                                                ? polylineWithUpdatedEnd.ToPoint
                                                                : polylineWithUpdatedEnd.FromPoint;

                foreach (IPath subCurve in GeometryUtils.GetPaths(cracked))
                {
                    var highLevelSubCurve =
                        (IPolyline)GeometryUtils.GetHighLevelGeometry(subCurve, true);

                    if (GeometryUtils.Intersects(highLevelSubCurve, unChangedPoint))
                    {
                        // re-apply the end point - this could still result in bbarrier crossings, but only on the last segment
                        SetEndpoint(highLevelSubCurve, newEndPoint, newEndAtFromPoint);

                        polylineWithUpdatedEnd = highLevelSubCurve;
                        break;
                    }
                }
            }

            return(polylineWithUpdatedEnd);
        }
Пример #25
0
        private static bool PathRunsAlongSeveralPolygons(
            [NotNull] IPath path, [NotNull] IList <IGeometry> allPolygons,
            [NotNull] IPoint startingAt, out IList <IGeometry> alongPolygons)
        {
            alongPolygons = new List <IGeometry>(allPolygons.Count);

            var touchCount = 0;

            IGeometry highLevelPath = GeometryUtils.GetHighLevelGeometry(path, true);

            foreach (IGeometry polygon in allPolygons)
            {
                // NOTE: Using GeometryUtils.Touches and Intersection of highLevelPath with polygon is very slow!
                //       -> extract only the relevant segments
                IPolyline polygonOutlinePart = TryGetAdjacentSegmentsAsPolyline(
                    (IPolygon)polygon, startingAt);

                if (polygonOutlinePart == null || polygonOutlinePart.IsEmpty)
                {
                    continue;
                }

                IPolyline lineAlongBoundary = IntersectionUtils.GetIntersectionLines(
                    polygonOutlinePart, (IPolycurve)highLevelPath, true, true);

                if (!lineAlongBoundary.IsEmpty)
                {
                    touchCount++;

                    alongPolygons.Add(polygon);
                }

                Marshal.ReleaseComObject(polygonOutlinePart);
                Marshal.ReleaseComObject(lineAlongBoundary);
            }

            Marshal.ReleaseComObject(highLevelPath);

            return(touchCount > 1);
        }
Пример #26
0
        public static IMultipoint GetInvalidIntersections(
            [NotNull] IPolyline polyline1,
            [NotNull] IPolyline polyline2,
            AllowedEndpointInteriorIntersections allowedEndpointInteriorIntersections,
            AllowedLineInteriorIntersections allowedLineInteriorIntersections,
            bool reportOverlaps,
            double vertexSearchDistance)
        {
            Assert.ArgumentNotNull(polyline1, nameof(polyline1));
            Assert.ArgumentNotNull(polyline2, nameof(polyline2));

            IntersectionPointOptions intersectionPointOptions =
                reportOverlaps
                                        ? IntersectionPointOptions.IncludeLinearIntersectionEndpoints
                                        : IntersectionPointOptions.DisregardLinearIntersections;

            // NOTE: this does not reliably find endpoint/interior intersections -> empty!! (even if Disjoint does return false)
            const bool  assumeIntersecting = true;
            IMultipoint intersections      = IntersectionUtils.GetIntersectionPoints(polyline1,
                                                                                     polyline2,
                                                                                     assumeIntersecting,
                                                                                     intersectionPointOptions);

            // TODO catch missed end point/interior intersections by checking end points explicitly

            if (intersections.IsEmpty)
            {
                return(intersections);
            }

            intersections = RemoveAllowedEndPointIntersections(intersections,
                                                               polyline1, polyline2,
                                                               allowedEndpointInteriorIntersections,
                                                               vertexSearchDistance);

            return(RemoveAllowedInteriorIntersections(intersections,
                                                      polyline1, polyline2,
                                                      allowedLineInteriorIntersections,
                                                      vertexSearchDistance));
        }
Пример #27
0
        public static IList <IGeometry> TryCut([NotNull] IPolyline inputPolyline,
                                               [NotNull] IPolyline cutPolyline)
        {
            var splitPoints = (IPointCollection)
                              IntersectionUtils.GetIntersectionPoints(inputPolyline, cutPolyline);

            if (splitPoints.PointCount == 0)
            {
                return(null);
            }

            List <IGeometry> splitGeometries =
                GeometryUtils.GetPartCount(inputPolyline) > 1
                                        ? SplitMultipartPolyline(inputPolyline, cutPolyline, splitPoints)
                                        : SplitPolyline(inputPolyline, splitPoints);

            // largest first
            splitGeometries.Sort(CompareGeometrySize);
            splitGeometries.Reverse();

            return(splitGeometries);
        }
Пример #28
0
        public static IEnumerable <LineIntersection> GetIntersections(
            [NotNull] IPolyline polyline1,
            [NotNull] IPolyline polyline2,
            bool is3D)
        {
            const bool  assumeIntersecting = true;
            IMultipoint intersections      =
                IntersectionUtils.GetIntersectionPoints(
                    polyline1, polyline2,
                    assumeIntersecting,
                    IntersectionPointOptions.DisregardLinearIntersections);

            if (intersections.IsEmpty)
            {
                yield break;
            }

            IEnumVertex enumIntersectionPoints =
                ((IPointCollection)intersections).EnumVertices;

            do
            {
                int vertexIndex;
                int outPartIndex;
                enumIntersectionPoints.QueryNext(TemplatePoint1,
                                                 out outPartIndex,
                                                 out vertexIndex);

                if (outPartIndex < 0 || vertexIndex < 0)
                {
                    break;
                }

                var intersection = new LineIntersection(polyline1, polyline2,
                                                        TemplatePoint1, is3D);
                yield return(intersection);
            } while (true);
        }
Пример #29
0
        private static IPolyline GetLinearIntersection(
            [NotNull] IPolygon polygon,
            [NotNull] IPolyline polyline)
        {
            var polygonTopoOp = (ITopologicalOperator)polygon;

            var result = (IPolyline)IntersectionUtils.Intersect(
                polygonTopoOp, polyline, esriGeometryDimension.esriGeometry1Dimension);

            if (result.IsEmpty)
            {
                return(null);
            }

            const bool allowReorder = true;
            const bool allowPathSplitAtIntersections = false;

            GeometryUtils.Simplify(result, allowReorder, allowPathSplitAtIntersections);

            GeometryUtils.AllowIndexing(result);

            return(result);
        }
Пример #30
0
        private static IPolyline VerifyZOnlyDifferences(IPolyline sourcePolyline,
                                                        IPolyline targetPolyline,
                                                        int expectedResultLength,
                                                        double zTolerance = 0)
        {
            IPolyline geomOpResult = IntersectionUtils.GetZOnlyDifferenceLines(
                sourcePolyline, targetPolyline, zTolerance);

            Assert.IsNotNull(geomOpResult);
            Assert.AreEqual(expectedResultLength, Math.Round(geomOpResult.Length, 3));

            IPolyline legacyResult =
                ReshapeUtils.GetZOnlyDifferenceLegacy(sourcePolyline,
                                                      targetPolyline, zTolerance);

            Assert.IsNotNull(legacyResult);

            Assert.AreEqual(expectedResultLength, Math.Round(legacyResult.Length, 3));

            GeometryUtils.AreEqual(geomOpResult, legacyResult);

            return(geomOpResult);
        }