public void CanFetchGeometryAsBinary() { executeSQL("DROP TABLE IF EXISTS Test"); executeSQL("CREATE TABLE Test (v Geometry NOT NULL)"); MySqlGeometry v = new MySqlGeometry(47.37, -122.21); var par = new MySqlParameter("?v", MySqlDbType.Geometry); par.Value = v; MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES (?v)", Connection); cmd.Parameters.Add(par); cmd.ExecuteNonQuery(); if (Connection.driver.Version.isAtLeast(8, 0, 1)) { cmd.CommandText = "SELECT ST_AsBinary(v) FROM Test"; } else { cmd.CommandText = "SELECT AsBinary(v) FROM Test"; } using (MySqlDataReader reader = cmd.ExecuteReader()) { reader.Read(); var val = reader.GetValue(0) as Byte[]; var MyGeometry = new MySqlGeometry(MySqlDbType.Geometry, val); Assert.Equal("POINT(47.37 -122.21)", MyGeometry.ToString()); } }
public void CanTryParseGeometryValueStringWithSRIDValue() { var mysqlGeometryResult = new MySqlGeometry(0, 0); MySqlGeometry.TryParse("SRID=101;POINT (47.37 -122.21)", out mysqlGeometryResult); Assert.Equal("SRID=101;POINT(47.37 -122.21)", mysqlGeometryResult.ToString()); }
public void CanTryParseGeometryValueString() { MySqlGeometry v = new MySqlGeometry(0, 0); MySqlGeometry.TryParse("POINT (47.37 -122.21)", out v); Assert.Equal("POINT(47.37 -122.21)", v.ToString()); }
public void CanGetToStringFromMySqlGeometry() { MySqlGeometry v = new MySqlGeometry(47.37, -122.21); var valToString = v.ToString(); Assert.AreEqual("POINT(47.37 -122.21)", valToString); }
public void CanCreateMySqlGeometryFromEmptyGeometryCollection() { var bytes = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; MySqlGeometry v = new MySqlGeometry(MySqlDbType.Geometry, bytes); Assert.Equal("POINT(3.45845952088873E-323 0)", v.ToString()); }
public void CanFetchGeometryAsBinary() { if (st.version.Major < 5) { return; } st.execSQL("DROP TABLE IF EXISTS Test"); st.execSQL("CREATE TABLE Test (v Geometry NOT NULL)"); MySqlGeometry v = new MySqlGeometry(47.37, -122.21); var par = new MySqlParameter("?v", MySqlDbType.Geometry); par.Value = v; MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES (?v)", st.conn); cmd.Parameters.Add(par); cmd.ExecuteNonQuery(); cmd.CommandText = "SELECT AsBinary(v) FROM Test"; using (MySqlDataReader reader = cmd.ExecuteReader()) { reader.Read(); var val = reader.GetValue(0) as Byte[]; var MyGeometry = new MySqlGeometry(MySqlDbType.Geometry, val); Assert.Equal("POINT(47.37 -122.21)", MyGeometry.ToString()); } }
public override string AsText(DbGeometry geometryValue) { if (geometryValue == null) { throw new ArgumentNullException("geometryValue"); } var providerValue = new MySqlGeometry(); MySqlGeometry.TryParse(geometryValue.ProviderValue.ToString(), out providerValue); return(providerValue.ToString()); }
public void CanUseCreateProviderValueFunction() { using (DistribuitorsContext context = new DistribuitorsContext()) { context.Database.Delete(); context.Database.Create(); context.Distributors.Add(new Distributor() { Name = "Graphic Design Institute", point = DbGeometry.FromText("POINT(-122.336106 47.605049)"), }); context.SaveChanges(); var point = (from u in context.Distributors select u.point).First(); var geometryWellKnownValueWKT = new DbGeometryWellKnownValue() { CoordinateSystemId = 0, WellKnownBinary = null, WellKnownText = "POINT(1 2)" }; MySqlGeometry providerValue = (MySqlGeometry)spatialServices.CreateProviderValue(geometryWellKnownValueWKT); Assert.AreEqual("POINT(1 2)", providerValue.ToString()); var geometryWellKnownValueWKB = new DbGeometryWellKnownValue() { CoordinateSystemId = 0, WellKnownBinary = providerValue.Value, WellKnownText = null }; MySqlGeometry providerValue_2 = (MySqlGeometry)spatialServices.CreateProviderValue(geometryWellKnownValueWKB); Assert.AreEqual("POINT(1 2)", providerValue_2.ToString()); context.Database.Delete(); } }