Exemple #1
0
        public void CanCreateFeatureWithoutTableSchema()
        {
            ISpatialReference sr =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95);

            IPolygon shape = GeometryFactory.CreatePolygon(
                GeometryFactory.CreatePoint(2600000, 1200000, sr),
                GeometryFactory.CreatePoint(2600050, 1200080, sr));

            GdbObjectMsg featureMsg = new GdbObjectMsg
            {
                ClassHandle = -1,
                ObjectId    = 42,
                Shape       = ProtobufGeometryUtils.ToShapeMsg(shape)
            };

            GdbFeatureClass fClass =
                new GdbFeatureClass(1, "Test", esriGeometryType.esriGeometryPolygon);

            GdbRow gdbRow = ProtobufConversionUtils.FromGdbObjectMsg(featureMsg, fClass);

            GdbFeature feature = (GdbFeature)gdbRow;

            Assert.AreEqual(42, feature.OID);
            Assert.True(GeometryUtils.AreEqual(shape, feature.Shape));
            Assert.AreEqual(1, feature.Class.ObjectClassID);
        }
Exemple #2
0
        private static ServiceCallStatus SendFinalResponse(
            [CanBeNull] QualityVerification verification,
            [CanBeNull] string qaServiceCancellationMessage,
            ConcurrentBag <IssueMsg> issues,
            List <GdbObjRefMsg> deletableAllowedErrors,
            [CanBeNull] IEnvelope verifiedPerimeter,
            Action <VerificationResponse> writeAction)
        {
            var response = new VerificationResponse();

            while (issues.TryTake(out IssueMsg issue))
            {
                response.Issues.Add(issue);
            }

            response.ObsoleteExceptions.AddRange(deletableAllowedErrors);

            ServiceCallStatus finalStatus =
                GetFinalCallStatus(verification, qaServiceCancellationMessage);

            response.ServiceCallStatus = (int)finalStatus;

            if (!string.IsNullOrEmpty(qaServiceCancellationMessage))
            {
                response.Progress = new VerificationProgressMsg
                {
                    Message = qaServiceCancellationMessage
                };
            }

            PackVerification(verification, response);

            if (verifiedPerimeter != null)
            {
                response.VerifiedPerimeter =
                    ProtobufGeometryUtils.ToShapeMsg(verifiedPerimeter);
            }

            _msg.DebugFormat(
                "Sending final message with {0} errors back to client...",
                issues.Count);

            try
            {
                writeAction(response);
            }
            catch (InvalidOperationException ex)
            {
                // For example: System.InvalidOperationException: Only one write can be pending at a time
                _msg.Warn(
                    "Error sending progress to the client. Retrying the last response in 1s...",
                    ex);

                // Re-try (only for final message)
                Task.Delay(1000);
                writeAction(response);
            }

            return(finalStatus);
        }
        public static ShapeMsg GetOpenJawReshapeReplaceEndPoint(
            [NotNull] OpenJawReshapeLineReplacementRequest request,
            [CanBeNull] ITrackCancel trackCancel = null)
        {
            var polylineToReshape =
                (IPolyline)ProtobufGeometryUtils.FromShapeMsg(request.Feature.Shape);
            var reshapeLine =
                (IPolyline)ProtobufGeometryUtils.FromShapeMsg(request.ReshapePath);

            IPoint endPoint = null;

            if (polylineToReshape != null && reshapeLine != null)
            {
                endPoint = ReshapeUtils.GetOpenJawReshapeLineReplaceEndPoint(
                    polylineToReshape, reshapeLine, request.UseNonDefaultReshapeSide);
            }

            if (endPoint == null)
            {
                return(new ShapeMsg());
            }

            ShapeMsg result = ProtobufGeometryUtils.ToShapeMsg(endPoint);

            return(result);
        }
