public void CanReadWriteMultipointXyz() { var points = new WKSPointZ[4]; points[0] = new WKSPointZ { X = 2600000, Y = 1200000, Z = 456 }; points[1] = new WKSPointZ { X = 2600030, Y = 1200020, Z = 457 }; points[2] = new WKSPointZ { X = 2600020, Y = 1200030, Z = 459 }; points[3] = new WKSPointZ { X = 2600010, Y = 1200010, Z = 416 }; ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95); IMultipoint multipoint = GeometryFactory.CreateMultipoint(points, sr); WkbGeometryWriter writer = new WkbGeometryWriter(); byte[] wkb = writer.WriteMultipoint(multipoint); // Wkx byte[] wkx = ToChristianSchwarzWkb(ToWkxMultipoint(points, Ordinates.Xyz)); Assert.AreEqual(wkx, wkb); // Bonus test: Geom WkbGeomWriter geomWriter = new WkbGeomWriter(); Multipoint <IPnt> multipnt = GeometryConversionUtils.CreateMultipoint(multipoint); byte[] wkbGeom = geomWriter.WriteMultipoint(multipnt, Ordinates.Xyz); Assert.AreEqual(wkb, wkbGeom); WkbGeometryReader reader = new WkbGeometryReader(); IMultipoint restored = reader.ReadMultipoint(new MemoryStream(wkb)); Assert.IsTrue(GeometryUtils.AreEqual(multipoint, restored)); // Geom WkbGeomReader geomReader = new WkbGeomReader(); Multipoint <IPnt> deserializedPnts = geomReader.ReadMultiPoint(new MemoryStream(wkbGeom)); Assert.IsTrue(multipnt.Equals(deserializedPnts)); }
public static double?Distance(this Multipoint multipoint1, Multipoint multipoint2) { if (Null(multipoint1, multipoint1.points, multipoint2, multipoint2.points)) { return(null); } if (multipoint1.Equals(multipoint2)) { return(0); } return(multipoint1.points !.SelectMany(p1 => multipoint2.points !.Select(p2 => Length(p1, p2))).Min()); }
public void CanWriteMultiPoint() { Pnt3D point1 = new Pnt3D(2600001.123, 1200000.987, 432.1); Pnt3D point2 = new Pnt3D(2600002.234, 1200002.876, 321.98); var multipoint = new Multipoint <IPnt>(new[] { point1, point2 }); WkbGeomWriter writer = new WkbGeomWriter(); byte[] bytes = writer.WriteMultipoint(multipoint); WkbGeomReader reader = new WkbGeomReader(); Multipoint <IPnt> deserizalized = reader.ReadMultiPoint(new MemoryStream(bytes)); Assert.AreEqual(multipoint.PointCount, deserizalized.PointCount); Assert.IsTrue(deserizalized.Equals(multipoint)); }