public void CanCutMultipatchWithInnerRingThroughInnerRing() { ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95); IPolygon originalPoly = GeometryFactory.CreatePolygon( GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 50, 50, lv95)); IPolygon innerRingPoly = GeometryFactory.CreatePolygon( GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 10, 10, lv95)); var innerRing = (IRing)((IGeometryCollection)innerRingPoly).Geometry[0]; innerRing.ReverseOrientation(); IMultiPatch multiPatch = GeometryFactory.CreateMultiPatch(originalPoly); GeometryFactory.AddRingToMultiPatch(innerRing, multiPatch, esriMultiPatchRingType .esriMultiPatchInnerRing); // cut line cuts through the inner ring IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2600000 - 100, 1200000), GeometryFactory.CreatePoint(2600000 + 100, 1200000)); cutLine.SpatialReference = lv95; IFeature mockFeature = TestUtils.CreateMockFeature(multiPatch); var cutter = new FeatureCutter(new[] { mockFeature }); cutter.ZSourceProvider = new DatasetSpecificSettingProvider <ChangeAlongZSource>( string.Empty, ChangeAlongZSource.SourcePlane); cutter.Cut(cutLine); IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature]; Assert.AreEqual(2, results.Count); double areaSum = 0; var partCount = 0; foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature]) { Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result)); areaSum += GeometryUtils.GetParts((IGeometryCollection)result) .Sum(part => ((IArea)part).Area); partCount += GeometryUtils.GetParts((IGeometryCollection)result).Count(); } Assert.AreEqual(2, partCount); Assert.AreEqual(((IArea)originalPoly).Area + ((IArea)innerRing).Area, areaSum, 0.0001); }
private static SegmentProxy CreateSegment([NotNull] IPoint p0, [NotNull] IPoint p1) { IPolyline l0 = GeometryFactory.CreateLine(p0, p1); ISegment s0 = ((ISegmentCollection)l0).get_Segment(0); return(new AoSegmentProxy(s0, 0, 0)); }
public void CanReshapeMultipatch() { ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95); IPolygon polygon = GeometryFactory.CreatePolygon( GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 50, 20, lv95)); IMultiPatch multiPatch = GeometryFactory.CreateMultiPatch( polygon); IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2600000 - 100, 1200000), GeometryFactory.CreatePoint(2600000 + 100, 1200000)); cutLine.SpatialReference = lv95; var reshapePath = (IPath)((IGeometryCollection)cutLine).Geometry[0]; var reshapeInfo = new ReshapeInfo(multiPatch, reshapePath, null); IList <ReshapeInfo> singleReshapes; ReshapeUtils.ReshapeAllGeometryParts(reshapeInfo, reshapePath, out singleReshapes); var reshapedRing = (IRing)((IGeometryCollection)multiPatch).Geometry[0]; Assert.True(MathUtils.AreEqual(((IArea)reshapedRing).Area, ((IArea)polygon).Area / 2, 0.1)); }
public void CanExecuteContainerLineNearTileBoundary() { IFeatureClass featureClass = CreatePolylineFeatureClass("CanExecuteContainerLineNearTileBoundary", 0.01); // Create error Feature const double x = 2600000; const double y = 1200000; IFeature row1 = featureClass.CreateFeature(); row1.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(x, y), GeometryFactory.CreatePoint(x, y + 800)); row1.Store(); IFeature row2 = featureClass.CreateFeature(); row2.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(x + 1000, y), GeometryFactory.CreatePoint(x + 1000, y + 800)); row2.Store(); // row3 is within tile[0,0], but within the search tolerance from tile[0,1] IFeature row3 = featureClass.CreateFeature(); row3.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(x + 300, y), GeometryFactory.CreatePoint(x + 300, y + 599.000)); row3.Store(); var helper = new CanExecuteContainerHelper(); helper.ExpectedMaximumRowCountPerTile = 2; var test = new VerifyingContainerTest((ITable)featureClass) { OnExecuteCore = helper.ExecuteRow, OnCompleteTile = helper.CompleteTile, OnCachedRow = helper.CachedRow }; test.SetSearchDistance(2); var container = new TestContainer.TestContainer { TileSize = 600 }; container.AddTest(test); container.MaxCachedPointCount = 1; // disable caching container.Execute(); Assert.AreEqual(4 + 1, helper.CompleteTileCount); // + 1 : wegen initialem Tile Assert.AreEqual( 5, helper.ExecuteRowCount); // row1,row in 2 Tiles, row3 only executed in first Tile Assert.AreEqual(6, helper.CachedRowCount); // 3 features x 2 intersected tiles }
public IPolygon CreateBuffer(double distance) { const bool forceCreation = false; IPolyline polyLine = GetPolyline(forceCreation); IPolyline bufferInput; if (GeometryUtils.HasNonLinearSegments(polyLine)) { if (polyLine.Length > 0) { bufferInput = GeometryFactory.Clone(polyLine); double xyTolerance = GeometryUtils.GetXyTolerance(polyLine); double xyResolution = GeometryUtils.GetXyResolution(polyLine); // note: buffering a non-linear segments always results in a densified buffer // apparently, the input is first densified with a large max. densify deviation // --> the input may not be contained in the buffer for small buffer distances // --> we need to densify the input ourselves to an appropriate max. deviation value double densifyDeviation = Math.Min(xyTolerance / 2, distance / 2); double minimumAllowedDeviation = xyResolution * 2.01; if (densifyDeviation < minimumAllowedDeviation) { densifyDeviation = minimumAllowedDeviation; } bufferInput.Densify(0, densifyDeviation); } else { bufferInput = GeometryFactory.CreateLine(polyLine.FromPoint, polyLine.ToPoint); } } else { bufferInput = polyLine; } using (var factory = new BufferFactory(explodeBuffers: false, densify: false)) { IPolygon result = null; foreach (IPolygon polygon in factory.Buffer(bufferInput, distance)) { Assert.Null(result, "more than 1 buffer geometry found"); result = polygon; } return(Assert.NotNull(result, "no buffer geometry found")); } }
public void CannotCutMultipartPolygonWithCutLineWithinTolerance() { ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95); IPolygon originalPoly = GeometryFactory.CreatePolygon( GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 100, 100, lv95)); IPolygon innerRingPoly = GeometryFactory.CreatePolygon( GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 10, 10, lv95)); IPolygon secondPart = GeometryFactory.CreatePolygon( GeometryFactory.CreateEnvelope(2700000, 1200000, 500, 100, 100, lv95)); ((IGeometryCollection)originalPoly).AddGeometryCollection( (IGeometryCollection)innerRingPoly); ((IGeometryCollection)originalPoly).AddGeometryCollection( (IGeometryCollection)secondPart); GeometryUtils.Simplify(originalPoly); // The cut line runs along the second ring (and diverts off to the outside) IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2700000 + 50, 1200000 - 30), GeometryFactory.CreatePoint(2700000 + 50, 1200000), GeometryFactory.CreatePoint(2700000 + 130, 1200000 + 50)); cutLine.SpatialReference = lv95; bool customIntersectOrig = IntersectionUtils.UseCustomIntersect; try { IntersectionUtils.UseCustomIntersect = false; const ChangeAlongZSource zSource = ChangeAlongZSource.InterpolatedSource; var resultsAo = CutGeometryUtils.TryCut(originalPoly, cutLine, zSource); IntersectionUtils.UseCustomIntersect = true; var resultsGeom = CutGeometryUtils.TryCut(originalPoly, cutLine, zSource); Assert.Null(resultsAo); Assert.Null(resultsGeom); } finally { IntersectionUtils.UseCustomIntersect = customIntersectOrig; } }
private IGeometry GetErrorGeometry([NotNull] ISegment segment) { IPoint fromPoint = segment.FromPoint; IPoint toPoint = segment.ToPoint; if (fromPoint != null && !fromPoint.IsEmpty && toPoint != null && !toPoint.IsEmpty) { return(GeometryFactory.CreateLine(fromPoint, toPoint)); } return(TestUtils.GetEnlargedExtentPolygon(segment, _xyTolerance)); }
public void CanCutMultipatchWithSelfIntersectingSketch() { // {FE286920-3D4C-4CB3-AC22-51056B97A23F} from TLM: IFeature mockFeature = TestUtils.CreateMockFeature("MultipatchWithVerticalWalls.xml"); ISpatialReference lv95 = mockFeature.Shape.SpatialReference; // Use case: snap inside the multipatch in order to create a sketch segment along an existing multipatch segment to cut along, // then use F7 (segment deflection) with deflection 0 to prolong the sketch line to make sure it cuts across the entire multipatch. // NOTE: The non-simple intersect output can only be reproduced with these real-world coordinates / snapped to storage SR it would work ok // Fix: simplify IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2574913.26117225, 1196875.8438835, lv95), GeometryFactory.CreatePoint(2574917.7921709, 1196878.12591931, lv95), GeometryFactory.CreatePoint(2574908.14863447, 1196873.26895571, lv95), GeometryFactory.CreatePoint(2574922.05492981, 1196880.27285628, lv95)); double originalArea = ((IArea3D)mockFeature.Shape).Area3D; var cutter = new FeatureCutter(new[] { mockFeature }); cutter.ZSourceProvider = new DatasetSpecificSettingProvider <ChangeAlongZSource>( string.Empty, ChangeAlongZSource.SourcePlane); cutter.Cut(cutLine); IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature]; Assert.AreEqual(2, results.Count); double areaSum = 0; var totalParts = 0; foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature]) { Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result)); totalParts += ((IGeometryCollection)result).GeometryCount; areaSum += ((IArea3D)result).Area3D; } Assert.AreEqual(6, totalParts); const double epsilon = 0.0001; Assert.IsTrue(MathUtils.AreEqual(originalArea, areaSum, epsilon)); }
public void CanCutMultipatchWithVerticalWalls() { // {FE286920-3D4C-4CB3-AC22-51056B97A23F} from TLM: IFeature mockFeature = TestUtils.CreateMockFeature("MultipatchWithVerticalWalls.xml"); ISpatialReference lv95 = mockFeature.Shape.SpatialReference; IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2574909.000, 1196870.000, lv95), GeometryFactory.CreatePoint(2574924.000, 1196878.000, lv95)); double originalArea = ((IArea)mockFeature.Shape).Area; double originalPartAreaSum = GeometryUtils.GetParts((IGeometryCollection)mockFeature.Shape) .Sum(part => ((IArea)part).Area); var cutter = new FeatureCutter(new[] { mockFeature }); cutter.ZSourceProvider = new DatasetSpecificSettingProvider <ChangeAlongZSource>( string.Empty, ChangeAlongZSource.SourcePlane); cutter.Cut(cutLine); IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature]; Assert.AreEqual(2, results.Count); double areaSum = 0; double partAreaSum = 0; foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature]) { Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result)); Assert.AreEqual(3, ((IGeometryCollection)result).GeometryCount); areaSum += ((IArea)result).Area; partAreaSum += GeometryUtils.GetParts((IGeometryCollection)result) .Sum(part => ((IArea)part).Area); } // The sum of all parts is not the same because some rings have negative orientation Assert.AreEqual(originalArea, areaSum, 0.01); Assert.AreEqual(originalPartAreaSum, partAreaSum, 0.01); }
public void CanCutMultipatchWithVerticalWallsThroughVerticalWallsSnapped() { // {FE286920-3D4C-4CB3-AC22-51056B97A23F} from TLM: IFeature mockFeature = TestUtils.CreateMockFeature("MultipatchWithVerticalWalls.xml"); ISpatialReference lv95 = mockFeature.Shape.SpatialReference; IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2574923.000, 1196869.000, lv95), GeometryFactory.CreatePoint(2574912.000, 1196885.000, lv95)); IPolygon origFootprint = GeometryFactory.CreatePolygon(mockFeature.Shape); cutLine = IntersectionUtils.GetIntersectionLines( cutLine, origFootprint, true, true); double originalArea = ((IArea3D)mockFeature.Shape).Area3D; var cutter = new FeatureCutter(new[] { mockFeature }); cutter.ZSourceProvider = new DatasetSpecificSettingProvider <ChangeAlongZSource>( string.Empty, ChangeAlongZSource.SourcePlane); cutter.Cut(cutLine); IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature]; Assert.AreEqual(2, results.Count); double areaSum = 0; var totalParts = 0; foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature]) { Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result)); totalParts += ((IGeometryCollection)result).GeometryCount; areaSum += ((IArea3D)result).Area3D; } Assert.AreEqual(7, totalParts); Assert.IsTrue(MathUtils.AreEqual(originalArea, areaSum, 0.01)); }
public void CanExecuteContainerTwoVerticalLines() { IFeatureClass featureClass = CreatePolylineFeatureClass("CanExecuteContainerTwoVerticalLines", 0.01); // Create error Feature const double x = 2600000; const double y = 1200000; IFeature row1 = featureClass.CreateFeature(); row1.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(x, y), GeometryFactory.CreatePoint(x, y + 800)); row1.Store(); IFeature row2 = featureClass.CreateFeature(); row2.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(x + 1000, y), GeometryFactory.CreatePoint(x + 1000, y + 800)); row2.Store(); var helper = new CanExecuteContainerHelper(); helper.ExpectedMaximumRowCountPerTile = 1; var test = new VerifyingContainerTest((ITable)featureClass) { OnExecuteCore = helper.ExecuteRow, OnCompleteTile = helper.CompleteTile }; test.SetSearchDistance(10); var container = new TestContainer.TestContainer { TileSize = 600 }; container.AddTest(test); container.Execute(); Assert.AreEqual(4 + 1, helper.CompleteTileCount); // + 1 : wegen initialem Tile Assert.AreEqual(4, helper.ExecuteRowCount); // 2 features x 2 intersected tiles }
public void CanCutMultipatchThroughVerticalWall_Top5022b() { // {5C8388FB-9A00-4AF4-BB0D-D120C8BDA88D} only the northern dormer window: IFeature mockFeature = TestUtils.CreateMockFeature("TOP5022b_MultipatchToCut.xml"); ISpatialReference lv95 = mockFeature.Shape.SpatialReference; IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2694073.141, 1263073.24, 408.781000000003), GeometryFactory.CreatePoint(2694073.91, 1263036.271, 408.781000000003)); cutLine.SpatialReference = lv95; double originalArea = ((IArea3D)mockFeature.Shape).Area3D; var cutter = new FeatureCutter(new[] { mockFeature }); cutter.ZSourceProvider = new DatasetSpecificSettingProvider <ChangeAlongZSource>( string.Empty, ChangeAlongZSource.SourcePlane); cutter.Cut(cutLine); IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature]; Assert.AreEqual(2, results.Count); double areaSum = 0; var totalParts = 0; foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature]) { Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result)); totalParts += ((IGeometryCollection)result).GeometryCount; areaSum += ((IArea3D)result).Area3D; } Assert.AreEqual(7, totalParts); Assert.IsTrue(MathUtils.AreEqual(originalArea, areaSum, 0.01)); }
public void CanCutMultipatch() { ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95); IPolygon originalPoly = GeometryFactory.CreatePolygon( GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 50, 20, lv95)); IMultiPatch multiPatch = GeometryFactory.CreateMultiPatch(originalPoly); IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2600000 - 100, 1200000), GeometryFactory.CreatePoint(2600000 + 100, 1200000)); cutLine.SpatialReference = lv95; IFeature mockFeature = TestUtils.CreateMockFeature(multiPatch); var cutter = new FeatureCutter(new[] { mockFeature }); cutter.ZSourceProvider = new DatasetSpecificSettingProvider <ChangeAlongZSource>( string.Empty, ChangeAlongZSource.SourcePlane); cutter.Cut(cutLine); IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature]; Assert.AreEqual(2, results.Count); double areaSum = 0; foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature]) { Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result)); areaSum += GeometryUtils.GetParts((IGeometryCollection)result) .Sum(part => ((IArea)part).Area); } Assert.IsTrue(MathUtils.AreEqual(((IArea)originalPoly).Area, areaSum)); }
public void TestFormat() { CultureInfo origCulture = Thread.CurrentThread.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; IFeatureClass featureClass = TestWorkspaceUtils.CreateSimpleFeatureClass(_testWs, "TestFormat", null, esriGeometryType .esriGeometryPolyline, esriSRProjCS2Type .esriSRProjCS_CH1903Plus_LV95); // make sure the table is known by the workspace ((IWorkspaceEdit)_testWs).StartEditing(false); ((IWorkspaceEdit)_testWs).StopEditing(true); { // Create error Feature IFeature row = featureClass.CreateFeature(); const double x = 2600000; const double y = 1200000; row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(x, y), GeometryFactory.CreatePoint(x + 0.3, y)); row.Store(); } var test = new QaSegmentLength(featureClass, 0.5, false); test.QaError += Test_QaFormatError; _errorCount = 0; test.Execute(); Assert.AreEqual(1, _errorCount); } finally { Thread.CurrentThread.CurrentCulture = origCulture; } }
public void CanCutMultipatchThroughVerticalWall_Top5022a() { // {4286CCE0-4539-4D91-B14B-1C3D79640021} from TLM: IFeature mockFeature = TestUtils.CreateMockFeature("TOP5022a_MultipatchToCut.xml"); ISpatialReference lv95 = mockFeature.Shape.SpatialReference; IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2694016.709, 1263646, lv95), GeometryFactory.CreatePoint(2694025, 1263657, lv95)); double originalArea = ((IArea3D)mockFeature.Shape).Area3D; var cutter = new FeatureCutter(new[] { mockFeature }); cutter.ZSourceProvider = new DatasetSpecificSettingProvider <ChangeAlongZSource>( string.Empty, ChangeAlongZSource.SourcePlane); cutter.Cut(cutLine); IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature]; Assert.AreEqual(2, results.Count); double areaSum = 0; var totalParts = 0; foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature]) { Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result)); totalParts += ((IGeometryCollection)result).GeometryCount; areaSum += ((IArea3D)result).Area3D; } Assert.AreEqual(6, totalParts); Assert.IsTrue(MathUtils.AreEqual(originalArea, areaSum, 0.01)); }
private static IGeometry GetErrorGeometry([NotNull] IPoint point, [NotNull] IPoint nearPoint, bool reportAsConnectionLine) { if (reportAsConnectionLine) { IPolyline line = GeometryFactory.CreateLine(GeometryFactory.Clone(point), GeometryFactory.Clone( nearPoint)); ((ITopologicalOperator)line).Simplify(); // check if the line is too short, if so report the point only return(line.IsEmpty ? GeometryFactory.Clone(point) : (IGeometry)line); } IMultipoint multipoint = GeometryFactory.CreateMultipoint(point, nearPoint); ((ITopologicalOperator)multipoint).Simplify(); return(multipoint); }
public void CannotPerformVerticalReshapeOnFlatRing() { // Originally this geometry resulted in an endless loop because // IntersectionUtils.IntersectNonPlanar returned the incorrect result ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95); // The problem cannot be reproduced with standard resolution var srResolution = (ISpatialReferenceResolution)lv95; srResolution.set_XYResolution(true, 0.001); var srTolerance = (ISpatialReferenceTolerance)lv95; srTolerance.XYTolerance = 0.01; // Vertical triangle, oriented towards the south: var points = new WKSPointZ[6]; points[0] = new WKSPointZ { X = 2578309.3000000007, Y = 1183264.3999999985, Z = 619.14500000000407 }; points[1] = new WKSPointZ { X = 2578295.6829999983, Y = 1183260.568, Z = 619.14500000000407 }; points[2] = new WKSPointZ { X = 2578293.9990000017, Y = 1183266.5500000007, Z = 619.14500000000407 }; points[3] = new WKSPointZ { X = 2578295.9070000015, Y = 1183267.1559999995, Z = 619.14500000000407 }; points[4] = new WKSPointZ { X = 2578307.5989999995, Y = 1183270.4450000003, Z = 619.14500000000407 }; points[5] = new WKSPointZ { X = 2578309.3000000007, Y = 1183264.3999999985, Z = 619.14500000000407 }; IRing ring = new RingClass(); ((IGeometry)ring).SpatialReference = lv95; GeometryUtils.MakeZAware(ring); GeometryUtils.SetWKSPointZs((IPointCollection4)ring, points); IMultiPatch multipatch = new MultiPatchClass(); ((IGeometry)multipatch).SpatialReference = lv95; GeometryUtils.MakeZAware(multipatch); GeometryUtils.MakeMAware(multipatch); GeometryUtils.MakePointIDAware(multipatch); GeometryFactory.AddRingToMultiPatch(ring, multipatch, esriMultiPatchRingType .esriMultiPatchOuterRing); var unReshaped = (IRing)((IGeometryCollection)multipatch).Geometry[0]; IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2578314.9090000018, 1183246.2400000021), GeometryFactory.CreatePoint(2578307.4299999997, 1183270.4310000017)); cutLine.SpatialReference = lv95; //GeometryUtils.MakeZAware(cutLine); var reshapePath = (IPath)((IGeometryCollection)cutLine).Geometry[0]; Assert.IsTrue(((ICurve3D)unReshaped).IsClosed3D); var reshapeInfo = new ReshapeInfo(multipatch, reshapePath, null); IList <IPath> verticalPaths; Assert.IsFalse(reshapeInfo.IsVerticalRingReshape(0, out verticalPaths)); Assert.AreEqual(0, verticalPaths.Count); Assert.IsTrue(ReshapeUtils.ReshapeGeometry(reshapeInfo, reshapePath)); var reshapedRing = (IRing)((IGeometryCollection)multipatch).Geometry[0]; Assert.AreEqual(6, ((IPointCollection)reshapedRing).PointCount); Assert.IsTrue(((ICurve3D)reshapedRing).IsClosed3D); }
public void CanReshapeVerticalRingWithMutipleReshapeLineCrossings() { ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95); // Vertical triangle, oriented towards the south: var points = new WKSPointZ[4]; points[0] = new WKSPointZ { X = 2600000, Y = 1200000, Z = 500 }; points[1] = new WKSPointZ { X = 2600100, Y = 1200000, Z = 500 }; points[2] = new WKSPointZ { X = 2600050, Y = 1200000, Z = 1000 }; points[3] = new WKSPointZ { X = 2600000, Y = 1200000, Z = 500 }; IRing ring = new RingClass(); ((IGeometry)ring).SpatialReference = lv95; GeometryUtils.MakeZAware(ring); GeometryUtils.SetWKSPointZs((IPointCollection4)ring, points); IMultiPatch multipatch = new MultiPatchClass(); ((IGeometry)multipatch).SpatialReference = lv95; GeometryUtils.MakeZAware(multipatch); GeometryUtils.MakeMAware(multipatch); GeometryUtils.MakePointIDAware(multipatch); GeometryFactory.AddRingToMultiPatch(ring, multipatch, esriMultiPatchRingType .esriMultiPatchOuterRing); var unReshaped = (IRing)((IGeometryCollection)multipatch).Geometry[0]; IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2600075, 1200000 - 100, 222), GeometryFactory.CreatePoint(2600075, 1200000 + 100, 222), GeometryFactory.CreatePoint(2600025, 1200000 + 100, 222), GeometryFactory.CreatePoint(2600025, 1200000 - 100, 222)); cutLine.SpatialReference = lv95; GeometryUtils.MakeZAware(cutLine); var reshapePath = (IPath)((IGeometryCollection)cutLine).Geometry[0]; Assert.IsTrue(((ICurve3D)unReshaped).IsClosed3D); var reshapeInfo = new ReshapeInfo(multipatch, reshapePath, null); IList <IPath> verticalPaths; Assert.IsTrue(reshapeInfo.IsVerticalRingReshape(0, out verticalPaths)); Assert.AreEqual(2, verticalPaths.Count); // Currently it is the caller's responsability to make 2 different reshapes using the desired side... // We want the middle part: // verticalPaths[0] is the one at X=2600025 var reshape1 = new ReshapeInfo(multipatch, verticalPaths[0], null); reshape1.RingReshapeSide = RingReshapeSideOfLine.Right; reshape1.NonPlanar = true; ReshapeUtils.ReshapeGeometry(reshape1, verticalPaths[0]); // verticalPaths[1] is the one at X=2600075 var reshape2 = new ReshapeInfo(multipatch, verticalPaths[1], null); reshape2.RingReshapeSide = RingReshapeSideOfLine.Left; reshape2.NonPlanar = true; ReshapeUtils.ReshapeGeometry(reshape2, verticalPaths[1]); var reshapedRing = (IRing)((IGeometryCollection)multipatch).Geometry[0]; Assert.AreEqual(6, ((IPointCollection)reshapedRing).PointCount); Assert.IsTrue(((ICurve3D)reshapedRing).IsClosed3D); double expectedLength = Math.Sqrt(50 * 50 + 500 * 500) * 1.0 + 50 + 2 * 250; Assert.AreEqual(expectedLength, ((ICurve3D)reshapedRing).Length3D, 0.001); var newPoints = new WKSPointZ[6]; GeometryUtils.QueryWKSPointZs((IPointCollection4)reshapedRing, newPoints); Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600025, Y = 1200000, Z = 500 }, newPoints[0], 0, 0)); // the new cut points Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600075, Y = 1200000, Z = 500 }, newPoints[1], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600075, Y = 1200000, Z = 750 }, newPoints[2], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600050, Y = 1200000, Z = 1000 }, newPoints[3], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600025, Y = 1200000, Z = 750 }, newPoints[4], 0, 0)); }
public void CanReshapeVerticalTriangularRingInMultipatch() { ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95); //IRing ring = GeometryFactory.CreateRing( // GeometryFactory.CreatePath()) var points = new WKSPointZ[4]; points[0] = new WKSPointZ { X = 2600000, Y = 1200000, Z = 500 }; points[1] = new WKSPointZ { X = 2600100, Y = 1200000, Z = 500 }; points[2] = new WKSPointZ { X = 2600050, Y = 1200000, Z = 1000 }; points[3] = new WKSPointZ { X = 2600000, Y = 1200000, Z = 500 }; IRing ring = new RingClass(); ((IGeometry)ring).SpatialReference = lv95; GeometryUtils.MakeZAware(ring); GeometryUtils.SetWKSPointZs((IPointCollection4)ring, points); IMultiPatch multipatch = new MultiPatchClass(); ((IGeometry)multipatch).SpatialReference = lv95; GeometryUtils.MakeZAware(multipatch); GeometryUtils.MakeMAware(multipatch); GeometryUtils.MakePointIDAware(multipatch); GeometryFactory.AddRingToMultiPatch(ring, multipatch, esriMultiPatchRingType .esriMultiPatchOuterRing); var unReshaped = (IRing)((IGeometryCollection)multipatch).Geometry[0]; int originalPointCount = ((IPointCollection)unReshaped).PointCount; IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2600075, 1200000 - 100, 222), GeometryFactory.CreatePoint(2600075, 1200000 + 100, 222)); cutLine.SpatialReference = lv95; GeometryUtils.MakeZAware(cutLine); var reshapePath = (IPath)((IGeometryCollection)cutLine).Geometry[0]; Assert.IsTrue(((ICurve3D)unReshaped).IsClosed3D); var reshapeInfo = new ReshapeInfo(multipatch, reshapePath, null) { NonPlanar = true }; IList <ReshapeInfo> singleReshapes; ReshapeUtils.ReshapeAllGeometryParts(reshapeInfo, reshapePath, out singleReshapes); var reshapedRing = (IRing)((IGeometryCollection)multipatch).Geometry[0]; Assert.AreEqual(originalPointCount + 1, ((IPointCollection)reshapedRing).PointCount); Assert.IsTrue(((ICurve3D)reshapedRing).IsClosed3D); double expectedLength = Math.Sqrt(50 * 50 + 500 * 500) * 1.5 + 75 + 250; Assert.AreEqual(expectedLength, ((ICurve3D)reshapedRing).Length3D, 0.001); var newPoints = new WKSPointZ[5]; GeometryUtils.QueryWKSPointZs((IPointCollection4)reshapedRing, newPoints); // first, fourth and last Assert.IsTrue(GeometryUtils.IsSamePoint(points[0], newPoints[0], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(points[2], newPoints[3], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(points[3], newPoints[4], 0, 0)); // the new cut points Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600075, Y = 1200000, Z = 500 }, newPoints[1], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600075, Y = 1200000, Z = 750 }, newPoints[2], 0, 0)); // And now reshape right through the vertex at the top, this time reshape the left cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2600050, 1200000 - 100, 222), GeometryFactory.CreatePoint(2600050, 1200000 + 100, 222)); cutLine.SpatialReference = lv95; GeometryUtils.MakeZAware(cutLine); reshapePath = (IPath)((IGeometryCollection)cutLine).Geometry[0]; reshapeInfo = new ReshapeInfo(multipatch, reshapePath, null) { NonPlanar = true }; // keep the right (small part) reshapeInfo.RingReshapeSide = RingReshapeSideOfLine.Right; ReshapeUtils.ReshapeAllGeometryParts(reshapeInfo, reshapePath, out singleReshapes); reshapedRing = (IRing)((IGeometryCollection)multipatch).Geometry[0]; Assert.AreEqual(5, ((IPointCollection)reshapedRing).PointCount); Assert.IsTrue(((ICurve3D)reshapedRing).IsClosed3D); expectedLength = Math.Sqrt(50 * 50 + 500 * 500) * 0.5 + 25 + 500 + 250; Assert.AreEqual(expectedLength, ((ICurve3D)reshapedRing).Length3D, 0.001); newPoints = new WKSPointZ[5]; GeometryUtils.QueryWKSPointZs((IPointCollection4)reshapedRing, newPoints); Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600050, Y = 1200000, Z = 500 }, newPoints[0], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600075, Y = 1200000, Z = 500 }, newPoints[1], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600075, Y = 1200000, Z = 750 }, newPoints[2], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600050, Y = 1200000, Z = 1000 }, newPoints[3], 0, 0)); }
public void CanReshapeVerticalSquareRingInMultipatch() { ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95); //IRing ring = GeometryFactory.CreateRing( // GeometryFactory.CreatePath()) var points = new WKSPointZ[5]; points[0] = new WKSPointZ { X = 2600000, Y = 1200000, Z = 500 }; points[1] = new WKSPointZ { X = 2600100, Y = 1200000, Z = 500 }; points[2] = new WKSPointZ { X = 2600100, Y = 1200000, Z = 1000 }; points[3] = new WKSPointZ { X = 2600000, Y = 1200000, Z = 1000 }; points[4] = new WKSPointZ { X = 2600000, Y = 1200000, Z = 500 }; IRing ring = new RingClass(); ((IGeometry)ring).SpatialReference = lv95; GeometryUtils.MakeZAware(ring); GeometryUtils.SetWKSPointZs((IPointCollection4)ring, points); IMultiPatch multipatch = new MultiPatchClass(); ((IGeometry)multipatch).SpatialReference = lv95; GeometryUtils.MakeZAware(multipatch); GeometryUtils.MakeMAware(multipatch); GeometryUtils.MakePointIDAware(multipatch); GeometryFactory.AddRingToMultiPatch(ring, multipatch, esriMultiPatchRingType .esriMultiPatchOuterRing); var unReshaped = (IRing)((IGeometryCollection)multipatch).Geometry[0]; int originalPointCount = ((IPointCollection)unReshaped).PointCount; // Left reshape is slightly larger -> vertical reshape side is determined by size only IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2600051, 1200000 - 100, 222), GeometryFactory.CreatePoint(2600051, 1200000 + 100, 222)); cutLine.SpatialReference = lv95; GeometryUtils.MakeZAware(cutLine); var reshapePath = (IPath)((IGeometryCollection)cutLine).Geometry[0]; Assert.IsTrue(((ICurve3D)unReshaped).IsClosed3D); var reshapeInfo = new ReshapeInfo(multipatch, reshapePath, null) { NonPlanar = true }; IList <ReshapeInfo> singleReshapes; ReshapeUtils.ReshapeAllGeometryParts(reshapeInfo, reshapePath, out singleReshapes); var reshapedRing = (IRing)((IGeometryCollection)multipatch).Geometry[0]; Assert.AreEqual(originalPointCount, ((IPointCollection)reshapedRing).PointCount); Assert.IsTrue(((ICurve3D)reshapedRing).IsClosed3D); Assert.AreEqual(2 * 500 + 2 * 51, ((ICurve3D)reshapedRing).Length3D); var newPoints = new WKSPointZ[5]; GeometryUtils.QueryWKSPointZs((IPointCollection4)reshapedRing, newPoints); // first, fourth and last Assert.IsTrue(GeometryUtils.IsSamePoint(points[0], newPoints[0], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(points[3], newPoints[3], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(points[4], newPoints[4], 0, 0)); // the new cut points Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600051, Y = 1200000, Z = 500 }, newPoints[1], 0, 0)); Assert.IsTrue(GeometryUtils.IsSamePoint(new WKSPointZ { X = 2600051, Y = 1200000, Z = 1000 }, newPoints[2], 0, 0)); }
private void TestFlowDirMultiExpression(IFeatureWorkspace ws) { IFeatureClass fc1; { var fields = new FieldsClass(); fields.AddField(FieldUtils.CreateOIDField()); fields.AddField(FieldUtils.CreateField("FlowDir", esriFieldType.esriFieldTypeInteger)); fields.AddField(FieldUtils.CreateShapeField( "Shape", esriGeometryType.esriGeometryPolyline, SpatialReferenceUtils.CreateSpatialReference ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95, true), 1000)); fc1 = DatasetUtils.CreateSimpleFeatureClass(ws, "TestFlowDirMultiExpression1", fields); } IFeatureClass fc2; { var fields = new FieldsClass(); fields.AddField(FieldUtils.CreateOIDField()); fields.AddField(FieldUtils.CreateField("FlowDir", esriFieldType.esriFieldTypeInteger)); fields.AddField(FieldUtils.CreateShapeField( "Shape", esriGeometryType.esriGeometryPolyline, SpatialReferenceUtils.CreateSpatialReference ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95, true), 1000)); fc2 = DatasetUtils.CreateSimpleFeatureClass(ws, "TestFlowDirMultiExpression2", fields); } // make sure the tables are known by the workspace ((IWorkspaceEdit)ws).StartEditing(false); ((IWorkspaceEdit)ws).StopEditing(true); { IFeature row = fc1.CreateFeature(); row.set_Value(1, 5); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(100, 200), GeometryFactory.CreatePoint(110, 190)); row.Store(); } { IFeature row = fc2.CreateFeature(); row.set_Value(1, 5); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(120, 190), GeometryFactory.CreatePoint(110, 190)); row.Store(); } { IFeature row = fc1.CreateFeature(); row.set_Value(1, null); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(120, 190), GeometryFactory.CreatePoint(130, 190)); row.Store(); } { var test = new QaFlowLogic( new[] { fc1, fc2 }, new[] { "FlowDir > 6", "FlowDir < 6" } // no feature fc1 will be inverted, feature of fc2 will be inverted ); test.QaError += Test_QaError; _errorCount = 0; test.Execute(); Assert.AreEqual(1, _errorCount); test.QaError -= Test_QaError; var container = new TestContainer(); container.AddTest(test); _errorCount = 0; container.QaError += Test_QaError; container.Execute(); Assert.AreEqual(1, _errorCount); } { var test = new QaFlowLogic( new[] { fc1, fc2 }, new[] { "FlowDir > 6" } // no feature will be inverted ); test.QaError += Test_QaError; _errorCount = 0; test.Execute(); Assert.AreEqual(3, _errorCount); test.QaError -= Test_QaError; var container = new TestContainer(); container.AddTest(test); container.QaError += Test_QaError; _errorCount = 0; container.Execute(); Assert.AreEqual(3, _errorCount); } }
private void TestFlowDirExpression(IFeatureWorkspace ws) { IFieldsEdit fields = new FieldsClass(); fields.AddField(FieldUtils.CreateOIDField()); fields.AddField(FieldUtils.CreateField("FlowDir", esriFieldType.esriFieldTypeInteger)); fields.AddField(FieldUtils.CreateShapeField( "Shape", esriGeometryType.esriGeometryPolyline, SpatialReferenceUtils.CreateSpatialReference ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95, true), 1000)); IFeatureClass featureClass = DatasetUtils.CreateSimpleFeatureClass(ws, "TestFlowDirExpression", fields); // make sure the table is known by the workspace ((IWorkspaceEdit)ws).StartEditing(false); ((IWorkspaceEdit)ws).StopEditing(true); { IFeature row = featureClass.CreateFeature(); row.set_Value(1, 5); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(100, 200), GeometryFactory.CreatePoint(110, 190)); row.Store(); } { IFeature row = featureClass.CreateFeature(); row.set_Value(1, 10); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(120, 190), GeometryFactory.CreatePoint(110, 190)); row.Store(); } IPoint lastPoint; { IFeature row = featureClass.CreateFeature(); row.set_Value(1, null); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(120, 190), GeometryFactory.CreatePoint(130, 190)); row.Store(); lastPoint = ((IPolyline)row.Shape).ToPoint; } var test = new QaFlowLogic(new[] { featureClass }, new[] { "FlowDir > 6" }); test.QaError += Test_QaError; _errorCount = 0; test.Execute(); Assert.AreEqual(1, _errorCount); Assert.AreEqual(lastPoint.X, _lastErrorPoint.X); Assert.AreEqual(lastPoint.Y, _lastErrorPoint.Y); test.QaError -= Test_QaError; var container = new TestContainer(); container.AddTest(test); container.QaError += Test_QaError; _errorCount = 0; container.Execute(); Assert.AreEqual(1, _errorCount); Assert.AreEqual(lastPoint.X, _lastErrorPoint.X); Assert.AreEqual(lastPoint.Y, _lastErrorPoint.Y); }
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)); }
public void CanCutPolygonWithZSourcePlane() { ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95); IPolygon originalPoly = GeometryFactory.CreatePolygon( GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 100, 100, lv95)); IPolygon innerRingPoly = GeometryFactory.CreatePolygon( GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 10, 10, lv95)); Plane3D plane = Plane3D.FitPlane(new List <Pnt3D> { new Pnt3D(2600000, 1200000, 500), new Pnt3D(2600100, 1200100, 580), new Pnt3D(2600000, 1200100, 550) }); ((IGeometryCollection)originalPoly).AddGeometryCollection( (IGeometryCollection)innerRingPoly); GeometryUtils.Simplify(originalPoly); ChangeAlongZUtils.AssignZ((IPointCollection)originalPoly, plane); // The non-z-aware cut line cuts north of the inner ring -> the inner ring should be assigned to the southern result IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2600000 - 100, 1200020), GeometryFactory.CreatePoint(2600000 - 40, 1200020), GeometryFactory.CreatePoint(2600000 - 40, 1200040), GeometryFactory.CreatePoint(2600000 + 40, 1200040), GeometryFactory.CreatePoint(2600000 + 40, 1200020), GeometryFactory.CreatePoint(2600000 + 100, 1200020)); cutLine.SpatialReference = lv95; bool customIntersectOrig = IntersectionUtils.UseCustomIntersect; try { IntersectionUtils.UseCustomIntersect = false; const ChangeAlongZSource zSource = ChangeAlongZSource.SourcePlane; var resultsAo = CutGeometryUtils.TryCut(originalPoly, cutLine, zSource); IntersectionUtils.UseCustomIntersect = true; var resultsGeom = CutGeometryUtils.TryCut(originalPoly, cutLine, zSource); Assert.NotNull(resultsAo); Assert.NotNull(resultsGeom); EnsureCutResult(resultsAo, originalPoly, plane, 3); EnsureCutResult(resultsGeom, originalPoly, plane, 3); // NOTE: The results have different start/end points, therefore GeometryUtils.AreEqual is false Assert.True(GeometryUtils.AreEqualInXY(resultsAo[0], resultsGeom[0])); Assert.True(GeometryUtils.AreEqualInXY(resultsAo[1], resultsGeom[1])); Assert.AreEqual(0, IntersectionUtils.GetZOnlyDifferenceLines( (IPolycurve)resultsAo[0], (IPolycurve)resultsGeom[0], 0.001) .Length); Assert.AreEqual(0, IntersectionUtils.GetZOnlyDifferenceLines( (IPolycurve)resultsAo[1], (IPolycurve)resultsGeom[1], 0.001) .Length); } finally { IntersectionUtils.UseCustomIntersect = customIntersectOrig; } }
public void CannotCutMultipatchWithTriangleStrip() { // To support triangles, triangle fans, etc.: // Consider implementing a completely different approach: // Go through points, determine for each point if it is on the left or right side of the cut line (above or below for vertical surfaces) // If the side changes, use intersection point to finish the strip on the one side and to start the strip on the other. ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95); object missing = Type.Missing; IMultiPatch multiPatch = new MultiPatchClass(); IPointCollection newStrip = new TriangleStripClass(); newStrip.AddPoint(GeometryFactory.CreatePoint(2600000, 1200000, 500), ref missing, ref missing); newStrip.AddPoint(GeometryFactory.CreatePoint(2600002, 1200000, 550), ref missing, ref missing); newStrip.AddPoint(GeometryFactory.CreatePoint(2600002, 1200002, 550), ref missing, ref missing); ((IGeometryCollection)multiPatch).AddGeometry( (IGeometry)newStrip, ref missing, ref missing); multiPatch.SpatialReference = lv95; GeometryUtils.MakeZAware(multiPatch); IPolyline cutLine = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(2600000, 1200001), GeometryFactory.CreatePoint(2600002, 1200001)); cutLine.SpatialReference = lv95; IFeature mockFeature = TestUtils.CreateMockFeature(multiPatch); var cutter = new FeatureCutter(new[] { mockFeature }); Exception assertionException = null; try { cutter.Cut(cutLine); } catch (Exception e) { assertionException = e; } Assert.NotNull(assertionException); // Once it is implemented: //IList<IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature]; //Assert.AreEqual(2, results.Count); //double areaSum = 0; //var partCount = 0; //foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature]) //{ // Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result)); // areaSum += // GeometryUtils.GetParts((IGeometryCollection)result) // .Sum(part => ((IArea)part).Area); // partCount += GeometryUtils.GetParts((IGeometryCollection)result).Count(); //} //Assert.AreEqual(2, partCount); }
public void CanHandleCachedPointCount() { IFeatureClass featureClass = CreatePolylineFeatureClass( "CanHandleCachedPointCount", 0.01); const double x = 2600000; const double y = 1200000; // Create features IFeature in4Tiles = featureClass.CreateFeature(); in4Tiles.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(x, y), GeometryFactory.CreatePoint(x + 1000, y + 800)); in4Tiles.Store(); IFeature inTiles_00_01 = featureClass.CreateFeature(); inTiles_00_01.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(x + 100, y + 100), GeometryFactory.CreatePoint(x + 800, y + 200)); inTiles_00_01.Store(); IFeature inTiles_00_10 = featureClass.CreateFeature(); inTiles_00_10.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(x + 100, y + 100), GeometryFactory.CreatePoint(x + 200, y + 200), GeometryFactory.CreatePoint(x + 200, y + 300), GeometryFactory.CreatePoint(x + 100, y + 400), GeometryFactory.CreatePoint(x + 100, y + 500), GeometryFactory.CreatePoint(x + 200, y + 600), GeometryFactory.CreatePoint(x + 200, y + 700), GeometryFactory.CreatePoint(x + 300, y + 800)); inTiles_00_10.Store(); IFeature inTiles_01_11 = featureClass.CreateFeature(); inTiles_01_11.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(x + 800, y + 100), GeometryFactory.CreatePoint(x + 800, y + 500), GeometryFactory.CreatePoint(x + 900, y + 1400)); inTiles_01_11.Store(); var helper = new CanHandleCachedPointCountHelper(); var test = new VerifyingContainerTest((ITable)featureClass) { OnExecuteCore = helper.HandleRows, OnCompleteTile = helper.HandleTiles }; test.SetSearchDistance(10); // Unlimited Cache var container1 = new TestContainer.TestContainer { TileSize = 600, MaxCachedPointCount = -1 }; // Assert.IsTrue(container1.MaxCachedPointCount < 0); helper.Reset(); helper.Container = container1; helper.ExpectedCacheCount = new[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; container1.AddTest(test); container1.Execute(GeometryFactory.CreateEnvelope(x, y, x + 1500, y + 1500)); // Very large Cache var container2 = new TestContainer.TestContainer { MaxCachedPointCount = int.MaxValue, TileSize = 600 }; helper.Reset(); helper.Container = container2; helper.ExpectedCacheCount = new[] { 0, 0, 8, 13, 3, 0, 3, 3, 0, 0 }; container2.AddTest(test); container2.Execute(GeometryFactory.CreateEnvelope(x, y, x + 1500, y + 1500)); // small feature Cache var container3 = new TestContainer.TestContainer { MaxCachedPointCount = 10, TileSize = 600 }; helper.Reset(); helper.Container = container3; helper.ExpectedCacheCount = new[] { 0, 0, 8, 5, 3, 0, 3, 3, 0, 0 }; // in the 5. tile, feature 'inTiles_01_11' with 3 points is used and hence not part of the cache container3.AddTest(test); container3.Execute(GeometryFactory.CreateEnvelope(x, y, x + 1500, y + 1500)); // very small feature Cache var container4 = new TestContainer.TestContainer { MaxCachedPointCount = 4, TileSize = 600 }; helper.Reset(); helper.Container = container4; helper.ExpectedCacheCount = new[] { 0, 0, 0, 2, 0, 0, 3, 3, 0, 0 }; // in the 3. tile, feature 'inTiles_01_11' with 3 points gets unloaded because of cache limitation // in the 5. tile, feature 'inTiles_01_11' gets loaded again, so that in the 6. and 7. tile it is cached container4.AddTest(test); container4.Execute(GeometryFactory.CreateEnvelope(x, y, x + 1500, y + 1500)); // no feature Cache var container5 = new TestContainer.TestContainer { MaxCachedPointCount = 0, TileSize = 600 }; helper.Reset(); helper.Container = container5; helper.ExpectedCacheCount = new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; container5.AddTest(test); container5.Execute(GeometryFactory.CreateEnvelope(x, y, x + 1500, y + 1500)); }