Exemple #4
0
        private DataRequest CreateDataRequest(IQueryFilter filter)
        {
            ShapeMsg searchGeoMsg =
                filter is ISpatialFilter spatialFilter && spatialFilter.Geometry != null
                                        ? ProtobufGeometryUtils.ToShapeMsg(spatialFilter.Geometry)
                                        : null;

            var dataRequest = new DataRequest
            {
                WhereClause    = filter.WhereClause,
                SearchGeometry = searchGeoMsg,
                SubFields      = filter.SubFields
            };

            if (_queryDefinition != null)
            {
                dataRequest.RelQueryDef = _queryDefinition;
            }
            else
            {
                dataRequest.ClassDef = Assert.NotNull(_classDefinition);
            }

            return(dataRequest);
        }
        public void CanConvertPolygonToFromShapeMsg()
        {
            string xmlFile = TestData.GetDensifiedWorkUnitPerimeterPath();

            var polygon = (IPolygon)GeometryUtils.FromXmlFile(xmlFile);

            var shapeMsg = ProtobufGeometryUtils.ToShapeMsg(
                polygon, ShapeMsg.FormatOneofCase.EsriShape,
                SpatialReferenceMsg.FormatOneofCase.SpatialReferenceEsriXml);

            IGeometry rehydrated = ProtobufGeometryUtils.FromShapeMsg(shapeMsg);

            Assert.NotNull(rehydrated);
            Assert.IsTrue(GeometryUtils.AreEqual(polygon, rehydrated));
            Assert.IsTrue(SpatialReferenceUtils.AreEqual(polygon.SpatialReference,
                                                         rehydrated.SpatialReference, true, true));

            // ... and WKB
            var wkbWriter = new WkbGeometryWriter();

            byte[] wkb = wkbWriter.WriteGeometry(polygon);

            var wkbShapeMsg = new ShapeMsg()
            {
                Wkb = ByteString.CopyFrom(wkb)
            };

            IGeometry rehydratedFromWkb = ProtobufGeometryUtils.FromShapeMsg(wkbShapeMsg);

            Assert.IsTrue(GeometryUtils.AreEqual(polygon, rehydratedFromWkb));
            Assert.IsTrue(
                SpatialReferenceUtils.AreEqual(polygon.SpatialReference,
                                               rehydrated.SpatialReference));

            // ... and envelope
            IEnvelope envelope = polygon.Envelope;

            var envShapeMsg = new ShapeMsg()
            {
                Envelope = new EnvelopeMsg()
                {
                    XMin = envelope.XMin,
                    YMin = envelope.YMin,
                    XMax = envelope.XMax,
                    YMax = envelope.YMax
                },
                SpatialReference = new SpatialReferenceMsg()
                {
                    SpatialReferenceWkid =
                        (int)WellKnownHorizontalCS.LV95
                }
            };

            IEnvelope rehydratedEnvelope =
                (IEnvelope)ProtobufGeometryUtils.FromShapeMsg(envShapeMsg);

            Assert.IsTrue(GeometryUtils.AreEqual(envelope, rehydratedEnvelope));
        }
