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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        private IGeometry CreateAsPolyline(IGeometry highLevelGeometryTemplate)
        {
            IGeometry result =
                GeometryFactory.CreateEmptyPolyline(highLevelGeometryTemplate);

            // ReSharper disable once RedundantEnumerableCastCall
            AddGeometries(LowLevelGeometries.Select(GetPath)
                          .Cast <IGeometry>(),
                          result);

            return(result);
        }
Beispiel #4
0
        private static IPolyline TryGetAdjacentSegmentsAsPolyline(
            [NotNull] IPolygon polygon,
            [NotNull] IPoint startingAt)
        {
            double xyTolerance = GeometryUtils.GetXyTolerance(startingAt);

            int         partIdx;
            const bool  allowNoMatch     = true;
            IList <int> adjacentSegments = SegmentReplacementUtils.GetAdjacentSegmentIndexes(
                polygon, startingAt, xyTolerance, out partIdx, allowNoMatch);

            if (adjacentSegments.Count == 0)
            {
                return(null);
            }

            var segmentList = new List <ISegment>();

            foreach (int segmentIdx in adjacentSegments)
            {
                ISegment segment = GeometryUtils.GetSegment((ISegmentCollection)polygon, partIdx,
                                                            segmentIdx);
                segmentList.Add(GeometryFactory.Clone(segment));
            }

            if (segmentList.Count == 0)
            {
                return(null);
            }

            ISegment[] segments = segmentList.ToArray();

            // create a polyline
            IPolyline result = GeometryFactory.CreateEmptyPolyline(polygon);

            GeometryUtils.GeometryBridge.AddSegments((ISegmentCollection)result,
                                                     ref segments);

            GeometryUtils.Simplify(result);

            return(result);
        }
        private static T CreateEmptyPolycurve <T>(Ordinates ordinates,
                                                  [CanBeNull] IGeometry template = null)
            where T : IPolycurve
        {
            bool createPolygon = typeof(IPolygon).IsAssignableFrom(typeof(T));

            if (template != null)
            {
                return(createPolygon
                                               ? (T)GeometryFactory.CreateEmptyPolygon(template)
                                               : (T)GeometryFactory.CreateEmptyPolyline(template));
            }

            bool zAware = ordinates == Ordinates.Xyz || ordinates == Ordinates.Xyzm;
            bool mAware = ordinates == Ordinates.Xym || ordinates == Ordinates.Xyzm;

            return(createPolygon
                                       ? (T)GeometryFactory.CreatePolygon(null, zAware, mAware)
                                       : (T)GeometryFactory.CreateEmptyPolyline(null, zAware, mAware));
        }
Beispiel #6
0
        public static IPolyline GetDifference([NotNull] IPolyline polyline,
                                              [NotNull] IPolyline otherLine,
                                              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 empty geometry? or null?

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

                if (polyline.Length <= maxLengthWorkaround &&
                    otherLine.Length < maxLengthWorkaround)
                {
                    if (((IRelationalOperator)polyline).Equals(otherLine))
                    {
                        return(GeometryFactory.CreateEmptyPolyline(polyline));
                    }
                }
            }

            return((IPolyline)IntersectionUtils.Difference(polyline, otherLine));
        }