Beispiel #1
0
        private static IEnumerable <IPoint> QueryEndpoints([NotNull] IPolyline polyline,
                                                           [NotNull] IPoint template)
        {
            var parts     = (IGeometryCollection)polyline;
            int partCount = parts.GeometryCount;

            if (partCount == 0)
            {
                yield break;
            }

            if (partCount == 1)
            {
                polyline.QueryFromPoint(template);
                yield return(template);

                polyline.QueryToPoint(template);
                yield return(template);
            }
            else
            {
                for (var i = 0; i < partCount; i++)
                {
                    var path = (IPath)parts.Geometry[i];

                    path.QueryFromPoint(template);
                    yield return(template);

                    path.QueryToPoint(template);
                    yield return(template);
                }
            }
        }
Beispiel #2
0
        private static IEnumerable <IPoint> GetEndpoints([NotNull] IPolyline polyline,
                                                         [NotNull] IPoint fromPointTemplate,
                                                         [NotNull] IPoint toPointTemplate)
        {
            polyline.QueryFromPoint(fromPointTemplate);
            polyline.QueryToPoint(toPointTemplate);

            yield return(fromPointTemplate);

            yield return(toPointTemplate);
        }
Beispiel #3
0
        private static CurveMeasureRange CreateMeasureRange([NotNull] IPolyline polyline,
                                                            double mMin, double mMax,
                                                            int oid, int tableIndex,
                                                            int partIndex)
        {
            Assert.ArgumentNotNull(polyline, nameof(polyline));

            var result = new CurveMeasureRange(oid, tableIndex, mMin, mMax, partIndex);

            polyline.QueryFromPoint(_pointTemplate.Value);

            AssignEndPoint(result, _pointTemplate.Value, mMin, mMax);

            polyline.QueryToPoint(_pointTemplate.Value);

            AssignEndPoint(result, _pointTemplate.Value, mMin, mMax);

            return(result);
        }
Beispiel #4
0
        public static bool SnapPoint([NotNull] IPoint newEndPoint,
                                     [NotNull] IList <IFeature> candidateTargetEdges,
                                     [NotNull] ILinearNetworkFeatureFinder networkFeatureFinder)
        {
            if (networkFeatureFinder.SearchTolerance <= 0)
            {
                return(false);
            }

            Pnt2D newEndPnt = new Pnt2D(newEndPoint.X, newEndPoint.Y);

            IPoint fromPoint = new PointClass()
            {
                SpatialReference = newEndPoint.SpatialReference
            };
            IPoint toPoint = new PointClass()
            {
                SpatialReference = newEndPoint.SpatialReference
            };

            double searchToleranceSquared = networkFeatureFinder.SearchTolerance *
                                            networkFeatureFinder.SearchTolerance;

            bool snapped = false;

            foreach (IFeature feature in candidateTargetEdges)
            {
                IPolyline otherPolyline = (IPolyline)feature.Shape;

                otherPolyline.QueryFromPoint(fromPoint);
                Pnt2D fromPnt = new Pnt2D(fromPoint.X, fromPoint.Y);

                double fromDistance2 = fromPnt.Dist2(newEndPnt);

                otherPolyline.QueryToPoint(toPoint);
                Pnt2D toPnt = new Pnt2D(toPoint.X, toPoint.Y);

                double toDistance2 = toPnt.Dist2(newEndPnt);

                if (fromDistance2 > searchToleranceSquared && toDistance2 > searchToleranceSquared)
                {
                    continue;
                }

                if (Math.Min(fromDistance2, toDistance2) < GetXyResolutionSquared(feature))
                {
                    // already snapped
                    continue;
                }

                IPoint sourcePoint = fromDistance2 < toDistance2 ? fromPoint : toPoint;

                snapped = true;
                CopyCoords(sourcePoint, newEndPoint);
            }

            if (!snapped)
            {
                // Try snapping onto curve interior
                foreach (IFeature feature in candidateTargetEdges)
                {
                    IPolyline otherPolyline = (IPolyline)feature.Shape;

                    double distanceFromCurve =
                        GeometryUtils.GetDistanceFromCurve(newEndPoint, otherPolyline, fromPoint);

                    if (distanceFromCurve >= 0 &&
                        distanceFromCurve < networkFeatureFinder.SearchTolerance)
                    {
                        snapped = true;
                        CopyCoords(fromPoint, newEndPoint);
                    }
                }
            }

            return(snapped);
        }