Exemple #6
0
        public void CanGetOpenJawReshapeLineReplaceEndPoint()
        {
            var fClass =
                new GdbFeatureClass(123, "TestFC", esriGeometryType.esriGeometryPolyline);

            var sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95,
                WellKnownVerticalCS.LN02);

            fClass.SpatialReference = sr;

            IPath sourcePath = GeometryFactory.CreatePath(
                GeometryFactory.CreatePoint(2600500, 1200000, sr),
                GeometryFactory.CreatePoint(2600500, 1200500, sr),
                GeometryFactory.CreatePoint(2601000, 1200500, sr));

            sourcePath.SpatialReference = sr;

            IPolyline sourcePolyline = GeometryFactory.CreatePolyline(sourcePath);

            GdbFeature sourceFeature = new GdbFeature(42, fClass)
            {
                Shape = sourcePolyline
            };

            IPath reshapePath = GeometryFactory.CreatePath(
                GeometryFactory.CreatePoint(2600500, 1200500, sr),
                GeometryFactory.CreatePoint(2600500, 1201000, sr));

            reshapePath.SpatialReference = sr;

            IPolyline reshapePolyline = GeometryFactory.CreatePolyline(reshapePath);

            var sourceFeatureMsg = ProtobufGdbUtils.ToGdbObjectMsg(sourceFeature);
            var reshapePathMsg   = ProtobufGeometryUtils.ToShapeMsg(reshapePolyline);

            var request = new OpenJawReshapeLineReplacementRequest
            {
                Feature     = sourceFeatureMsg,
                ReshapePath = reshapePathMsg
            };

            ShapeMsg response =
                AdvancedReshapeServiceUtils.GetOpenJawReshapeReplaceEndPoint(request);

            IPoint resultPoint = (IPoint)ProtobufGeometryUtils.FromShapeMsg(response);

            Assert.IsTrue(GeometryUtils.AreEqual(sourcePolyline.ToPoint, resultPoint));

            // Non-default side:
            request.UseNonDefaultReshapeSide = true;

            response =
                AdvancedReshapeServiceUtils.GetOpenJawReshapeReplaceEndPoint(request);
            resultPoint = (IPoint)ProtobufGeometryUtils.FromShapeMsg(response);

            Assert.IsTrue(GeometryUtils.AreEqual(sourcePolyline.FromPoint, resultPoint));
        }
        public static AdvancedReshapeResponse Reshape(
            [NotNull] AdvancedReshapeRequest request)
        {
            var polyline = (IPolyline)ProtobufGeometryUtils.FromShapeMsg(request.ReshapePaths);

            List <IPath> reshapePaths = GeometryUtils.GetPaths(Assert.NotNull(polyline)).ToList();

            GeometryReshaperBase reshaper = CreateReshaper(request, reshapePaths);

            bool useNonDefaultReshapeSide = request.UseNonDefaultReshapeSide;

            var notifications = new NotificationCollection();

            IDictionary <IGeometry, NotificationCollection> reshapedGeometries =
                reshaper.Reshape(reshapePaths, useNonDefaultReshapeSide, notifications);

            Assert.NotNull(reshapedGeometries, "No reshaped geometries");

            if (reshapedGeometries.Count == 0)
            {
                return(NoReshapeResponse(notifications));
            }

            var response = new AdvancedReshapeResponse();

            if (reshaper.ResultWithinOtherResultButNotInOriginal(
                    reshapedGeometries.Keys, out IPolygon containedPolygon))
            {
                response.OverlapPolygon = ProtobufGeometryUtils.ToShapeMsg(containedPolygon);
            }

            // Messages regarding some of the features that were not reshaped:
            if (notifications.Count > 0 && request.Features.Count > 1)
            {
                string overallMessage = notifications.Concatenate(". ");

                _msg.Info(overallMessage);
                response.WarningMessage = overallMessage;
            }

            // Junction-move, updating of adjacent lines is performed in Save:
            IList <IFeature> storedFeatures = reshaper.Save(reshapedGeometries);

            response.OpenJawReshapeHappened   = reshaper.OpenJawReshapeOcurred;
            response.OpenJawIntersectionCount = reshaper.OpenJawIntersectionPointCount;

            PackReshapeResponseFeatures(response, storedFeatures, reshapedGeometries,
                                        reshaper.OpenJawReshapeOcurred,
                                        reshaper.NotificationIsWarning);

            return(response);
        }
        public void CanConvertPolygonToFromShapeMsgFastEnough()
        {
            string xmlFile = TestData.GetHugeLockergesteinPolygonPath();

            var polygon = (IPolygon)GeometryUtils.FromXmlFile(xmlFile);

            var watch = Stopwatch.StartNew();

            var runCount = 100;

            ShapeMsg shapeMsg = null;

            for (int i = 0; i < runCount; i++)
            {
                shapeMsg = ProtobufGeometryUtils.ToShapeMsg(polygon);
            }

            long dehydrationAvg = watch.ElapsedMilliseconds / runCount;

            Console.WriteLine("Dehydration: {0}ms", dehydrationAvg);

            watch.Restart();

            IPoint point = new PointClass();

            IGeometry rehydrated = null;

            for (int i = 0; i < runCount; i++)
            {
                rehydrated = ProtobufGeometryUtils.FromShapeMsg(shapeMsg);

                // This is almost free:
                ((IPointCollection)rehydrated).QueryPoint(23, point);

                // This results in an extra 45ms on average:
                //point = ((IPointCollection) rehydrated).Point[23];
            }

            long rehydrationAvg = watch.ElapsedMilliseconds / runCount;

            Assert.IsTrue(GeometryUtils.AreEqual(polygon, rehydrated));

            Console.WriteLine("Rehydration: {0}ms", rehydrationAvg);

            Assert.Less(dehydrationAvg, 60);
            Assert.Less(rehydrationAvg, 30);

            // Typical output on a reasonable laptop:
            //Dehydration: 45ms
            //Rehydration: 20ms
        }
        private static ReshapeLineMsg ToReshapeLineMsg([NotNull] CutSubcurve cutSubcurve)
        {
            var result = new ReshapeLineMsg();

            result.Path = ProtobufGeometryUtils.ToShapeMsg(cutSubcurve.Path);

            result.CanReshape  = cutSubcurve.CanReshape;
            result.IsCandidate = cutSubcurve.IsReshapeMemberCandidate;
            result.IsFiltered  = cutSubcurve.IsFiltered;

            result.TargetSegmentAtFrom =
                cutSubcurve.FromPointIsStitchPoint
                                        ? ProtobufGeometryUtils.ToShapeMsg(cutSubcurve.TargetSegmentAtFromPoint)
                                        : null;

            result.TargetSegmentAtTo =
                cutSubcurve.ToPointIsStitchPoint
                                        ? ProtobufGeometryUtils.ToShapeMsg(cutSubcurve.TargetSegmentAtToPoint)
                                        : null;

            if (cutSubcurve.ExtraTargetInsertPoints != null)
            {
                result.ExtraTargetInsertPoints =
                    ProtobufGeometryUtils.ToShapeMsg(
                        GeometryFactory.CreateMultipoint(cutSubcurve.ExtraTargetInsertPoints));
            }

            if (cutSubcurve.Source != null)
            {
                GdbObjectReference sourceObjRef = cutSubcurve.Source.Value;

                result.Source = new GdbObjRefMsg
                {
                    ClassHandle = sourceObjRef.ClassId,
                    ObjectId    = sourceObjRef.ObjectId
                };
            }

            return(result);
        }
