public void CanValidateReshapeLine() { ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95); IPath reshapePath = GeometryFactory.CreatePath( GeometryFactory.CreatePoint(2600000.12, 1200000.12, sr), GeometryFactory.CreatePoint(2600000.121, 1200000.121, sr)); IPolyline polyline = GeometryFactory.CreatePolyline(2600000, 1200000, 2600001, 1200001); var reshapeInfo = new ReshapeInfo(polyline, reshapePath, null); // It says it's closed but it's just a bit short Assert.IsTrue(reshapePath.IsClosed); Assert.IsFalse(reshapeInfo.ValidateReshapePath()); // even with 3 points: WKSPoint middlePoint; middlePoint.X = 2600000.1205; middlePoint.Y = 1200000.1205; ((IPointCollection)reshapePath).InsertWKSPoints(1, 1, middlePoint); reshapeInfo = new ReshapeInfo(polyline, reshapePath, null); Assert.IsTrue(reshapePath.IsClosed); Assert.IsFalse(reshapeInfo.ValidateReshapePath()); }
public void CanTestEmptyGeometrySdePolyline() { IWorkspace workspace = TestUtils.OpenUserWorkspaceOracle(); //IWorkspace workspace = ProSuite.Commons.AO.Test.TestUtils.OpenSDEWorkspaceOracle(); IPolyline normalGeometry = GeometryFactory.CreatePolyline( GeometryFactory.CreatePath(new PointClass { X = 2600000, Y = 1200000, Z = 400 }, new PointClass { X = 2600000, Y = 1200100, Z = 400 }, new PointClass { X = 2600100, Y = 1200000, Z = 400 }, new PointClass { X = 2600000, Y = 1200000, Z = 400 })); GeometryUtils.MakeZAware(normalGeometry); IFeature feature = CreateEmptyGeometryFeature((IFeatureWorkspace)workspace, esriGeometryType.esriGeometryPolyline, normalGeometry); AssertOneErrorEmptyGeometry((IFeatureClass)feature.Class); }
private static IPolyline CreatePolyline(params IPoint[] vertices) { IPath path = GeometryFactory.CreatePath(vertices); IPolyline polyline = GeometryFactory.CreatePolyline(path); return(polyline); }
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 CanReplaceSegmentsWithNonZAwareReplacement() { ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95); IPolyline originalPolyline = GeometryFactory.CreatePolyline( GeometryFactory.CreatePath( GeometryFactory.CreatePoint(2600000, 1200000, 400, double.NaN, lv95), GeometryFactory.CreatePoint(2600010, 1200000, 410, double.NaN, lv95), GeometryFactory.CreatePoint(2600020, 1200000, 410, double.NaN, lv95), GeometryFactory.CreatePoint(2600030, 1200000, 420, double.NaN, lv95))); IPath replacement = GeometryFactory.CreatePath( GeometryFactory.CreatePoint(2600010, 1200000, 0, double.NaN, lv95), GeometryFactory.CreatePoint(2600015, 1200010, 500, double.NaN, lv95), GeometryFactory.CreatePoint(2600020, 1200000, 900, double.NaN, lv95)); // NOTE: The Z value of the first point of the replacement is used, however, the envelope of the resulting pathToReshape is not updated! // Hence it is crucial to insert the exact replacement end points into the geometry to reshape! IPolyline polyline = GeometryFactory.Clone(originalPolyline); var pathToReshape = (ISegmentCollection)((IGeometryCollection)polyline).Geometry[0]; GeometryUtils.MakeNonZAware(replacement); SegmentReplacementUtils.ReplaceSegments((IPath)pathToReshape, replacement, replacement.FromPoint, replacement.ToPoint); Assert.AreEqual(410, ((IPointCollection)pathToReshape).Point[1].Z); Assert.AreEqual(400, polyline.Envelope.ZMin, "Envelope is not inconsistent any more after segment replacment!"); // Now connect within a segment: IPoint firstPoint = replacement.FromPoint; firstPoint.X = 2600007; ((IPointCollection)replacement).UpdatePoint(0, firstPoint); polyline = GeometryFactory.Clone(originalPolyline); pathToReshape = (ISegmentCollection)((IGeometryCollection)polyline).Geometry[0]; GeometryUtils.MakeNonZAware(replacement); SegmentReplacementUtils.ReplaceSegments((IPath)pathToReshape, replacement, replacement.FromPoint, replacement.ToPoint); Assert.AreEqual(407, ((IPointCollection)pathToReshape).Point[1].Z); Assert.AreEqual(400, polyline.Envelope.ZMin, "Envelope is not inconsistent any more after segment replacment!"); }
public void CanCreateNonSimpleRing() { IPath path = GeometryFactory.CreatePath(GeometryFactory.CreatePoint(100, 100)); IRing ring = GeometryFactory.CreateRing(path); Assert.AreEqual(1, ((IPointCollection)ring).PointCount); ring = GeometryFactory.CreateRing(new PathClass()); Assert.IsTrue(ring.IsEmpty); }
private static IPath GetPath([NotNull] IGeometry lowLevelGeometry) { if (lowLevelGeometry.GeometryType == esriGeometryType.esriGeometryPath) { return((IPath)lowLevelGeometry); } if (lowLevelGeometry.GeometryType == esriGeometryType.esriGeometryRing) { return(GeometryFactory.CreatePath((IRing)lowLevelGeometry)); } throw new InvalidOperationException( $"Unsupported input geometry type: {lowLevelGeometry.GeometryType}"); }
public IPath GetCutOffBoundaryConnectLine(ICurve pathOnTarget, IPoint toTargetPoint) { IPath result = null; // disregard the part that does not connect to the un-reshaped part if (!GeometryUtils.Disjoint(UnreshapedBoundaryPart, GeometryUtils.GetHighLevelGeometry(pathOnTarget, true))) { IPoint lastUnreshapedVertex = null; IPoint otherPathOnTargetEnd = null; if (GeometryUtils.AreEqualInXY(pathOnTarget.FromPoint, toTargetPoint)) { otherPathOnTargetEnd = pathOnTarget.ToPoint; } else if (GeometryUtils.AreEqualInXY(pathOnTarget.ToPoint, toTargetPoint)) { otherPathOnTargetEnd = pathOnTarget.FromPoint; } foreach (IPath unreshapedPath in GeometryUtils.GetPaths(UnreshapedBoundaryPart)) { var unreshapedPoints = (IPointCollection)unreshapedPath; if (GeometryUtils.AreEqualInXY(unreshapedPath.FromPoint, otherPathOnTargetEnd)) { lastUnreshapedVertex = unreshapedPoints.Point[1]; } else if (GeometryUtils.AreEqualInXY(unreshapedPath.ToPoint, otherPathOnTargetEnd)) { lastUnreshapedVertex = unreshapedPoints.Point[unreshapedPoints.PointCount - 2]; } } if (lastUnreshapedVertex != null) { result = GeometryFactory.CreatePath(lastUnreshapedVertex, toTargetPoint); } } return(result); }
public void LearningTest_ReplaceSegmentsWithNonIdenticalConnectPointsZs() { ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95); IPolyline originalPolyline = GeometryFactory.CreatePolyline( GeometryFactory.CreatePath( GeometryFactory.CreatePoint(2600000, 1200000, 400, double.NaN, lv95), GeometryFactory.CreatePoint(2600010, 1200000, 405, double.NaN, lv95), GeometryFactory.CreatePoint(2600020, 1200000, 410, double.NaN, lv95), GeometryFactory.CreatePoint(2600030, 1200000, 420, double.NaN, lv95))); IPath replacement = GeometryFactory.CreatePath( GeometryFactory.CreatePoint(2600010, 1200000, 0, double.NaN, lv95), GeometryFactory.CreatePoint(2600015, 1200010, 500, double.NaN, lv95), GeometryFactory.CreatePoint(2600020, 1200000, 900, double.NaN, lv95)); // NOTE: The Z value of the first point of the replacement is used, however, the envelope of the resulting pathToReshape is not updated! // Hence it is crucial to insert the exact replacement end points into the geometry to reshape! IPolyline polyline = GeometryFactory.Clone(originalPolyline); var pathToReshape = (ISegmentCollection)((IGeometryCollection)polyline).Geometry[0]; pathToReshape.ReplaceSegmentCollection(1, 2, (ISegmentCollection)replacement); // This makes no difference: //pathToReshape.SegmentsChanged(); Assert.AreEqual(0, ((IPointCollection)pathToReshape).Point[1].Z); Assert.AreEqual(400, polyline.Envelope.ZMin, "Envelope is not inconsistent any more after ArcObjects segment replacment!"); // Make sure this does not happen in SegmentReplacementUtils polyline = GeometryFactory.Clone(originalPolyline); pathToReshape = (ISegmentCollection)((IGeometryCollection)polyline).Geometry[0]; SegmentReplacementUtils.ReplaceSegments((IPath)pathToReshape, replacement, replacement.FromPoint, replacement.ToPoint); Assert.AreEqual(0, ((IPointCollection)pathToReshape).Point[1].Z); Assert.AreEqual(0, polyline.Envelope.ZMin, "Envelope is inconsistent after SegmentReplacementUtils.ReplaceSegments!"); }
public static IPolyline CreatePolyline( [NotNull] IEnumerable <IntersectionPath3D> intersectionPaths, [NotNull] ISpatialReference spatialReference) { var paths = new List <IPath>(); foreach (IntersectionPath3D lineString in intersectionPaths) { List <IPoint> points = lineString.Segments.GetPoints() .Select(p => GeometryFactory.CreatePoint(p.X, p.Y, p.Z)) .ToList(); IPath path = GeometryFactory.CreatePath(points); paths.Add(path); } return(GeometryFactory.CreatePolyline(paths, spatialReference, true, false)); }
private IPath CalculateSourceTargetPointsConnectLine(IPoint sourceConnectPoint, IPoint targetConnectPoint) { IPath result; var unionReplacedPolyline = (IPolyline)GeometryUtils.GetHighLevelGeometry(_unionReshapeInfo.ReplacedSegments); if (GeometryUtils.Intersects(targetConnectPoint, unionReplacedPolyline)) { // use the connection along the replaced segments result = SegmentReplacementUtils.GetSegmentsBetween( sourceConnectPoint, targetConnectPoint, _unionReshapeInfo.ReplacedSegments); } else { result = GeometryFactory.CreatePath(sourceConnectPoint, targetConnectPoint); } return(result); }
public IPolyline GetSourceTargetConnectLines() { IGeometryCollection result = null; object missing = Type.Missing; foreach (KeyValuePair <IPoint, IPoint> sourceTargetPair in SourceTargetPairs) { IPath connectLine = GeometryFactory.CreatePath(sourceTargetPair.Key, sourceTargetPair.Value); if (result == null) { result = (IGeometryCollection)GeometryFactory.CreatePolyline(connectLine); } else { result.AddGeometry(connectLine, ref missing, ref missing); } } return((IPolyline)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 IPath FindConnection(IPolyline geometryToReshapeAsPolyline, ICurve pathOnTarget, bool searchForward) { IPoint toTargetPoint = searchForward ? pathOnTarget.FromPoint : pathOnTarget.ToPoint; if (_intersectingSourceTargetPoints.Count == 0) { return(null); } IPath result = null; IPoint sourcePoint; // if the target point is already on the geometry (due to individual reshape) still // try to connect to source to be consistent with adjacent polygons... //// the target intersection point could have already been met by individual reshape: //if (GeometryUtils.Intersects(geometryToReshapeAsPolyline, toTargetPoint)) //{ // // The targetPoint actually intersects the source -> no connect line needed, but return a usable connect line // IPath singlePointPath = CreateSinglePointPath(toTargetPoint); // result = singlePointPath; //} if (IsTargetIntersectionPoint(toTargetPoint, out sourcePoint)) { //it's an actual target intersection point if (GeometryUtils.Intersects(geometryToReshapeAsPolyline, sourcePoint)) { //TEST: // TODO: inject otherGeometriesIndividualReshapes from outside (using geometryToReshapeAsPolyline is not correct!) IPath otherPolysReplacedSegments = GetReplacedSegmentsForOtherGeometry(geometryToReshapeAsPolyline, sourcePoint, toTargetPoint); if (otherPolysReplacedSegments != null) { result = otherPolysReplacedSegments; } // END TEST else { // if the source point is still part of the current geometry, but an additional connectionLineAtCutOff // might be found that will later be relevant when this path might have been reshaped away again result = GeometryFactory.CreatePath(sourcePoint, toTargetPoint); // TODO: evaluate blocking just before applying - if it is blocked, retry after all other geometries have been reshaped... if (CrossesBlockingGeometry(result)) { result = null; } } } else { // if the target point is on the border between an already reshaped and an unreshaped part: bool targetPointTouchesUnreshapedPart = GeometryUtils.Touches( UnreshapedBoundaryPart, toTargetPoint); if (targetPointTouchesUnreshapedPart) { // Return a usable connection. Do not try to connect back to last unreshaped // vertex because this might have already been done for the adjacent pathOnTarget // and now the toTargetPoint is already ok result = CreateSinglePointPath(toTargetPoint); } } if (result == null && GeometryUtils.AreEqualInXY(sourcePoint, toTargetPoint)) { // TODO: is this ever needed??? // The targetPoint actually intersects the source -> no connect line needed, but return a usable connect line IPath singlePointPath = CreateSinglePointPath(toTargetPoint); return(singlePointPath); } } // the toTargetPoint point could have already been met by individual reshape: if (result == null && GeometryUtils.Intersects(geometryToReshapeAsPolyline, toTargetPoint)) { // The targetPoint actually intersects the source -> no connect line needed, but return a usable connect line IPath singlePointPath = CreateSinglePointPath(toTargetPoint); result = singlePointPath; } return(result); }
public void CanCutMultipartPolyline() { ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95); IPath path1 = GeometryFactory.CreatePath( GeometryFactory.CreatePoint(2600000, 1200000, lv95), GeometryFactory.CreatePoint(2600010, 1200000, lv95)); IPath path2 = GeometryFactory.CreatePath( GeometryFactory.CreatePoint(2600000, 1200002, lv95), GeometryFactory.CreatePoint(2600010, 1200002, lv95)); ICollection <IPath> pathCollection = new List <IPath> { path1, path2 }; IPolyline multipartPolyline = GeometryFactory.CreatePolyline( pathCollection, lv95); // cuts the lower path and assigns the western part to the original feature IPolyline cutOnePartLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2600006, 1200000), GeometryFactory.CreatePoint(2600006, 1200001)); cutOnePartLine.SpatialReference = lv95; IFeature mockFeature = TestUtils.CreateMockFeature(multipartPolyline); var cutter = new FeatureCutter(new[] { mockFeature }); cutter.Cut(cutOnePartLine); IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature]; Assert.AreEqual(2, results.Count); double sizeSum = 0; foreach (IGeometry result in results) { Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result)); sizeSum += GeometryUtils.GetParts((IGeometryCollection)result) .Sum(part => ((ICurve)part).Length); } Assert.IsTrue( MathUtils.AreEqual(((ICurve)multipartPolyline).Length, sizeSum)); // cuts both remaining parts into 4 pieces // Consider re-joining the parts at the left of the line and those at the right // But this logic would also have to be applied for polygons and should probably be optional IPolyline cutBothPartsLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2600004, 1200000), GeometryFactory.CreatePoint(2600004, 1200002)); cutBothPartsLine.SpatialReference = lv95; // the largest ist the first mockFeature.Shape = results[0]; cutter = new FeatureCutter(new[] { mockFeature }); cutter.Cut(cutBothPartsLine); results = cutter.ResultGeometriesByFeature[mockFeature]; Assert.AreEqual(2, results.Count); sizeSum = 0; foreach (IGeometry result in results) { Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result)); sizeSum += GeometryUtils.GetParts((IGeometryCollection)result) .Sum(part => ((ICurve)part).Length); } Assert.IsTrue( MathUtils.AreEqual(((ICurve)mockFeature.Shape).Length, sizeSum)); }