private static GdbObjectReference GetOriginalGdbObjectReference( [NotNull] ResultObjectMsg resultObjectMsg) { Assert.ArgumentNotNull(nameof(resultObjectMsg)); // TODO: long int! int classHandle, objectId; if (resultObjectMsg.FeatureCase == ResultObjectMsg.FeatureOneofCase.Insert) { InsertedObjectMsg insert = Assert.NotNull(resultObjectMsg.Insert); GdbObjRefMsg originalObjRefMsg = insert.OriginalReference; classHandle = originalObjRefMsg.ClassHandle; objectId = originalObjRefMsg.ObjectId; } else { GdbObjectMsg updateMsg = Assert.NotNull(resultObjectMsg.Update); classHandle = updateMsg.ClassHandle; objectId = updateMsg.ObjectId; } return(new GdbObjectReference(classHandle, objectId)); }
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); }
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); } }
public static GdbFeature FromGdbFeatureMsg( [NotNull] GdbObjectMsg gdbObjectMsg, [NotNull] GdbTableContainer tableContainer) { var featureClass = (IFeatureClass)tableContainer.GetByClassId(gdbObjectMsg.ClassHandle); GdbFeature result = CreateGdbFeature(gdbObjectMsg, featureClass); return(result); }
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); }
private static GdbFeature CreateGdbFeature(GdbObjectMsg gdbObjectMsg, IFeatureClass featureClass) { ISpatialReference classSpatialRef = DatasetUtils.GetSpatialReference(featureClass); IGeometry shape = ProtobufGeometryUtils.FromShapeMsg(gdbObjectMsg.Shape, classSpatialRef); var result = new GdbFeature(gdbObjectMsg.ObjectId, featureClass) { Shape = shape }; return(result); }
public static GdbObjectMsg ToGdbObjectMsg([NotNull] Feature feature, [NotNull] Geometry geometry, bool useSpatialRefWkId) { var result = new GdbObjectMsg(); FeatureClass featureClass = feature.GetTable(); // Or use handle? result.ClassHandle = (int)featureClass.GetID(); result.ObjectId = (int)feature.GetObjectID(); result.Shape = ToShapeMsg(geometry, useSpatialRefWkId); return(result); }
public static GdbObjectMsg ToGdbObjectMsg( [NotNull] IObject featureOrObject, [CanBeNull] IGeometry geometry, int objectClassHandle, SpatialReferenceMsg.FormatOneofCase spatialRefFormat = SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkid) { var result = new GdbObjectMsg(); result.ClassHandle = objectClassHandle; result.ObjectId = featureOrObject.OID; result.Shape = ProtobufGeometryUtils.ToShapeMsg(geometry, ShapeMsg.FormatOneofCase.EsriShape, spatialRefFormat); return(result); }
public static GdbRow FromGdbObjectMsg( [NotNull] GdbObjectMsg gdbObjectMsg, [NotNull] ITable table) { GdbRow result; if (table is IFeatureClass featureClass) { result = CreateGdbFeature(gdbObjectMsg, featureClass); } else { result = new GdbRow(gdbObjectMsg.ObjectId, (IObjectClass)table); } ReadMsgValues(gdbObjectMsg, result, table); return(result); }
public static List <ResultFeature> ApplyReshapeCurves( [NotNull] ChangeAlongGrpc.ChangeAlongGrpcClient rpcClient, [NotNull] IList <Feature> sourceFeatures, [NotNull] IList <Feature> targetFeatures, [NotNull] IList <CutSubcurve> selectedSubcurves, CancellationToken cancellationToken, out ChangeAlongCurves newChangeAlongCurves) { Dictionary <GdbObjectReference, Feature> featuresByObjRef = CreateFeatureDictionary(sourceFeatures, targetFeatures); ApplyReshapeLinesRequest request = CreateApplyReshapeCurvesRequest(sourceFeatures, targetFeatures, selectedSubcurves); ApplyReshapeLinesResponse response = rpcClient.ApplyReshapeLines(request, null, null, cancellationToken); List <ResultObjectMsg> responseResultFeatures = response.ResultFeatures.ToList(); var resultFeatures = new List <ResultFeature>(); foreach (ResultObjectMsg resultObjectMsg in responseResultFeatures) { GdbObjectMsg updateMsg = Assert.NotNull(resultObjectMsg.Update); var updateObjRef = new GdbObjectReference(updateMsg.ClassHandle, updateMsg.ObjectId); Feature originalFeature = featuresByObjRef[updateObjRef]; resultFeatures.Add(new ResultFeature(originalFeature, resultObjectMsg)); } newChangeAlongCurves = PopulateReshapeAlongCurves( sourceFeatures, targetFeatures, response.NewReshapeLines, (ReshapeAlongCurveUsability)response.ReshapeLinesUsability); return(resultFeatures); }
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); }
public void CanReshapeAlongFilteredLinesByNoTargetOverlap() { GetOverlappingPolygons(out GdbFeature sourceFeature, out GdbFeature targetFeature); CalculateReshapeLinesRequest calculationRequest = CreateCalculateReshapeLinesRequest(sourceFeature, targetFeature); // // Filter by 'no target overlaps': // calculationRequest.FilterOptions = new ReshapeLineFilterOptionsMsg(); calculationRequest.FilterOptions.ExcludeResultingInOverlaps = true; CalculateReshapeLinesResponse calculateResponse = ChangeAlongServiceUtils.CalculateReshapeLines(calculationRequest, null); Assert.AreEqual(ReshapeAlongCurveUsability.CanReshape, (ReshapeAlongCurveUsability)calculateResponse.ReshapeLinesUsability); // 1 inside-source line and 1 (reshapable, but filtered) outside-source line. AssertReshapeLineCount(calculateResponse.ReshapeLines, 2, 2, 1); int insideLineIndex = GetInsideReshapeLineIndex(calculateResponse.ReshapeLines, sourceFeature.Shape); IPolyline insideLine = (IPolyline)ProtobufGeometryUtils.FromShapeMsg( calculateResponse.ReshapeLines[insideLineIndex].Path); Assert.NotNull(insideLine); Assert.AreEqual(1000, insideLine.Length); // // Reshape the default-side: ApplyReshapeLinesRequest applyRequest = new ApplyReshapeLinesRequest(); applyRequest.ReshapeLines.Add(calculateResponse.ReshapeLines[insideLineIndex]); applyRequest.CalculationRequest = calculationRequest; applyRequest.InsertVerticesInTarget = false; applyRequest.UseNonDefaultReshapeSide = false; ApplyReshapeLinesResponse applyResponse = ChangeAlongServiceUtils.ApplyReshapeLines(applyRequest, null); Assert.AreEqual(1, applyResponse.ResultFeatures.Count); GdbObjectMsg updatedFeatureMsg = applyResponse.ResultFeatures[0].Update; IGeometry updatedGeometry = ProtobufGeometryUtils.FromShapeMsg(updatedFeatureMsg.Shape); Assert.IsNotNull(updatedGeometry); Assert.AreEqual(1000 * 1000 * 3 / 4, ((IArea)updatedGeometry).Area); // Check the new reshape line - there should be 1 reshapable, but filtered line AssertReshapeLineCount(applyResponse.NewReshapeLines, 1, 1, 1); // Technically the curve could be used to reshape (filtered out is not evaluated for usability) Assert.AreEqual(ReshapeAlongCurveUsability.CanReshape, (ReshapeAlongCurveUsability)applyResponse.ReshapeLinesUsability); // Reshape the non-default side. This should probably not be possible but as it is currently // just labelled a reshape line filter, it can be justified to reshape anyway... applyRequest.UseNonDefaultReshapeSide = true; applyResponse = ChangeAlongServiceUtils.ApplyReshapeLines(applyRequest, null); Assert.AreEqual(1, applyResponse.ResultFeatures.Count); updatedFeatureMsg = applyResponse.ResultFeatures[0].Update; updatedGeometry = ProtobufGeometryUtils.FromShapeMsg(updatedFeatureMsg.Shape); Assert.IsNotNull(updatedGeometry); Assert.AreEqual(1000 * 1000 * 1 / 4, ((IArea)updatedGeometry).Area); // Check the new reshape line - there should be 1 reshapable, but filtered line AssertReshapeLineCount(applyResponse.NewReshapeLines, 1, 1, 1); // Technically the curve could be used to reshape (filtered out is not evaluated for usability) Assert.AreEqual(ReshapeAlongCurveUsability.CanReshape, (ReshapeAlongCurveUsability)applyResponse.ReshapeLinesUsability); }
public void CanReshapeAlongFilteredLinesByExtent() { GetOverlappingPolygons(out GdbFeature sourceFeature, out GdbFeature targetFeature); CalculateReshapeLinesRequest calculationRequest = CreateCalculateReshapeLinesRequest(sourceFeature, targetFeature); IEnvelope visibleExtent = sourceFeature.Shape.Envelope; visibleExtent.Expand(10, 10, false); calculationRequest.FilterOptions = new ReshapeLineFilterOptionsMsg(); calculationRequest.FilterOptions.ClipLinesOnVisibleExtent = true; calculationRequest.FilterOptions.VisibleExtents.Add( ProtobufGeometryUtils.ToEnvelopeMsg(visibleExtent)); CalculateReshapeLinesResponse calculateResponse = ChangeAlongServiceUtils.CalculateReshapeLines(calculationRequest, null); Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape, calculateResponse.ReshapeLinesUsability); // 1 inside-line and 2 extent-intersecting dangles to the outside within the extent. AssertReshapeLineCount(calculateResponse.ReshapeLines, 3, 1); int insideLineIndex = GetInsideReshapeLineIndex(calculateResponse.ReshapeLines, sourceFeature.Shape); IPolyline insideLine = (IPolyline)ProtobufGeometryUtils.FromShapeMsg( calculateResponse.ReshapeLines[insideLineIndex].Path); Assert.NotNull(insideLine); Assert.AreEqual(1000, insideLine.Length); // // Reshape the non-default side (should be possible): // ApplyReshapeLinesRequest applyRequest = new ApplyReshapeLinesRequest(); applyRequest.ReshapeLines.Add(calculateResponse.ReshapeLines[insideLineIndex]); applyRequest.CalculationRequest = calculationRequest; applyRequest.InsertVerticesInTarget = false; applyRequest.UseNonDefaultReshapeSide = true; ApplyReshapeLinesResponse applyResponse = ChangeAlongServiceUtils.ApplyReshapeLines(applyRequest, null); Assert.AreEqual(1, applyResponse.ResultFeatures.Count); GdbObjectMsg updatedFeatureMsg = applyResponse.ResultFeatures[0].Update; GdbObjectReference resultFeatureObjRef = new GdbObjectReference( updatedFeatureMsg.ClassHandle, updatedFeatureMsg.ObjectId); Assert.AreEqual(new GdbObjectReference(sourceFeature), resultFeatureObjRef); IGeometry updatedGeometry = ProtobufGeometryUtils.FromShapeMsg(updatedFeatureMsg.Shape); Assert.IsNotNull(updatedGeometry); Assert.AreEqual(1000 * 1000 * 1 / 4, ((IArea)updatedGeometry).Area); // Check the new reshape line - there should be 2 non-reshapable dangles AssertReshapeLineCount(applyResponse.NewReshapeLines, 2, 0); Assert.AreEqual(ReshapeAlongCurveUsability.InsufficientOrAmbiguousReshapeCurves, (ReshapeAlongCurveUsability)applyResponse.ReshapeLinesUsability); }
public void CanReshapeAlongNonDefaultSide() { GetOverlappingPolygons(out GdbFeature sourceFeature, out GdbFeature targetFeature); CalculateReshapeLinesRequest calculationRequest = CreateCalculateReshapeLinesRequest(sourceFeature, targetFeature); CalculateReshapeLinesResponse calculateResponse = ChangeAlongServiceUtils.CalculateReshapeLines(calculationRequest, null); Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape, calculateResponse.ReshapeLinesUsability); AssertReshapeLineCount(calculateResponse.ReshapeLines, 2, 2); List <ShapeMsg> reshapePathMsgs = calculateResponse.ReshapeLines.Select(l => l.Path).ToList(); List <IPolyline> resultLines = ProtobufGeometryUtils.FromShapeMsgList <IPolyline>(reshapePathMsgs); int insideLineIndex = resultLines .Select((reshapePath, index) => (reshapePath, index)) .First(rl => GeometryUtils.InteriorIntersects( rl.reshapePath, sourceFeature.Shape)).index; var insideLines = resultLines.Where(rl => GeometryUtils.InteriorIntersects(rl, sourceFeature.Shape)) .ToList(); Assert.AreEqual(1, insideLines.Count); Assert.AreEqual(1000, (insideLines[0]).Length); // // Reshape the default side: // ApplyReshapeLinesRequest applyRequest = new ApplyReshapeLinesRequest(); applyRequest.ReshapeLines.Add(calculateResponse.ReshapeLines[insideLineIndex]); applyRequest.CalculationRequest = calculationRequest; applyRequest.InsertVerticesInTarget = false; applyRequest.UseNonDefaultReshapeSide = false; ApplyReshapeLinesResponse applyResponse = ChangeAlongServiceUtils.ApplyReshapeLines(applyRequest, null); Assert.AreEqual(1, applyResponse.ResultFeatures.Count); GdbObjectMsg updatedFeatureMsg = applyResponse.ResultFeatures[0].Update; GdbObjectReference resultFeatureObjRef = new GdbObjectReference( updatedFeatureMsg.ClassHandle, updatedFeatureMsg.ObjectId); Assert.AreEqual(new GdbObjectReference(sourceFeature), resultFeatureObjRef); IGeometry updatedGeometry = ProtobufGeometryUtils.FromShapeMsg(updatedFeatureMsg.Shape); Assert.IsNotNull(updatedGeometry); Assert.AreEqual(1000 * 1000 * 3 / 4, ((IArea)updatedGeometry).Area); // Check the new reshape line: AssertReshapeLineCount(applyResponse.NewReshapeLines, 1, 1); Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape, applyResponse.ReshapeLinesUsability); // // Reshape the non-default side: // applyRequest.UseNonDefaultReshapeSide = true; applyResponse = ChangeAlongServiceUtils.ApplyReshapeLines(applyRequest, null); Assert.AreEqual(1, applyResponse.ResultFeatures.Count); updatedFeatureMsg = applyResponse.ResultFeatures[0].Update; resultFeatureObjRef = new GdbObjectReference( updatedFeatureMsg.ClassHandle, updatedFeatureMsg.ObjectId); Assert.AreEqual(new GdbObjectReference(sourceFeature), resultFeatureObjRef); updatedGeometry = ProtobufGeometryUtils.FromShapeMsg(updatedFeatureMsg.Shape); Assert.IsNotNull(updatedGeometry); Assert.AreEqual((double)1000 * 1000 * 1 / 4, ((IArea)updatedGeometry).Area); }
public void CanReshapeAlongBufferedTarget() { GetOverlappingPolygons(out GdbFeature sourceFeature, out GdbFeature targetFeature); CalculateReshapeLinesRequest calculationRequest = CreateCalculateReshapeLinesRequest(sourceFeature, targetFeature); double minSegmentLength = 2; calculationRequest.TargetBufferOptions = new TargetBufferOptionsMsg(); calculationRequest.TargetBufferOptions.BufferDistance = 10; calculationRequest.TargetBufferOptions.BufferMinimumSegmentLength = minSegmentLength; CalculateReshapeLinesResponse calculateResponse = ChangeAlongServiceUtils.CalculateReshapeLines(calculationRequest, null); Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape, calculateResponse.ReshapeLinesUsability); AssertReshapeLineCount(calculateResponse.ReshapeLines, 4, 4); List <ShapeMsg> reshapePathMsgs = calculateResponse.ReshapeLines.Select(l => l.Path).ToList(); List <IPolyline> resultLines = ProtobufGeometryUtils.FromShapeMsgList <IPolyline>(reshapePathMsgs); int insideLineIndex = resultLines .Select((reshapePath, index) => (reshapePath, index)) .OrderBy(rl => rl.reshapePath.Length) .First(rl => GeometryUtils.InteriorIntersects( rl.reshapePath, sourceFeature.Shape)).index; var insideLines = resultLines.Where(rl => GeometryUtils.InteriorIntersects(rl, sourceFeature.Shape)) .ToList(); Assert.AreEqual(2, insideLines.Count); foreach (IPolyline resultLine in resultLines) { Assert.AreNotEqual(1000, resultLine.Length); Assert.AreEqual( 0, GeometryUtils.GetShortSegments(resultLine, minSegmentLength).Count); } // // Reshape the default side: // ApplyReshapeLinesRequest applyRequest = new ApplyReshapeLinesRequest(); applyRequest.ReshapeLines.Add(calculateResponse.ReshapeLines[insideLineIndex]); applyRequest.CalculationRequest = calculationRequest; applyRequest.InsertVerticesInTarget = false; applyRequest.UseNonDefaultReshapeSide = false; ApplyReshapeLinesResponse applyResponse = ChangeAlongServiceUtils.ApplyReshapeLines(applyRequest, null); Assert.AreEqual(1, applyResponse.ResultFeatures.Count); GdbObjectMsg updatedFeatureMsg = applyResponse.ResultFeatures[0].Update; GdbObjectReference resultFeatureObjRef = new GdbObjectReference( updatedFeatureMsg.ClassHandle, updatedFeatureMsg.ObjectId); Assert.AreEqual(new GdbObjectReference(sourceFeature), resultFeatureObjRef); IGeometry updatedGeometry = ProtobufGeometryUtils.FromShapeMsg(updatedFeatureMsg.Shape); // The shortest reshape line results in a greater remaining area: Assert.IsNotNull(updatedGeometry); Assert.Greater(((IArea)updatedGeometry).Area, 1000 * 1000 * 3 / (double)4); // Check the new reshape line: AssertReshapeLineCount(applyResponse.NewReshapeLines, 3, 3); Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape, applyResponse.ReshapeLinesUsability); }
public void CanReshapeAlongMinimalTolerance() { GetOverlappingPolygons(out GdbFeature sourceFeature, out GdbFeature targetFeature); // Insert an extra point: IPoint targetAlmostIntersectPoint = GeometryFactory.CreatePoint( 2601000.001, 1200500.0, sourceFeature.Shape.SpatialReference); bool pointInserted = ReshapeUtils.EnsurePointsExistInTarget( targetFeature.Shape, new[] { targetAlmostIntersectPoint }, 0.001); Assert.IsTrue(pointInserted); Assert.AreEqual(6, GeometryUtils.GetPointCount(targetFeature.Shape)); CalculateReshapeLinesRequest calculationRequest = CreateCalculateReshapeLinesRequest(sourceFeature, targetFeature); CalculateReshapeLinesResponse calculateResponse = ChangeAlongServiceUtils.CalculateReshapeLines(calculationRequest, null); Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape, calculateResponse.ReshapeLinesUsability); AssertReshapeLineCount(calculateResponse.ReshapeLines, 2, 2); int insideLineIndex = GetInsideReshapeLineIndex(calculateResponse.ReshapeLines, sourceFeature.Shape); IPolyline insideLine = (IPolyline)ProtobufGeometryUtils.FromShapeMsg( calculateResponse.ReshapeLines[insideLineIndex].Path); Assert.NotNull(insideLine); Assert.AreNotEqual(1000.0, (insideLine).Length); // NOTE: If IntersectionUtils.UseCustomIntersect = true the from point is exactly on the inserted point // Otherwise it's somewhere between - so we cannot do the exact comparison Assert.AreNotEqual(insideLine.FromPoint.X, 2601000.0); Assert.AreNotEqual(insideLine.ToPoint.X, 2601000.0); // // Reshape the default side: ApplyReshapeLinesRequest applyRequest = new ApplyReshapeLinesRequest(); applyRequest.ReshapeLines.Add(calculateResponse.ReshapeLines[insideLineIndex]); applyRequest.CalculationRequest = calculationRequest; applyRequest.InsertVerticesInTarget = false; applyRequest.UseNonDefaultReshapeSide = false; ApplyReshapeLinesResponse applyResponse = ChangeAlongServiceUtils.ApplyReshapeLines(applyRequest, null); Assert.AreEqual(1, applyResponse.ResultFeatures.Count); GdbObjectMsg updatedFeatureMsg = applyResponse.ResultFeatures[0].Update; IGeometry updatedGeometry = ProtobufGeometryUtils.FromShapeMsg(updatedFeatureMsg.Shape); Assert.IsNotNull(updatedGeometry); Assert.Greater(((IArea)updatedGeometry).Area, 1000.0 * 1000.0 * 3 / 4); // Check the new reshape line: AssertReshapeLineCount(applyResponse.NewReshapeLines, 1, 1); Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape, applyResponse.ReshapeLinesUsability); // // // The same using the minimum tolerance: // calculationRequest.Tolerance = 0; calculateResponse = ChangeAlongServiceUtils.CalculateReshapeLines(calculationRequest, null); Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape, calculateResponse.ReshapeLinesUsability); AssertReshapeLineCount(calculateResponse.ReshapeLines, 2, 2); insideLineIndex = GetInsideReshapeLineIndex(calculateResponse.ReshapeLines, sourceFeature.Shape); insideLine = (IPolyline)ProtobufGeometryUtils.FromShapeMsg( calculateResponse.ReshapeLines[insideLineIndex].Path); Assert.NotNull(insideLine); Assert.AreEqual(1000.0, insideLine.Length, 0.000000001); // NOTE: If IntersectionUtils.UseCustomIntersect = true the from point is exactly on the inserted point // Otherwise it's somewhere between - so we cannot do the exact comparison Assert.AreEqual(2601000.0, insideLine.FromPoint.X); Assert.AreEqual(1200500.0, insideLine.FromPoint.Y); // // Apply with minimum tolerance: applyRequest = new ApplyReshapeLinesRequest(); applyRequest.ReshapeLines.Add(calculateResponse.ReshapeLines[insideLineIndex]); applyRequest.CalculationRequest = calculationRequest; applyRequest.InsertVerticesInTarget = false; applyRequest.UseNonDefaultReshapeSide = false; applyResponse = ChangeAlongServiceUtils.ApplyReshapeLines(applyRequest, null); Assert.AreEqual(1, applyResponse.ResultFeatures.Count); updatedFeatureMsg = applyResponse.ResultFeatures[0].Update; updatedGeometry = ProtobufGeometryUtils.FromShapeMsg(updatedFeatureMsg.Shape); Assert.IsNotNull(updatedGeometry); Assert.AreEqual(1000 * 1000 * 3 / 4, ((IArea)updatedGeometry).Area); // Check the new remaining reshape line (outside) AssertReshapeLineCount(applyResponse.NewReshapeLines, 1, 1); Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape, applyResponse.ReshapeLinesUsability); IPolyline outsideLine = (IPolyline)ProtobufGeometryUtils.FromShapeMsg( applyResponse.NewReshapeLines[0].Path); Assert.NotNull(outsideLine); Assert.AreEqual(3000.0, outsideLine.Length, 0.000000001); // NOTE: If IntersectionUtils.UseCustomIntersect = true the from point is exactly on the inserted point // Otherwise it's somewhere between - so we cannot do the exact comparison Assert.AreEqual(2601000.0, outsideLine.ToPoint.X); Assert.AreEqual(1200500.0, outsideLine.ToPoint.Y); }
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)); }
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); }
private static void ReadMsgValues(GdbObjectMsg gdbObjectMsg, GdbRow intoResult, ITable table) { if (gdbObjectMsg.Values.Count == 0) { return; } Assert.AreEqual(table.Fields.FieldCount, gdbObjectMsg.Values.Count, "GdbObject message values do not correspond to table schema"); for (var index = 0; index < gdbObjectMsg.Values.Count; index++) { AttributeValue attributeValue = gdbObjectMsg.Values[index]; switch (attributeValue.ValueCase) { case AttributeValue.ValueOneofCase.None: break; case AttributeValue.ValueOneofCase.DbNull: intoResult.set_Value(index, DBNull.Value); break; case AttributeValue.ValueOneofCase.ShortIntValue: intoResult.set_Value(index, attributeValue.ShortIntValue); break; case AttributeValue.ValueOneofCase.LongIntValue: intoResult.set_Value(index, attributeValue.LongIntValue); break; case AttributeValue.ValueOneofCase.FloatValue: intoResult.set_Value(index, attributeValue.FloatValue); break; case AttributeValue.ValueOneofCase.DoubleValue: intoResult.set_Value(index, attributeValue.DoubleValue); break; case AttributeValue.ValueOneofCase.StringValue: intoResult.set_Value(index, attributeValue.StringValue); break; case AttributeValue.ValueOneofCase.DateTimeTicksValue: intoResult.set_Value( index, new DateTime(attributeValue.DateTimeTicksValue)); break; case AttributeValue.ValueOneofCase.UuidValue: var guid = new Guid(attributeValue.UuidValue.Value.ToByteArray()); IUID uid = UIDUtils.CreateUID(guid); intoResult.set_Value(index, uid); break; case AttributeValue.ValueOneofCase.BlobValue: intoResult.set_Value(index, attributeValue.BlobValue); break; default: if (table.Fields.Field[index].Type == esriFieldType.esriFieldTypeGeometry) { // Leave empty, it is already assigned to the Shape property break; } throw new ArgumentOutOfRangeException(); } } }
public static GdbObjectMsg ToGdbObjectMsg([NotNull] IObject featureOrObject, bool includeSpatialRef = false, bool includeFieldValues = false) { var result = new GdbObjectMsg(); result.ClassHandle = featureOrObject.Class.ObjectClassID; result.ObjectId = featureOrObject.OID; if (featureOrObject is IFeature feature) { IGeometry featureShape = GdbObjectUtils.GetFeatureShape(feature); result.Shape = ProtobufGeometryUtils.ToShapeMsg( featureShape, ShapeMsg.FormatOneofCase.EsriShape, includeSpatialRef ? SpatialReferenceMsg.FormatOneofCase.SpatialReferenceEsriXml : SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkid); } if (includeFieldValues) { for (int i = 0; i < featureOrObject.Fields.FieldCount; i++) { IField field = featureOrObject.Fields.Field[i]; object valueObject = featureOrObject.Value[i]; var attributeValue = new AttributeValue(); result.Values.Add(attributeValue); if (valueObject == DBNull.Value || valueObject == null) { attributeValue.DbNull = true; } else { switch (field.Type) { case esriFieldType.esriFieldTypeSmallInteger: attributeValue.ShortIntValue = (int)valueObject; break; case esriFieldType.esriFieldTypeInteger: attributeValue.LongIntValue = (int)valueObject; break; case esriFieldType.esriFieldTypeSingle: attributeValue.ShortIntValue = (int)valueObject; break; case esriFieldType.esriFieldTypeDouble: attributeValue.DoubleValue = (double)valueObject; break; case esriFieldType.esriFieldTypeString: attributeValue.StringValue = (string)valueObject; break; case esriFieldType.esriFieldTypeDate: attributeValue.DateTimeTicksValue = ((DateTime)valueObject).Ticks; break; case esriFieldType.esriFieldTypeOID: attributeValue.ShortIntValue = (int)valueObject; break; case esriFieldType.esriFieldTypeGeometry: // Leave empty, it is sent through Shape property break; case esriFieldType.esriFieldTypeBlob: // TODO: Test and make this work attributeValue.BlobValue = ByteString.CopyFrom((byte[])valueObject); break; case esriFieldType.esriFieldTypeRaster: // Not supported, ignore break; case esriFieldType.esriFieldTypeGUID: byte[] asBytes = new Guid((string)valueObject).ToByteArray(); attributeValue.UuidValue = new UUID { Value = ByteString.CopyFrom(asBytes) }; break; case esriFieldType.esriFieldTypeGlobalID: asBytes = new Guid((string)valueObject).ToByteArray(); attributeValue.UuidValue = new UUID { Value = ByteString.CopyFrom(asBytes) }; break; case esriFieldType.esriFieldTypeXML: // Not supported, ignore break; default: throw new ArgumentOutOfRangeException(); } } } } return(result); }
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); }
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; } } }