Exemple #10
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);
            }
        }
Exemple #11
0
        private static IssueMsg CreateIssueProto(
            [NotNull] IssueFoundEventArgs args,
            [NotNull] IBackgroundVerificationInputs backgroundVerificationInputs)
        {
            QualityCondition qualityCondition =
                args.QualitySpecificationElement.QualityCondition;

            IssueMsg issueProto = new IssueMsg();

            issueProto.ConditionId   = qualityCondition.Id;
            issueProto.Allowable     = args.IsAllowable;
            issueProto.StopCondition = args.Issue.StopCondition;

            CallbackUtils.DoWithNonNull(
                args.Issue.Description, s => issueProto.Description = s);

            IssueCode issueCode = args.Issue.IssueCode;

            if (issueCode != null)
            {
                CallbackUtils.DoWithNonNull(
                    issueCode.ID, s => issueProto.IssueCodeId = s);

                CallbackUtils.DoWithNonNull(
                    issueCode.Description, s => issueProto.IssueCodeDescription = s);
            }

            CallbackUtils.DoWithNonNull(
                args.Issue.AffectedComponent,
                (value) => issueProto.AffectedComponent = value);

            issueProto.InvolvedTables.AddRange(GetInvolvedTableMessages(args.Issue.InvolvedTables));

            CallbackUtils.DoWithNonNull(
                args.LegacyInvolvedObjectsString,
                (value) => issueProto.LegacyInvolvedRows = value);

            IVerificationContext verificationContext =
                Assert.NotNull(backgroundVerificationInputs.VerificationContext);

            var supportedGeometryTypes =
                GetSupportedErrorRepoGeometryTypes(verificationContext).ToList();

            // create valid Error geometry (geometry type, min dimensions) if possible
            IGeometry geometry = ErrorRepositoryUtils.GetGeometryToStore(
                args.ErrorGeometry,
                verificationContext.SpatialReferenceDescriptor.SpatialReference,
                supportedGeometryTypes);

            issueProto.IssueGeometry =
                ProtobufGeometryUtils.ToShapeMsg(geometry);

            // NOTE: Multipatches are not restored from byte arrays in EsriShape (10.6.1)
            ShapeMsg.FormatOneofCase format =
                geometry?.GeometryType == esriGeometryType.esriGeometryMultiPatch
                                        ? ShapeMsg.FormatOneofCase.Wkb
                                        : ShapeMsg.FormatOneofCase.EsriShape;

            issueProto.IssueGeometry =
                ProtobufGeometryUtils.ToShapeMsg(geometry, format);

            issueProto.CreationDateTimeTicks = DateTime.Now.Ticks;

            //issueProto.IsInvalidException = args.us;

            //if (args.IsAllowed)
            //{
            //	issueProto.ExceptedObjRef = new GdbObjRefMsg()
            //	                            {
            //		                            ClassHandle = args.AllowedErrorRef.ClassId,
            //		                            ObjectId = args.AllowedErrorRef.ObjectId
            //	                            };
            //}

            return(issueProto);
        }
