Exemple #1
0
        public static Overlaps GetSelectableOverlaps(
            [NotNull] IEnumerable <IFeature> sourceFeatures,
            [NotNull] IList <IFeature> overlappingFeatures,
            [CanBeNull] ITrackCancel trackCancel = null)
        {
            var result = new Overlaps();

            Stopwatch watch = Stopwatch.StartNew();

            var sourceCount = 0;

            if (overlappingFeatures.Count == 0)
            {
                return(result);
            }

            SpatialHashSearcher <IFeature> targetIndex =
                SpatialHashSearcher <IFeature> .CreateSpatialSearcher(
                    overlappingFeatures, GetEnvelope);

            foreach (IFeature sourceFeature in sourceFeatures)
            {
                if (trackCancel != null && !trackCancel.Continue())
                {
                    _msg.Debug("Overlaps calculation was cancelled.");
                    return(result);
                }

                result.AddGeometries(
                    new GdbObjectReference(sourceFeature),
                    GetSelectableOverlaps(sourceFeature, targetIndex, result.Notifications,
                                          trackCancel).ToList());

                _msg.DebugFormat(
                    "Calculated overlaps for source feature {0}. Current overlaps count: {1}",
                    GdbObjectUtils.ToString(sourceFeature), result.OverlapCount);

                sourceCount++;
            }

            _msg.DebugStopTiming(watch,
                                 "Calculated {0} overlaps between {1} source and {2} target features.",
                                 result.OverlapCount, sourceCount, overlappingFeatures.Count);

            return(result);
        }
        /// <summary>
        /// Calculates the result geometries and adds them to the relevant dictionaries.
        /// </summary>
        /// <param name="fromFeatures"></param>
        /// <param name="overlaps"></param>
        /// <param name="targetFeaturesForVertexInsertion"></param>
        /// <param name="trackCancel"></param>
        public void CalculateResults(
            [NotNull] IEnumerable <IFeature> fromFeatures,
            [NotNull] Overlaps overlaps,
            [CanBeNull] ICollection <IFeature> targetFeaturesForVertexInsertion = null,
            [CanBeNull] ITrackCancel trackCancel = null)
        {
            Assert.ArgumentNotNull(fromFeatures, nameof(fromFeatures));
            Assert.ArgumentNotNull(overlaps, nameof(overlaps));

            foreach (IFeature feature in fromFeatures)
            {
                if (trackCancel != null && !trackCancel.Continue())
                {
                    return;
                }

                var gdbObjRef = new GdbObjectReference(feature);

                IList <IGeometry> overlapsForFeature;
                if (!overlaps.OverlapsBySourceRef.TryGetValue(gdbObjRef, out overlapsForFeature))
                {
                    _msg.DebugFormat("No overlaps for feature {0}", gdbObjRef);
                    continue;
                }

                IPolycurve overlapGeometry = (IPolycurve)GeometryUtils.Union(overlapsForFeature);

                ProcessFeature(feature, overlapGeometry);

                if (targetFeaturesForVertexInsertion != null)
                {
                    // TODO: Filter target features using spatial index!
                    InsertIntersectingVerticesInTargets(targetFeaturesForVertexInsertion,
                                                        overlapGeometry);
                }
            }
        }