public void CanReadWriteSingleRingPolygonXyz() { IPolygon poly = GeometryFactory.CreatePolygon(2600000, 1200000, 2601000, 1201000, 400); WkbGeometryWriter writer = new WkbGeometryWriter(); byte[] wkb = writer.WritePolygon(poly); // Wkx var ordinates = Ordinates.Xyz; LinearRing wkxLinearRing = ToWkxLinearRing(GeometryUtils.GetWKSPointZs(poly), ordinates); byte[] wkx = ToChristianSchwarzWkb(ToWkxPolygon(wkxLinearRing)); Assert.AreEqual(wkx, wkb); // Bonus test: Geom WkbGeomWriter geomWriter = new WkbGeomWriter(); RingGroup ringGroup = GeometryConversionUtils.CreateRingGroup(poly); byte[] wkbGeom = geomWriter.WritePolygon(ringGroup, ordinates); Assert.AreEqual(wkb, wkbGeom); WkbGeometryReader reader = new WkbGeometryReader(); IPolygon restored = reader.ReadPolygon(new MemoryStream(wkb)); Assert.IsTrue(GeometryUtils.AreEqual(poly, restored)); WkbGeomReader geomReader = new WkbGeomReader(); Assert.IsTrue( ringGroup.Equals(geomReader.ReadPolygon(new MemoryStream(wkbGeom)))); }
public void CanReadWriteSingleExteriorRingWithIslandsPolygonXyz() { ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95); IPolygon outerRing = GeometryFactory.CreatePolygon(2600000, 1200000, 2601000, 1201000, 432); outerRing.SpatialReference = sr; IPolygon innerRing = GeometryFactory.CreatePolygon(2600100, 1200100, 2600200, 1200200, 321); innerRing.SpatialReference = sr; IPolygon polyWithHole = (IPolygon)IntersectionUtils.Difference(outerRing, innerRing); WkbGeometryWriter writer = new WkbGeometryWriter(); byte[] wkb = writer.WritePolygon(polyWithHole); // Wkx var ordinates = Ordinates.Xyz; IGeometry exteriorRing = GeometryUtils.GetParts(polyWithHole).First(); IGeometry interiorRing = GeometryUtils.GetPaths(polyWithHole).Last(); LinearRing wkxOuterRing = ToWkxLinearRing(exteriorRing, ordinates); LinearRing wkxInnerRing = ToWkxLinearRing(interiorRing, ordinates); byte[] wkx = ToChristianSchwarzWkb(ToWkxPolygon(wkxOuterRing, new[] { wkxInnerRing })); Assert.AreEqual(wkx, wkb); // Bonus test: Geom WkbGeomWriter geomWriter = new WkbGeomWriter(); RingGroup ringGroup = GeometryConversionUtils.CreateRingGroup(polyWithHole); byte[] wkbGeom = geomWriter.WritePolygon(ringGroup, ordinates); Assert.AreEqual(wkb, wkbGeom); WkbGeometryReader reader = new WkbGeometryReader(); IPolygon restored = reader.ReadPolygon(new MemoryStream(wkb)); Assert.IsTrue(GeometryUtils.AreEqual(polyWithHole, restored)); // Geom: WkbGeomReader geomReader = new WkbGeomReader(); Assert.IsTrue( ringGroup.Equals(geomReader.ReadPolygon(new MemoryStream(wkbGeom)))); }
private static Dictionary <RingGroup, List <RingGroup> > PrepareSplitPartsDictionary( IList <IGeometry> cutFootprintParts) { var splitPartsByFootprintPart = new Dictionary <RingGroup, List <RingGroup> >(); foreach (IGeometry cutFootprintPart in cutFootprintParts) { var footprintPartGeom = GeometryConversionUtils.CreateRingGroup((IPolygon)cutFootprintPart); splitPartsByFootprintPart.Add(footprintPartGeom, new List <RingGroup>()); } return(splitPartsByFootprintPart); }
private static void CutAndAssignToFootprintParts( [NotNull] GeometryPart multipatchPart, [NotNull] IPolyline cutLine, [NotNull] IDictionary <RingGroup, List <RingGroup> > splitPartsByFootprintPart, ChangeAlongZSource zSource) { double tolerance = GeometryUtils.GetXyTolerance(multipatchPart.FirstGeometry); double zTolerance = GeometryUtils.GetZTolerance(multipatchPart.FirstGeometry); RingGroup ringGroup = GeometryConversionUtils.CreateRingGroup(multipatchPart); int pointId; if (GeometryUtils.HasUniqueVertexId( Assert.NotNull(multipatchPart.MainOuterRing), out pointId)) { ringGroup.Id = pointId; } bool inverted = ringGroup.ClockwiseOriented == false; if (inverted) { ringGroup.ReverseOrientation(); } IList <RingGroup> cutRingGroups = CutRingGroupPlanar(ringGroup, cutLine, tolerance, zSource, zTolerance); AssignResultsToFootprintParts(cutRingGroups, splitPartsByFootprintPart, tolerance); if (inverted) { foreach (RingGroup cutRingGroup in cutRingGroups) { cutRingGroup.ReverseOrientation(); } } }
private static IList <IList <RingGroup> > TryCutConnectedComponents( IPolygon inputPolygon, IPolyline cutPolyline, ChangeAlongZSource zSource) { double tolerance = GeometryUtils.GetXyTolerance(inputPolygon); double zTolerance = GeometryUtils.GetZTolerance(inputPolygon); var result = new List <IList <RingGroup> >(); foreach (IPolygon connectedComponent in GeometryUtils.GetConnectedComponents( inputPolygon)) { RingGroup ringGroup = GeometryConversionUtils.CreateRingGroup(connectedComponent); IList <RingGroup> cutRingGroups = CutRingGroupPlanar( ringGroup, cutPolyline, tolerance, zSource, zTolerance); result.Add(cutRingGroups); } return(result); }