Exemple #12
0
        public void CanRemoveOverlaps()
        {
            var fClass =
                new GdbFeatureClass(123, "TestFC", esriGeometryType.esriGeometryPolygon);

            var sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95,
                WellKnownVerticalCS.LN02);

            IPolygon polygon1 = GeometryFactory.CreatePolygon(
                GeometryFactory.CreatePoint(2600000, 1200000, sr),
                GeometryFactory.CreatePoint(2601000, 1201000, sr));

            polygon1.SpatialReference = sr;

            GdbFeature sourceFeature = new GdbFeature(42, fClass)
            {
                Shape = polygon1
            };

            IPolygon polygon2 = GeometryFactory.CreatePolygon(
                GeometryFactory.CreatePoint(2600500, 1200500, sr),
                GeometryFactory.CreatePoint(2601500, 1201500, sr));

            polygon2.SpatialReference = sr;

            GdbFeature targetFeature = new GdbFeature(43, fClass)
            {
                Shape = polygon2
            };

            IPolygon overlap = GeometryFactory.CreatePolygon(
                GeometryFactory.CreatePoint(2600500, 1200500, sr),
                GeometryFactory.CreatePoint(2601000, 1201000, sr));

            overlap.SpatialReference = sr;

            var sourceFeatureMsg = ProtobufGdbUtils.ToGdbObjectMsg(sourceFeature);
            var targetFeatureMsg = ProtobufGdbUtils.ToGdbObjectMsg(targetFeature);

            var objectClassMsg = ProtobufGdbUtils.ToObjectClassMsg(sourceFeature.Class);

            var removeRequest = new RemoveOverlapsRequest()
            {
                ClassDefinitions =
                {
                    objectClassMsg
                },
                SourceFeatures =
                {
                    sourceFeatureMsg
                },
                UpdatableTargetFeatures =
                {
                    targetFeatureMsg
                }
            };

            var overlapsMsg = new OverlapMsg();

            overlapsMsg.OriginalFeatureRef = new GdbObjRefMsg()
            {
                ClassHandle = sourceFeatureMsg.ClassHandle,
                ObjectId    = sourceFeatureMsg.ObjectId
            };

            overlapsMsg.Overlaps.Add(ProtobufGeometryUtils.ToShapeMsg(overlap));

            removeRequest.Overlaps.Add(overlapsMsg);

            RemoveOverlapsResponse removeResponse =
                RemoveOverlapsServiceUtils.RemoveOverlaps(removeRequest);

            Assert.AreEqual(1, removeResponse.ResultsByFeature.Count);
            ResultGeometriesByFeature resultByFeature = removeResponse.ResultsByFeature[0];

            GdbObjectReference originalObjRef = new GdbObjectReference(
                resultByFeature.OriginalFeatureRef.ClassHandle,
                resultByFeature.OriginalFeatureRef.ObjectId);

            Assert.AreEqual(new GdbObjectReference(sourceFeature), originalObjRef);

            IGeometry updatedGeometry =
                ProtobufGeometryUtils.FromShapeMsg(resultByFeature.UpdatedGeometry);

            Assert.IsNotNull(updatedGeometry);
            Assert.AreEqual(1000 * 1000 * 3 / 4, ((IArea)updatedGeometry).Area);

            Assert.AreEqual(0, resultByFeature.NewGeometries.Count);

            IFeature updatedTarget =
                ProtobufConversionUtils.FromGdbObjectMsgList(removeResponse.TargetFeaturesToUpdate,
                                                             removeRequest.ClassDefinitions)
                .Single();

            int pointCount = GeometryUtils.GetPointCount(updatedTarget.Shape);

            Assert.AreEqual(5 + 2, pointCount);
        }
