protected override byte[] Write(Geometry geom) { var writer = new GeoPackageGeoWriter { HandleOrdinates = Ordinates }; return(writer.Write(geom)); }
public virtual void New_pointZ_should_be_written() { var coord = new Coordinate(11.11, 22.22, 33.33); var point = GeometryFactory.Default.CreatePoint(coord); DoTest(conn => { using (var cmd = conn.CreateCommand()) { const string sql = @" DELETE FROM [sample_feature_table_z]; INSERT INTO [sample_feature_table_z] ([id], [geometry]) VALUES (1, @pbytes);"; cmd.CommandText = sql; var writer = new GeoPackageGeoWriter { HandleOrdinates = Ordinates.XYZ }; byte[] bytes = writer.Write(point); cmd.Parameters.AddWithValue("pbytes", bytes); int ret = cmd.ExecuteNonQuery(); Assert.AreEqual(1, ret); } using (var cmd = conn.CreateCommand()) { const string sql = @" SELECT geometry ,ST_Is3D(geometry) ,ST_IsMeasured(geometry) ,ST_AsText(GeomFromGPB(geometry)) FROM [sample_feature_table_z] WHERE [id] = 1;"; cmd.CommandText = sql; using (var rdr = cmd.ExecuteReader()) { Assert.IsTrue(rdr.Read()); byte[] blob = rdr.GetFieldValue <byte[]>(0); var reader = new GeoPackageGeoReader { HandleOrdinates = Ordinates.XYZ }; var geom = reader.Read(blob); Assert.AreEqual(point, geom); Assert.AreEqual(point.AsBinary(), geom.AsBinary()); Assert.IsTrue(rdr.GetBoolean(1)); Assert.IsFalse(rdr.GetBoolean(2)); string wkt = rdr.GetString(3); Assert.IsFalse(string.IsNullOrEmpty(wkt)); Assert.AreEqual("POINT Z(11.11 22.22 33.33)", wkt); } } }); }
public virtual void Srid_should_be_read_only_if_configured() { var coord = new Coordinate(11.11, 22.22); var point = GeometryFactory.Default.CreatePoint(coord); point.SRID = 3004; DoTest(conn => { using (var cmd = conn.CreateCommand()) { const string sql = @" DELETE FROM [sample_feature_table]; INSERT INTO [sample_feature_table] ([id], [geometry]) VALUES (1, @pbytes);"; cmd.CommandText = sql; var writer = new GeoPackageGeoWriter { HandleOrdinates = Ordinates.XY }; Assert.IsTrue(writer.HandleSRID); byte[] bytes = writer.Write(point); cmd.Parameters.AddWithValue("pbytes", bytes); int ret = cmd.ExecuteNonQuery(); Assert.AreEqual(1, ret); } using (var cmd = conn.CreateCommand()) { const string sql = @" SELECT geometry ,ST_Is3D(geometry) ,ST_IsMeasured(geometry) ,ST_AsText(GeomFromGPB(geometry)) FROM [sample_feature_table] WHERE [id] = 1;"; cmd.CommandText = sql; using (var rdr = cmd.ExecuteReader()) { Assert.IsTrue(rdr.Read()); byte[] blob = rdr.GetFieldValue <byte[]>(0); var reader = new GeoPackageGeoReader { HandleOrdinates = Ordinates.XY, HandleSRID = true }; var geom = reader.Read(blob); Assert.AreEqual(point, geom); Assert.AreEqual(point.SRID, geom.SRID); } } }); }
public virtual void New_pointZM_should_be_written() { var sequenceFactory = new DotSpatialAffineCoordinateSequenceFactory(Ordinates.XYZM); var coordinateSequence = sequenceFactory.Create( new[] { 11.11, 22.22 }, new[] { 33.33 }, new[] { 44.44 }); var factory = new GeometryFactory(sequenceFactory); var point = factory.CreatePoint(coordinateSequence); Assert.AreEqual(33.33, point.Z); Assert.AreEqual(44.44, point.M); DoTest(conn => { using (var cmd = conn.CreateCommand()) { const string sql = @" DELETE FROM [sample_feature_table_zm]; INSERT INTO [sample_feature_table_zm] ([id], [geometry]) VALUES (1, @pbytes);"; cmd.CommandText = sql; var writer = new GeoPackageGeoWriter { HandleOrdinates = Ordinates.XYZM }; byte[] bytes = writer.Write(point); cmd.Parameters.AddWithValue("pbytes", bytes); int ret = cmd.ExecuteNonQuery(); Assert.AreEqual(1, ret); } using (var cmd = conn.CreateCommand()) { const string sql = @" SELECT geometry ,ST_Is3D(geometry) ,ST_IsMeasured(geometry) ,ST_AsText(GeomFromGPB(geometry)) FROM [sample_feature_table_zm] WHERE [id] = 1;"; cmd.CommandText = sql; using (var rdr = cmd.ExecuteReader()) { Assert.IsTrue(rdr.Read()); byte[] blob = rdr.GetFieldValue <byte[]>(0); var reader = new GeoPackageGeoReader(sequenceFactory, new PrecisionModel(PrecisionModels.Floating)); var geom = reader.Read(blob); Assert.AreEqual(point, geom); Assert.AreEqual(point.AsBinary(), geom.AsBinary()); Assert.IsTrue(rdr.GetBoolean(1)); Assert.IsTrue(rdr.GetBoolean(2)); string wkt = rdr.GetString(3); Assert.IsFalse(string.IsNullOrEmpty(wkt)); Assert.AreEqual("POINT ZM(11.11 22.22 33.33 44.44)", wkt); } } }); }