public void CanWriteAndReadMultiLinestring() { var points1 = new List <Pnt3D> { new Pnt3D(0, 0, 9), new Pnt3D(0, 100, 8), new Pnt3D(100, 100, 5) }; var points2 = new List <Pnt3D>(); points2.Add(new Pnt3D(140, -10, 0)); points2.Add(new Pnt3D(140, 30, 23)); points2.Add(new Pnt3D(300, 30, 56)); points2.Add(new Pnt3D(300, -10, 0)); MultiPolycurve polycurve = new MultiPolycurve(new[] { new Linestring(points1), new Linestring(points2) }); WkbGeomWriter writer = new WkbGeomWriter(); byte[] bytes = writer.WriteMultiLinestring(polycurve); WkbGeomReader reader = new WkbGeomReader(); MultiPolycurve deserialized = reader.ReadMultiPolycurve(new MemoryStream(bytes)); Assert.IsTrue(deserialized.Equals(polycurve)); }
public void CanReadWriteSinglePartPolylineXy() { var points = new WKSPointZ[4]; points[0] = new WKSPointZ { X = 2600000, Y = 1200000, Z = double.NaN }; points[1] = new WKSPointZ { X = 2600030, Y = 1200020, Z = double.NaN }; points[2] = new WKSPointZ { X = 2600020, Y = 1200030, Z = double.NaN }; points[3] = new WKSPointZ { X = 2600040, Y = 1200040, Z = double.NaN }; IPolyline polyline = GeometryFactory.CreatePolyline(points, null); GeometryUtils.MakeNonZAware(polyline); GeometryUtils.Simplify(polyline); WkbGeometryWriter writer = new WkbGeometryWriter(); byte[] wkb = writer.WritePolyline(polyline); // ArcObjects byte[] arcObjectsWkb = GeometryUtils.ToWkb(polyline); Assert.AreEqual(wkb, arcObjectsWkb); // Wkx byte[] wkx = ToChristianSchwarzWkb(ToWkxLineString(points, Ordinates.Xy)); Assert.AreEqual(wkx, wkb); // Bonus test: Geom WkbGeomWriter geomWriter = new WkbGeomWriter(); MultiPolycurve multiPlycurve = GeometryConversionUtils.CreateMultiPolycurve(polyline); byte[] wkbGeom = geomWriter.WriteMultiLinestring(multiPlycurve, Ordinates.Xy); Assert.AreEqual(wkb, wkbGeom); WkbGeometryReader reader = new WkbGeometryReader(); IPolyline restored = reader.ReadPolyline(new MemoryStream(wkb)); Assert.IsTrue(GeometryUtils.AreEqual(polyline, restored)); // Geom WkbGeomReader geomReader = new WkbGeomReader(); Assert.IsTrue( multiPlycurve.Equals(geomReader.ReadMultiPolycurve(new MemoryStream(wkbGeom)))); }
public void CanReadWriteMultiPartPolylineXyz() { // The spatial reference is important to avoid small differences in // coordinates (snap to spatial reference!) ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95); var points1 = new WKSPointZ[4]; points1[0] = new WKSPointZ { X = 2600000, Y = 1200000, Z = 456 }; points1[1] = new WKSPointZ { X = 2600030, Y = 1200020, Z = 457 }; points1[2] = new WKSPointZ { X = 2600020, Y = 1200030, Z = 459 }; points1[3] = new WKSPointZ { X = 2600040, Y = 1200040, Z = 416 }; IPolyline polyline1 = GeometryFactory.CreatePolyline(points1, sr); var points2 = new WKSPointZ[4]; points2[0] = new WKSPointZ { X = 2610000, Y = 1200000, Z = 656 }; points2[1] = new WKSPointZ { X = 2610030, Y = 1200020, Z = 657 }; points2[2] = new WKSPointZ { X = 2610020, Y = 1200030, Z = 659 }; points2[3] = new WKSPointZ { X = 2610040, Y = 1200040, Z = 616 }; IPolyline polyline2 = GeometryFactory.CreatePolyline(points2, sr); IPolyline polyline = (IPolyline)GeometryUtils.Union(polyline1, polyline2); GeometryUtils.Simplify(polyline); WkbGeometryWriter writer = new WkbGeometryWriter(); byte[] wkb = writer.WritePolyline(polyline); // Wkx var ordinates = Ordinates.Xyz; MultiLineString multiLineString = new MultiLineString( new List <LineString> { ToWkxLineString(points1, ordinates), ToWkxLineString(points2, ordinates) }); byte[] wkx = ToChristianSchwarzWkb(multiLineString); Assert.AreEqual(wkx, wkb); // Bonus test: Geom WkbGeomWriter geomWriter = new WkbGeomWriter(); MultiPolycurve multiPlycurve = GeometryConversionUtils.CreateMultiPolycurve(polyline); byte[] wkbGeom = geomWriter.WriteMultiLinestring(multiPlycurve, ordinates); Assert.AreEqual(wkb, wkbGeom); WkbGeometryReader reader = new WkbGeometryReader(); IPolyline restored = reader.ReadPolyline(new MemoryStream(wkb)); Assert.IsTrue(GeometryUtils.AreEqual(polyline, restored)); // Geom: WkbGeomReader geomReader = new WkbGeomReader(); Assert.IsTrue( multiPlycurve.Equals(geomReader.ReadMultiPolycurve(new MemoryStream(wkbGeom)))); }