Exemple #13
0
        public void CanAdvancedReshapePolygon()
        {
            var fClass =
                new GdbFeatureClass(123, "TestFC", esriGeometryType.esriGeometryPolygon);

            var sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95,
                WellKnownVerticalCS.LN02);

            fClass.SpatialReference = sr;

            IPolygon polygon1 = GeometryFactory.CreatePolygon(
                GeometryFactory.CreatePoint(2600000, 1200000, sr),
                GeometryFactory.CreatePoint(2601000, 1201000, sr));

            polygon1.SpatialReference = sr;

            GdbFeature sourceFeature = new GdbFeature(42, fClass)
            {
                Shape = polygon1
            };

            IPath reshapePath = GeometryFactory.CreatePath(
                GeometryFactory.CreatePoint(2600500, 1200000, sr),
                GeometryFactory.CreatePoint(2600500, 1200500, sr),
                GeometryFactory.CreatePoint(2601000, 1200500, sr));

            reshapePath.SpatialReference = sr;

            IPolyline reshapePolyline = GeometryFactory.CreatePolyline(reshapePath);

            var sourceFeatureMsg = ProtobufGdbUtils.ToGdbObjectMsg(sourceFeature);
            var reshapePaths     = ProtobufGeometryUtils.ToShapeMsg(reshapePolyline);

            var objectClassMsg = ProtobufGdbUtils.ToObjectClassMsg(sourceFeature.Class);

            AdvancedReshapeRequest request = new AdvancedReshapeRequest()
            {
                ClassDefinitions =
                {
                    objectClassMsg
                },
                Features =
                {
                    sourceFeatureMsg
                },
                ReshapePaths = reshapePaths
            };

            AdvancedReshapeResponse response = AdvancedReshapeServiceUtils.Reshape(request);

            Assert.AreEqual(1, response.ResultFeatures.Count);

            GdbObjectMsg resultFeatureMsg = response.ResultFeatures[0].UpdatedFeature;

            Assert.AreEqual(sourceFeature.OID, resultFeatureMsg.ObjectId);
            Assert.AreEqual(sourceFeature.Class.ObjectClassID, resultFeatureMsg.ClassHandle);

            var resultPoly = (IPolygon)ProtobufGeometryUtils.FromShapeMsg(resultFeatureMsg.Shape);

            Assert.NotNull(resultPoly);

            double oneQuarter = 1000d * 1000d / 4d;

            Assert.AreEqual(3 * oneQuarter, ((IArea)resultPoly).Area);

            // Non-default side:
            request.UseNonDefaultReshapeSide = true;

            response = AdvancedReshapeServiceUtils.Reshape(request);

            Assert.AreEqual(1, response.ResultFeatures.Count);
            resultFeatureMsg = response.ResultFeatures[0].UpdatedFeature;

            resultPoly = (IPolygon)ProtobufGeometryUtils.FromShapeMsg(resultFeatureMsg.Shape);

            Assert.NotNull(resultPoly);

            Assert.AreEqual(oneQuarter, ((IArea)resultPoly).Area);
        }
