private static void PackReshapeResponseFeatures(
            AdvancedReshapeResponse result,
            [NotNull] IEnumerable <IFeature> storedFeatures,
            [NotNull] IDictionary <IGeometry, NotificationCollection> reshapedGeometries,
            bool openJawReshapeOccurred,
            bool notificationIsWarning)
        {
            foreach (IFeature storedFeature in storedFeatures)
            {
                IFeature  feature     = storedFeature;
                IGeometry newGeometry = storedFeature.Shape;

                var resultFeature = new ResultObjectMsg();

                GdbObjectMsg resultFeatureMsg =
                    ProtobufGdbUtils.ToGdbObjectMsg(feature, newGeometry,
                                                    storedFeature.Class.ObjectClassID);

                resultFeature.Update = resultFeatureMsg;

                if (reshapedGeometries.ContainsKey(newGeometry) &&
                    (reshapedGeometries[newGeometry] != null))
                {
                    foreach (INotification notification in reshapedGeometries[newGeometry])
                    {
                        resultFeature.Notifications.Add(notification.Message);
                        resultFeature.HasWarning = notificationIsWarning;
                    }
                }

                result.ResultFeatures.Add(resultFeature);
            }
        }
Exemplo n.º 2
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));
        }
        private static void AssertCanConvertToDtoAndBack(GdbFeature feature)
        {
            GdbObjectMsg dehydrated =
                ProtobufGdbUtils.ToGdbObjectMsg(feature);

            var featureClass = (GdbFeatureClass)feature.Class;

            GdbFeature rehydrated = ProtobufConversionUtils.FromGdbFeatureMsg(
                dehydrated, new GdbTableContainer(new[] { featureClass }));

            AssertSameFeature(feature, rehydrated);
        }
Exemplo n.º 4
0
        private static CalculateCutLinesRequest CreateCalculateCutLinesRequest(
            IObject sourceFeature, IObject targetFeature)
        {
            var sourceFeatureMsg = ProtobufGdbUtils.ToGdbObjectMsg(sourceFeature);
            var targetFeatureMsg = ProtobufGdbUtils.ToGdbObjectMsg(targetFeature);

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

            var calculationRequest = new CalculateCutLinesRequest();

            calculationRequest.ClassDefinitions.Add(objectClassMsg);

            calculationRequest.TargetFeatures.Add(targetFeatureMsg);
            calculationRequest.SourceFeatures.Add(sourceFeatureMsg);

            // Use the data tolerance
            calculationRequest.Tolerance = -1;

            return(calculationRequest);
        }
