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); }
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 void CanCutAlongInsertTargetVertices() { GetOverlappingPolygons(out GdbFeature sourceFeature, out GdbFeature targetFeature); CalculateCutLinesRequest calculationRequest = CreateCalculateCutLinesRequest(sourceFeature, targetFeature); CalculateCutLinesResponse calculateResponse = ChangeAlongServiceUtils.CalculateCutLines(calculationRequest, null); Assert.AreEqual(ReshapeAlongCurveUsability.CanReshape, (ReshapeAlongCurveUsability)calculateResponse.ReshapeLinesUsability); AssertReshapeLineCount(calculateResponse.CutLines, 1, 1); IPolyline reshapeLine = (IPolyline)ProtobufGeometryUtils.FromShapeMsg(calculateResponse.CutLines[0].Path); Assert.NotNull(reshapeLine); Assert.AreEqual(1000, (reshapeLine).Length); // // Cutting // var applyRequest = new ApplyCutLinesRequest(); applyRequest.CutLines.Add(calculateResponse.CutLines[0]); applyRequest.CalculationRequest = calculationRequest; applyRequest.InsertVerticesInTarget = true; ApplyCutLinesResponse applyResponse = ChangeAlongServiceUtils.ApplyCutLines(applyRequest, null); Assert.AreEqual(3, applyResponse.ResultFeatures.Count); List <IGeometry> cutSourceGeometries = applyResponse.ResultFeatures .Where(f => GetObjectId(f) != targetFeature.OID) .Select(GetShape) .ToList(); Assert.AreEqual(1000 * 1000, cutSourceGeometries.Sum(g => ((IArea)g).Area)); IGeometry updatedTargetGeometry = applyResponse.ResultFeatures .Where(f => f.Update?.ObjectId == targetFeature.OID) .Select(GetShape) .Single(); Assert.AreEqual(GeometryUtils.GetPointCount(targetFeature.Shape) + 2, GeometryUtils.GetPointCount(updatedTargetGeometry)); // Check the new reshape line: AssertReshapeLineCount(applyResponse.NewCutLines, 0, 0); Assert.AreEqual(ReshapeAlongCurveUsability.NoReshapeCurves, (ReshapeAlongCurveUsability)applyResponse.CutLinesUsability); }
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)); }
private static IList <IPoint> PointsFromShapeMsg([CanBeNull] ShapeMsg shapeMsg) { var geometry = ProtobufGeometryUtils.FromShapeMsg(shapeMsg); if (geometry == null) { return(null); } return(GeometryUtils.GetPoints(geometry).ToList()); }
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); }
private static IPath GetPath([CanBeNull] ShapeMsg polylineMsg) { IPolyline polyline = (IPolyline)ProtobufGeometryUtils.FromShapeMsg(polylineMsg); if (polyline == null || polyline.IsEmpty) { return(null); } IPath result = (IPath)((IGeometryCollection)polyline).Geometry[0]; return(result); }
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 ISegment GetSegment([CanBeNull] ShapeMsg segmentMsg) { IPolyline polyline = (IPolyline)ProtobufGeometryUtils.FromShapeMsg(segmentMsg); if (polyline == null || polyline.IsEmpty) { return(null); } ISegment result = ((ISegmentCollection)polyline).Segment[0]; return(result); }
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); }
private static IGeometry GetShape(ResultObjectMsg resultObjectMsg) { ShapeMsg shapeMsg; switch (resultObjectMsg.FeatureCase) { case ResultObjectMsg.FeatureOneofCase.Update: shapeMsg = resultObjectMsg.Update.Shape; break; case ResultObjectMsg.FeatureOneofCase.Insert: shapeMsg = resultObjectMsg.Insert.InsertedObject.Shape; break; default: return(null); } return(shapeMsg == null ? null : ProtobufGeometryUtils.FromShapeMsg(shapeMsg)); }
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 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); }
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); }
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 CanCutAlongUsingZSources() { GetOverlappingPolygons(out GdbFeature sourceFeature, out GdbFeature targetFeature); GeometryUtils.MakeZAware(sourceFeature.Shape); GeometryUtils.MakeZAware(targetFeature.Shape); var normal = new Vector(new[] { 0.5, 0.5, 2 }); Pnt3D planePoint = new Pnt3D(2600000, 1200000, 600); Plane3D sourcePlane = new Plane3D(normal, planePoint); ChangeAlongZUtils.AssignZ((IPointCollection)sourceFeature.Shape, sourcePlane); GeometryUtils.ApplyConstantZ(targetFeature.Shape, 500); CalculateCutLinesRequest calculationRequest = CreateCalculateCutLinesRequest(sourceFeature, targetFeature); CalculateCutLinesResponse calculateResponse = ChangeAlongServiceUtils.CalculateCutLines(calculationRequest, null); Assert.AreEqual(ReshapeAlongCurveUsability.CanReshape, (ReshapeAlongCurveUsability)calculateResponse.ReshapeLinesUsability); AssertReshapeLineCount(calculateResponse.CutLines, 1, 1); IPolyline reshapeLine = (IPolyline)ProtobufGeometryUtils.FromShapeMsg(calculateResponse.CutLines[0].Path); Assert.NotNull(reshapeLine); Assert.AreEqual(1000, (reshapeLine).Length); Linestring cutLinestring = GeometryConversionUtils.GetLinestring(GeometryUtils.GetPaths(reshapeLine).Single()); Pnt3D midPoint = (Pnt3D)cutLinestring.GetPointAlong(0.5, true); List <Pnt3D> points = GeometryConversionUtils.GetPntList(reshapeLine); Assert.IsTrue(points.All(p => MathUtils.AreEqual(p.Z, 500.0))); // // Cutting - TargetZ // var applyRequest = new ApplyCutLinesRequest(); applyRequest.CutLines.Add(calculateResponse.CutLines[0]); applyRequest.CalculationRequest = calculationRequest; applyRequest.InsertVerticesInTarget = false; applyRequest.ChangedVerticesZSource = (int)ChangeAlongZSource.Target; ApplyCutLinesResponse applyResponse = ChangeAlongServiceUtils.ApplyCutLines(applyRequest, null); Assert.AreEqual(2, applyResponse.ResultFeatures.Count); List <IGeometry> cutGeometries = applyResponse.ResultFeatures.Select(GetShape).ToList(); Assert.AreEqual(1000 * 1000, cutGeometries.Sum(g => ((IArea)g).Area)); List <MultiPolycurve> multiPolycurves = cutGeometries .Select(g => GeometryConversionUtils.CreateMultiPolycurve((IPolycurve)g)) .ToList(); foreach (MultiPolycurve multiPolycurve in multiPolycurves) { Line3D segment = multiPolycurve.FindSegments(midPoint, 0.001).First().Value; Assert.AreEqual(500, segment.StartPoint.Z); Assert.AreEqual(500, segment.EndPoint.Z); } // // Cutting - Interpolate // applyRequest = new ApplyCutLinesRequest(); applyRequest.CutLines.Add(calculateResponse.CutLines[0]); applyRequest.CalculationRequest = calculationRequest; applyRequest.InsertVerticesInTarget = false; applyRequest.ChangedVerticesZSource = (int)ChangeAlongZSource.InterpolatedSource; applyResponse = ChangeAlongServiceUtils.ApplyCutLines(applyRequest, null); Assert.AreEqual(2, applyResponse.ResultFeatures.Count); cutGeometries = applyResponse.ResultFeatures.Select(GetShape).ToList(); Assert.AreEqual(1000 * 1000, cutGeometries.Sum(g => ((IArea)g).Area)); multiPolycurves = cutGeometries .Select(g => GeometryConversionUtils.CreateMultiPolycurve((IPolycurve)g)) .ToList(); foreach (MultiPolycurve multiPolycurve in multiPolycurves) { List <Line3D> segments = multiPolycurve.FindSegments(midPoint, 0.001) .Select(kvp => kvp.Value).ToList(); Assert.AreEqual(2, segments.Count); // Check if they are properly ordered and same length Assert.AreEqual(segments[0].EndPoint, segments[1].StartPoint); Assert.AreEqual(segments[0].Length2D, segments[1].Length2D); // Check if they are interpolated double average = (segments[0].StartPoint.Z + segments[1].EndPoint.Z) / 2; Assert.AreEqual(average, segments[0].EndPoint.Z); } // // Cutting - Plane // applyRequest = new ApplyCutLinesRequest(); applyRequest.CutLines.Add(calculateResponse.CutLines[0]); applyRequest.CalculationRequest = calculationRequest; applyRequest.InsertVerticesInTarget = false; applyRequest.ChangedVerticesZSource = (int)ChangeAlongZSource.SourcePlane; applyResponse = ChangeAlongServiceUtils.ApplyCutLines(applyRequest, null); Assert.AreEqual(2, applyResponse.ResultFeatures.Count); cutGeometries = applyResponse.ResultFeatures.Select(GetShape).ToList(); Assert.AreEqual(1000 * 1000, cutGeometries.Sum(g => ((IArea)g).Area)); multiPolycurves = cutGeometries .Select(g => GeometryConversionUtils.CreateMultiPolycurve((IPolycurve)g)) .ToList(); foreach (MultiPolycurve multiPolycurve in multiPolycurves) { bool?coplanar = ChangeAlongZUtils.AreCoplanar( multiPolycurve.GetPoints().ToList(), sourcePlane, 0.01, out double _, out string _); Assert.IsTrue(coplanar); } }
private static GeometryReshaperBase CreateReshaper( AdvancedReshapeRequest request, IList <IPath> reshapePaths) { GeometryReshaperBase result; bool allowOpenJaw = request.AllowOpenJawReshape; bool moveOpenJawEndJunction = request.MoveOpenJawEndJunction; IList <IFeature> featuresToReshape = GetFeaturesToReshape(request, out GdbTableContainer container); if (featuresToReshape.Count == 1) { IFeature firstFeature = featuresToReshape[0]; var singleGeometryReshaper = new GeometryReshaper(firstFeature) { AllowOpenJawReshape = allowOpenJaw }; result = singleGeometryReshaper; } else { var stickyIntersections = new StickyIntersections(featuresToReshape); foreach (SourceTargetPointPair pair in request.StickyIntersections) { stickyIntersections.SourceTargetPairs.Add( new KeyValuePair <IPoint, IPoint>( (IPoint)ProtobufGeometryUtils.FromShapeMsg( pair.SourcePoint), (IPoint)ProtobufGeometryUtils.FromShapeMsg( pair.TargetPoint))); } result = new MultipleGeometriesReshaper(featuresToReshape) { MultipleSourcesTreatIndividually = true, MultipleSourcesTreatAsUnion = request.MultipleSourcesTryUnion, MaxProlongationLengthFactor = 4, StickyIntersectionPoints = stickyIntersections }; // Conditions for closed reshape paths being removed: // - multiple source geometries, at least two of which polygons // - multiple reshape paths (or a single closed path) // ... consider checking that the ring-path is completely inside the outermost ring of the source polygon's union // or at least that several polygons are intersected by the sketch geometry if ((reshapePaths.Count > 1) || reshapePaths.All(path => path.IsClosed)) { if (ContainsMultiplePolygonFeatures(featuresToReshape)) { result.RemoveClosedReshapePathAreas = true; } } } if (moveOpenJawEndJunction) { IList <IFeature> targetCandidates = ProtobufConversionUtils.FromGdbObjectMsgList( request.PotentiallyConnectedFeatures, container); result.NetworkFeatureFinder = new LinearNetworkGdbFeatureFinder(targetCandidates); result.NetworkFeatureUpdater = new LinearNetworkNodeUpdater(result.NetworkFeatureFinder); } result.MoveLineEndJunction = moveOpenJawEndJunction; // TODO: Add to admin-options (i.e. central defaults only, no GUI) together with the threshold // _useSimplifiedReshapeSideDeterminationVertexThreshold in ReshapeInfo result.AllowSimplifiedReshapeSideDetermination = true; return(result); }
public void CanCutAlong() { GetOverlappingPolygons(out GdbFeature sourceFeature, out GdbFeature targetFeature); CalculateCutLinesRequest calculationRequest = CreateCalculateCutLinesRequest(sourceFeature, targetFeature); CalculateCutLinesResponse calculateResponse = ChangeAlongServiceUtils.CalculateCutLines(calculationRequest, null); Assert.AreEqual(ReshapeAlongCurveUsability.CanReshape, (ReshapeAlongCurveUsability)calculateResponse.ReshapeLinesUsability); AssertReshapeLineCount(calculateResponse.CutLines, 1, 1); IPolyline reshapeLine = (IPolyline)ProtobufGeometryUtils.FromShapeMsg(calculateResponse.CutLines[0].Path); Assert.NotNull(reshapeLine); Assert.AreEqual(1000, (reshapeLine).Length); // // Cutting // 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); List <IGeometry> geometries = applyResponse.ResultFeatures.Select(GetShape).ToList(); Assert.AreEqual(1000 * 1000, geometries.Sum(g => ((IArea)g).Area)); ResultObjectMsg updateResultMsg = applyResponse.ResultFeatures.First( r => r.FeatureCase == ResultObjectMsg.FeatureOneofCase.Update); GdbObjectReference updateObjRef = new GdbObjectReference(updateResultMsg.Update.ClassHandle, updateResultMsg.Update.ObjectId); Assert.AreEqual(new GdbObjectReference(sourceFeature), updateObjRef); IGeometry firstGeometry = ProtobufGeometryUtils.FromShapeMsg(updateResultMsg.Update.Shape); Assert.IsNotNull(firstGeometry); Assert.AreEqual(1000 * 1000 * 3 / 4, ((IArea)firstGeometry).Area); // 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 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 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 CanReshapeAlongInsertTargetVertices() { 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); int insideLineIndex = GetInsideReshapeLineIndex(calculateResponse.ReshapeLines, sourceFeature.Shape); IPolyline insideLine = (IPolyline)ProtobufGeometryUtils.FromShapeMsg( calculateResponse.ReshapeLines[insideLineIndex].Path); Assert.NotNull(insideLine); Assert.AreEqual(1000.0, insideLine.Length); // // Reshape the default side: // ApplyReshapeLinesRequest applyRequest = new ApplyReshapeLinesRequest(); applyRequest.ReshapeLines.Add(calculateResponse.ReshapeLines[insideLineIndex]); applyRequest.CalculationRequest = calculationRequest; applyRequest.InsertVerticesInTarget = true; applyRequest.UseNonDefaultReshapeSide = false; ApplyReshapeLinesResponse applyResponse = ChangeAlongServiceUtils.ApplyReshapeLines(applyRequest, null); Assert.AreEqual(2, applyResponse.ResultFeatures.Count); ResultObjectMsg sourceResultMsg = applyResponse.ResultFeatures.First( f => f.Update.ObjectId == sourceFeature.OID); IGeometry updatedSourceGeometry = ProtobufGeometryUtils.FromShapeMsg(sourceResultMsg.Update.Shape); Assert.IsNotNull(updatedSourceGeometry); Assert.AreEqual(1000 * 1000 * 3 / 4, ((IArea)updatedSourceGeometry).Area); ResultObjectMsg targetResultMsg = applyResponse.ResultFeatures.First( f => f.Update.ObjectId == targetFeature.OID); IGeometry updatedTargetGeometry = ProtobufGeometryUtils.FromShapeMsg(targetResultMsg.Update.Shape); Assert.AreEqual(GeometryUtils.GetPointCount(targetFeature.Shape) + 2, GeometryUtils.GetPointCount(updatedTargetGeometry)); // Check the new reshape line: AssertReshapeLineCount(applyResponse.NewReshapeLines, 1, 1); Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape, applyResponse.ReshapeLinesUsability); }
private ServiceCallStatus VerifyStandaloneXmlCore( StandaloneVerificationRequest request, IServerStreamWriter <StandaloneVerificationResponse> responseStream, ITrackCancel trackCancel) { // Machine login SetupUserNameProvider(Environment.UserName); try { VerificationParametersMsg parameters = request.Parameters; IGeometry perimeter = ProtobufGeometryUtils.FromShapeMsg(parameters.Perimeter); XmlBasedVerificationService qaService = new XmlBasedVerificationService( HtmlReportTemplatePath, QualitySpecificationTemplatePath); XmlQualitySpecificationMsg xmlSpecification = request.Specification; var dataSources = new List <DataSource>(); foreach (string replacement in xmlSpecification.DataSourceReplacements) { List <string> replacementStrings = StringUtils.SplitAndTrim(replacement, '|'); Assert.AreEqual(2, replacementStrings.Count, "Data source workspace is not of the format \"workspace_id | catalog_path\""); var dataSource = new DataSource(replacementStrings[0], replacementStrings[0]) { WorkspaceAsText = replacementStrings[1] }; dataSources.Add(dataSource); } var aoi = perimeter == null ? null : new AreaOfInterest(perimeter); try { qaService.ExecuteVerification( xmlSpecification.Xml, xmlSpecification.SelectedSpecificationName, dataSources, aoi, null, parameters.TileSize, request.OutputDirectory, IssueRepositoryType.FileGdb, true, trackCancel); } catch (ArgumentException argumentException) { _msg.Warn("Argument exception", argumentException); return(ServiceCallStatus.Failed); } } catch (Exception e) { _msg.DebugFormat("Error during processing of request {0}", request); _msg.Error($"Error verifying quality: {e.Message}", e); if (!EnvironmentUtils.GetBooleanEnvironmentVariableValue( "PROSUITE_QA_SERVER_KEEP_SERVING_ON_ERROR")) { SetUnhealthy(); } return(ServiceCallStatus.Failed); } return(trackCancel.Continue() ? ServiceCallStatus.Finished : ServiceCallStatus.Cancelled); }
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); }