Exemple #14
0
        public void CanAdvancedReshapePolyline()
        {
            var fClass =
                new GdbFeatureClass(123, "TestFC", esriGeometryType.esriGeometryPolyline);

            var sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95,
                WellKnownVerticalCS.LN02);

            fClass.SpatialReference = sr;

            IPolyline sourcePolyline = CreatePolyline(
                GeometryFactory.CreatePoint(2600500, 1200000, sr),
                GeometryFactory.CreatePoint(2600500, 1200500, sr),
                GeometryFactory.CreatePoint(2601000, 1200500, sr));

            GdbFeature sourceFeature =
                new GdbFeature(42, fClass)
            {
                Shape = sourcePolyline
            };

            IPolyline sourceAdjacentPolyline = CreatePolyline(
                GeometryFactory.CreatePoint(2601000, 1200500, sr),
                GeometryFactory.CreatePoint(2601500, 1200500, sr),
                GeometryFactory.CreatePoint(2601500, 1200000, sr));

            GdbFeature sourceAdjacentFeature =
                new GdbFeature(43, fClass)
            {
                Shape = sourceAdjacentPolyline
            };

            IPolyline reshapePolyline = CreatePolyline(
                GeometryFactory.CreatePoint(2600500, 1200500, sr),
                GeometryFactory.CreatePoint(2600500, 1201000, sr));

            var sourceFeatureMsg         = ProtobufGdbUtils.ToGdbObjectMsg(sourceFeature);
            var reshapePaths             = ProtobufGeometryUtils.ToShapeMsg(reshapePolyline);
            var sourceAdjacentFeatureMsg = ProtobufGdbUtils.ToGdbObjectMsg(sourceAdjacentFeature);

            var objectClassMsg = ProtobufGdbUtils.ToObjectClassMsg(sourceFeature.Class);

            AdvancedReshapeRequest request = new AdvancedReshapeRequest()
            {
                ClassDefinitions =
                {
                    objectClassMsg
                },
                Features =
                {
                    sourceFeatureMsg
                },
                ReshapePaths                 = reshapePaths,
                AllowOpenJawReshape          = true,
                MoveOpenJawEndJunction       = true,
                PotentiallyConnectedFeatures =
                {
                    sourceAdjacentFeatureMsg
                }
            };

            AdvancedReshapeResponse response = AdvancedReshapeServiceUtils.Reshape(request);

            Assert.AreEqual(2, response.ResultFeatures.Count);

            GdbObjectMsg resultFeatureMsg = response.ResultFeatures[1].UpdatedFeature;

            Assert.AreEqual(sourceFeature.OID, resultFeatureMsg.ObjectId);
            Assert.AreEqual(sourceFeature.Class.ObjectClassID, resultFeatureMsg.ClassHandle);

            var resultPolyline =
                (IPolyline)ProtobufGeometryUtils.FromShapeMsg(resultFeatureMsg.Shape);

            Assert.NotNull(resultPolyline);

            Assert.IsTrue(GeometryUtils.AreEqual(resultPolyline.ToPoint, reshapePolyline.ToPoint));

            GdbObjectMsg resultAdjacentFeatureMsg = response.ResultFeatures[0].UpdatedFeature;
            var          resultAdjacentPolyline   =
                (IPolyline)ProtobufGeometryUtils.FromShapeMsg(resultAdjacentFeatureMsg.Shape);

            Assert.NotNull(resultAdjacentPolyline);
            Assert.IsTrue(
                GeometryUtils.AreEqual(resultAdjacentPolyline.FromPoint, reshapePolyline.ToPoint));

            // Non-default side:
            request.UseNonDefaultReshapeSide = true;

            response = AdvancedReshapeServiceUtils.Reshape(request);

            Assert.AreEqual(1, response.ResultFeatures.Count);
            resultFeatureMsg = response.ResultFeatures[0].UpdatedFeature;

            resultPolyline = (IPolyline)ProtobufGeometryUtils.FromShapeMsg(resultFeatureMsg.Shape);

            Assert.NotNull(resultPolyline);

            Assert.IsTrue(
                GeometryUtils.AreEqual(resultPolyline.FromPoint, reshapePolyline.ToPoint));
        }
Exemple #15
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);
        }