Exemplo n.º 5
0
        public void CanCalculateOverlaps()
        {
            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
            };

            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
            };

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

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

            CalculateOverlapsRequest calculationRequest = new CalculateOverlapsRequest()
            {
                ClassDefinitions =
                {
                    objectClassMsg
                },
                SourceFeatures =
                {
                    sourceFeatureMsg
                },
                TargetFeatures =
                {
                    targetFeatureMsg
                }
            };

            CalculateOverlapsResponse response =
                RemoveOverlapsServiceUtils.CalculateOverlaps(calculationRequest, null);

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

            List <ShapeMsg> shapeBufferList =
                response.Overlaps.SelectMany(kvp => kvp.Overlaps).ToList();

            List <IPolygon> resultPolys =
                ProtobufGeometryUtils.FromShapeMsgList <IPolygon>(shapeBufferList);

            Assert.AreEqual(1, resultPolys.Count);

            Assert.AreEqual(1000 * 1000 / 4, ((IArea)resultPolys[0]).Area);

            // Now the removal:
            RemoveOverlapsRequest removeRequest = new RemoveOverlapsRequest();

            removeRequest.ClassDefinitions.AddRange(calculationRequest.ClassDefinitions);
            removeRequest.SourceFeatures.AddRange(calculationRequest.SourceFeatures);
            removeRequest.Overlaps.Add(response.Overlaps);

            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);

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

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

            Assert.AreEqual(0, resultByFeature.NewGeometries.Count);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void CanCutMultipleSourcesAlong()
        {
            GetOverlappingPolygons(out GdbFeature source1Feature, out GdbFeature source2Feature);

            IFeatureClass fClass = (IFeatureClass)source1Feature.Class;

            IFeature cutFeature = fClass.CreateFeature();

            cutFeature.Shape =
                GeometryFactory.CreatePolygon(
                    GeometryFactory.CreatePoint(2600000, 1200750),
                    GeometryFactory.CreatePoint(2602000, 1202000));
            cutFeature.Store();

            var source1FeatureMsg = ProtobufGdbUtils.ToGdbObjectMsg(source1Feature);
            var source2FeatureMsg = ProtobufGdbUtils.ToGdbObjectMsg(source2Feature);

            var targetFeatureMsg = ProtobufGdbUtils.ToGdbObjectMsg(cutFeature);

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

            var calculationRequest = new CalculateCutLinesRequest();

            calculationRequest.ClassDefinitions.Add(objectClassMsg);
            calculationRequest.SourceFeatures.Add(source1FeatureMsg);
            calculationRequest.SourceFeatures.Add(source2FeatureMsg);

            calculationRequest.TargetFeatures.Add(targetFeatureMsg);

            calculationRequest.Tolerance = -1;

            CalculateCutLinesResponse calculateResponse =
                ChangeAlongServiceUtils.CalculateCutLines(calculationRequest, null);

            Assert.AreEqual(ReshapeAlongCurveUsability.CanReshape,
                            (ReshapeAlongCurveUsability)calculateResponse.ReshapeLinesUsability);

            AssertReshapeLineCount(calculateResponse.CutLines, 2, 2);

            Assert.AreEqual(source1Feature.OID, calculateResponse.CutLines[0].Source.ObjectId);
            Assert.AreEqual(source2Feature.OID, calculateResponse.CutLines[1].Source.ObjectId);

            foreach (ReshapeLineMsg cutLineMsg in calculateResponse.CutLines)
            {
                IPolyline reshapeLine =
                    (IPolyline)ProtobufGeometryUtils.FromShapeMsg(cutLineMsg.Path);

                Assert.NotNull(reshapeLine);
                Assert.AreEqual(1000, reshapeLine.Length);
            }

            //
            // Cutting using just one of the lines:
            //
            var applyRequest = new ApplyCutLinesRequest();

            applyRequest.CutLines.Add(calculateResponse.CutLines[0]);
            applyRequest.CalculationRequest     = calculationRequest;
            applyRequest.InsertVerticesInTarget = false;

            ApplyCutLinesResponse applyResponse =
                ChangeAlongServiceUtils.ApplyCutLines(applyRequest, null);

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

            GdbObjectMsg updatedFeatureMsg =
                applyResponse.ResultFeatures.First(
                    r => r.FeatureCase == ResultObjectMsg.FeatureOneofCase.Update).Update;

            GdbObjectReference updatedObjRef =
                new GdbObjectReference(updatedFeatureMsg.ClassHandle, updatedFeatureMsg.ObjectId);

            Assert.AreEqual(new GdbObjectReference(source1Feature), updatedObjRef);

            // Check the new reshape line:
            AssertReshapeLineCount(applyResponse.NewCutLines, 1, 1);

            Assert.AreEqual(ReshapeAlongCurveUsability.CanReshape,
                            (ReshapeAlongCurveUsability)applyResponse.CutLinesUsability);

            //
            // Cutting using both lines:
            //
            applyRequest = new ApplyCutLinesRequest();

            applyRequest.CutLines.AddRange(calculateResponse.CutLines);
            applyRequest.CalculationRequest     = calculationRequest;
            applyRequest.InsertVerticesInTarget = false;

            applyResponse = ChangeAlongServiceUtils.ApplyCutLines(applyRequest, null);

            Assert.AreEqual(4, applyResponse.ResultFeatures.Count);

            // Check the new reshape line:
            AssertReshapeLineCount(applyResponse.NewCutLines, 0, 0);

            Assert.AreEqual(ReshapeAlongCurveUsability.NoReshapeCurves,
                            (ReshapeAlongCurveUsability)applyResponse.CutLinesUsability);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
0
        public static RemoveOverlapsResponse RemoveOverlaps(
            [NotNull] RemoveOverlapsRequest request,
            [CanBeNull] ITrackCancel trackCancel = null)
        {
            // Unpack request
            bool explodeMultiparts          = request.ExplodeMultipartResults;
            bool storeOverlapsAsNewFeatures = request.StoreOverlapsAsNewFeatures;

            GdbTableContainer container = ProtobufConversionUtils.CreateGdbTableContainer(
                request.ClassDefinitions, null, out _);

            IList <IFeature> selectedFeatureList =
                ProtobufConversionUtils.FromGdbObjectMsgList(
                    request.SourceFeatures, container);

            IList <IFeature> targetFeaturesForVertexInsertion =
                ProtobufConversionUtils.FromGdbObjectMsgList(
                    request.UpdatableTargetFeatures, container);

            Overlaps overlaps = new Overlaps();

            foreach (OverlapMsg overlapMsg in request.Overlaps)
            {
                GdbObjectReference gdbRef = new GdbObjectReference(
                    overlapMsg.OriginalFeatureRef.ClassHandle,
                    overlapMsg.OriginalFeatureRef.ObjectId);

                IFeatureClass fClass = (IFeatureClass)container.GetByClassId(gdbRef.ClassId);

                List <IGeometry> overlapGeometries =
                    ProtobufGeometryUtils.FromShapeMsgList <IGeometry>(
                        overlapMsg.Overlaps,
                        DatasetUtils.GetSpatialReference(fClass));

                overlaps.AddGeometries(gdbRef, overlapGeometries);
            }

            // Remove overlaps
            OverlapsRemover overlapsRemover = RemoveOverlaps(
                selectedFeatureList, overlaps, targetFeaturesForVertexInsertion, explodeMultiparts,
                storeOverlapsAsNewFeatures, trackCancel);

            // Pack response
            var result = overlapsRemover.Result;

            var response = new RemoveOverlapsResponse();

            PackResultGeometries(result.ResultsByFeature,
                                 response.ResultsByFeature);

            response.NonStorableMessages.AddRange(result.NonStorableMessages);

            if (result.TargetFeaturesToUpdate != null)
            {
                foreach (var keyValuePair in result.TargetFeaturesToUpdate)
                {
                    IFeature  feature     = keyValuePair.Key;
                    IGeometry newGeometry = keyValuePair.Value;

                    GdbObjectMsg targetFeatureMsg =
                        ProtobufGdbUtils.ToGdbObjectMsg(
                            feature, newGeometry, feature.Class.ObjectClassID);

                    response.TargetFeaturesToUpdate.Add(targetFeatureMsg);
                }
            }

            response.ResultHasMultiparts = result.ResultHasMultiparts;

            return(response);
        }
Exemplo n.º 11
0
        public void CanCreateGdbRowFromRealData()
        {
            IWorkspace ws = TestUtils.OpenUserWorkspaceOracle();

            const string tlmStrasse = "TOPGIS_TLM.TLM_STRASSE";

            IFeatureClass realFeatureClass = DatasetUtils.OpenFeatureClass(ws, tlmStrasse);

            var objectClassMsg = ProtobufGdbUtils.ToObjectClassMsg(realFeatureClass, true);

            GdbTableContainer gdbTableContainer =
                ProtobufConversionUtils.CreateGdbTableContainer(
                    new[] { objectClassMsg }, null, out GdbWorkspace _);

            var virtualFeatureClass = (IFeatureClass)gdbTableContainer.OpenTable(tlmStrasse);

            Assert.AreEqual(realFeatureClass.ObjectClassID, virtualFeatureClass.ObjectClassID);
            Assert.AreEqual(DatasetUtils.GetName(realFeatureClass),
                            DatasetUtils.GetName(virtualFeatureClass));
            Assert.AreEqual(realFeatureClass.AliasName, virtualFeatureClass.AliasName);
            Assert.AreEqual(realFeatureClass.ShapeFieldName, virtualFeatureClass.ShapeFieldName);
            Assert.AreEqual(realFeatureClass.OIDFieldName, virtualFeatureClass.OIDFieldName);
            Assert.AreEqual(realFeatureClass.FeatureClassID, virtualFeatureClass.FeatureClassID);
            Assert.AreEqual(realFeatureClass.FeatureType, virtualFeatureClass.FeatureType);
            Assert.AreEqual(realFeatureClass.HasOID, virtualFeatureClass.HasOID);
            Assert.AreEqual(realFeatureClass.ShapeType, virtualFeatureClass.ShapeType);
            Assert.AreEqual(realFeatureClass.ShapeFieldName, virtualFeatureClass.ShapeFieldName);

            Assert.IsTrue(SpatialReferenceUtils.AreEqual(
                              DatasetUtils.GetSpatialReference(realFeatureClass),
                              DatasetUtils.GetSpatialReference(virtualFeatureClass), true, true));

            Assert.AreEqual(realFeatureClass.Fields.FieldCount,
                            virtualFeatureClass.Fields.FieldCount);

            int featureCount = 0;

            foreach (var feature in GdbQueryUtils.GetFeatures(realFeatureClass, true))
            {
                // TODO: Move all this to separate project referenced by both client and server
                GdbObjectMsg gdbObjectMsg =
                    ProtobufGdbUtils.ToGdbObjectMsg(feature, false, true);

                GdbRow gdbRow =
                    ProtobufConversionUtils.FromGdbObjectMsg(
                        gdbObjectMsg, (ITable)realFeatureClass);

                for (int i = 0; i < feature.Fields.FieldCount; i++)
                {
                    object expected = feature.get_Value(i);
                    object actual   = gdbRow.get_Value(i);

                    if (expected is IGeometry shape)
                    {
                        Assert.IsTrue(
                            GeometryUtils.AreEqual(shape, (IGeometry)actual));
                    }
                    else
                    {
                        Assert.AreEqual(expected, actual);
                    }
                }

                featureCount++;

                if (featureCount > 250)
                {
                    return;
                }
            }
        }
Exemplo n.º 12
0
        private static IList <ResultObjectMsg> GetResultFeatureMessages(
            [CanBeNull] ICollection <KeyValuePair <IFeature, IList <IFeature> > > insertsByOriginal,
            [CanBeNull] IEnumerable <IFeature> allResultFeatures,
            [CanBeNull] Func <IFeature, IEnumerable <string> > notificationsForFeature = null,
            [CanBeNull] Func <IFeature, bool> warningForFeature = null)
        {
            IList <ResultObjectMsg> ResultObjectMsgs = new List <ResultObjectMsg>();

            HashSet <IFeature> allInserts = new HashSet <IFeature>();

            if (insertsByOriginal != null)
            {
                foreach (KeyValuePair <IFeature, IList <IFeature> > kvp in insertsByOriginal)
                {
                    IList <IFeature> inserts  = kvp.Value;
                    IFeature         original = kvp.Key;

                    var originalRef = new GdbObjRefMsg
                    {
                        ClassHandle = original.Class.ObjectClassID,
                        ObjectId    = original.OID
                    };

                    foreach (IFeature insert in inserts)
                    {
                        allInserts.Add(insert);

                        var insertMsg =
                            new InsertedObjectMsg
                        {
                            InsertedObject    = ProtobufGdbUtils.ToGdbObjectMsg(insert),
                            OriginalReference = originalRef
                        };

                        var featureMsg = new ResultObjectMsg
                        {
                            Insert = insertMsg
                        };

                        AddNotification(insert, featureMsg, notificationsForFeature,
                                        warningForFeature);

                        ResultObjectMsgs.Add(featureMsg);
                    }
                }
            }

            if (allResultFeatures != null)
            {
                foreach (IFeature resultFeature in allResultFeatures)
                {
                    if (allInserts.Contains(resultFeature))
                    {
                        continue;
                    }

                    ResultObjectMsg updateMsg =
                        new ResultObjectMsg
                    {
                        Update = ProtobufGdbUtils.ToGdbObjectMsg(resultFeature)
                    };

                    AddNotification(resultFeature, updateMsg, notificationsForFeature,
                                    warningForFeature);

                    ResultObjectMsgs.Add(updateMsg);
                }
            }

            return(ResultObjectMsgs);
        }