Ejemplo n.º 1
0
        private static void PackResultGeometries(
            [CanBeNull] IList <OverlapResultGeometries> resultsByFeature,
            [NotNull] ICollection <ResultGeometriesByFeature> intoResponseGeometriesByFeature)
        {
            if (resultsByFeature == null)
            {
                return;
            }

            foreach (OverlapResultGeometries resultByFeature in resultsByFeature)
            {
                var feature = resultByFeature.OriginalFeature;

                var resultGeometriesByFeature = new ResultGeometriesByFeature();

                // Original feature's geometry does not need to be transported back.
                resultGeometriesByFeature.OriginalFeatureRef =
                    ProtobufGdbUtils.ToGdbObjRefMsg(feature);

                resultGeometriesByFeature.UpdatedGeometry =
                    ProtobufGeometryUtils.ToShapeMsg(resultByFeature.LargestResult);

                foreach (var insertGeometry in resultByFeature.NonLargestResults)
                {
                    resultGeometriesByFeature.NewGeometries.Add(
                        ProtobufGeometryUtils.ToShapeMsg(insertGeometry));
                }

                foreach (IGeometry newOverlapFeature in resultByFeature.OverlappingGeometries)
                {
                    resultGeometriesByFeature.NewGeometries.Add(
                        ProtobufGeometryUtils.ToShapeMsg(
                            newOverlapFeature));
                }

                intoResponseGeometriesByFeature.Add(resultGeometriesByFeature);
            }
        }
Ejemplo n.º 2
0
        public static CalculateOverlapsResponse CalculateOverlaps(
            [NotNull] CalculateOverlapsRequest request,
            [CanBeNull] ITrackCancel trackCancel)
        {
            var watch = Stopwatch.StartNew();

            IList <IFeature> sourceFeatures =
                ProtobufConversionUtils.FromGdbObjectMsgList(
                    request.SourceFeatures, request.ClassDefinitions);

            IList <IFeature> targetFeatures =
                ProtobufConversionUtils.FromGdbObjectMsgList(
                    request.TargetFeatures, request.ClassDefinitions);

            _msg.DebugStopTiming(watch, "Unpacked feature lists from request params");

            Overlaps selectableOverlaps = RemoveOverlapsUtils.GetSelectableOverlaps(
                sourceFeatures, targetFeatures, trackCancel);

            watch = Stopwatch.StartNew();

            var result = new CalculateOverlapsResponse();

            foreach (var overlapByGdbRef
                     in selectableOverlaps.OverlapsBySourceRef)
            {
                var gdbObjRefMsg = ProtobufGdbUtils.ToGdbObjRefMsg(overlapByGdbRef.Key);

                var overlap = overlapByGdbRef.Value;

                var overlapsMsg = new OverlapMsg()
                {
                    OriginalFeatureRef = gdbObjRefMsg
                };

                foreach (IGeometry geometry in overlap)
                {
                    // TODO: At some point the SR-XY tol/res should be transferred separately (via class-lookup?)
                    var shapeFormat = ShapeMsg.FormatOneofCase.EsriShape;
                    var srFormat    = SpatialReferenceMsg.FormatOneofCase.SpatialReferenceEsriXml;

                    overlapsMsg.Overlaps.Add(
                        ProtobufGeometryUtils.ToShapeMsg(
                            geometry, shapeFormat, srFormat));

                    if (_msg.IsVerboseDebugEnabled)
                    {
                        _msg.VerboseDebug(
                            $"Calculated overlap: {GeometryUtils.ToString(geometry)}");
                    }
                }

                result.Overlaps.Add(overlapsMsg);
            }

            foreach (var notification in selectableOverlaps.Notifications)
            {
                result.Notifications.Add(notification.Message);
            }

            _msg.DebugStopTiming(watch, "Packed overlaps into response");

            return(result);
        }