public override object CreateProviderValue(DbGeometryWellKnownValue wellKnownValue) { CheckParameterNotNull("wellKnownValue", wellKnownValue); if (wellKnownValue.WellKnownText != null) { return(InvokeStaticFunction( SqlTypes.SqlGeometryType, "STGeomFromText", SqlTypes.SqlCharsFromString(wellKnownValue.WellKnownText), wellKnownValue.CoordinateSystemId)); } else if (wellKnownValue.WellKnownBinary != null) { return(InvokeStaticFunction( SqlTypes.SqlGeometryType, "STGeomFromWKB", SqlTypes.SqlBytesFromByteArray(wellKnownValue.WellKnownBinary), wellKnownValue.CoordinateSystemId)); } else { throw new ArgumentException("wellKnownValue"); } }
public void Verify_DbGeometry_CreateProviderValue_WKB_method() { var geometryWellKnownValue = new DbGeometryWellKnownValue() { CoordinateSystemId = DefaultCoordinateSystemId, WellKnownBinary = PointWKB, WellKnownText = null }; dynamic providerValue = spatialServices.CreateProviderValue(geometryWellKnownValue); Assert.Equal(PointWKT, providerValue.ToString()); }
/// <summary> /// Get sql geometry object from well known text /// </summary> /// <param name="wkt">Well known text representation of the value</param> /// <param name="srid">The identifier associated with the coordinate system.</param> /// <returns></returns> public override object GetSqlGeometry(string wkt, int srid) { #if EF6 var geo = new DbGeometryWellKnownValue { WellKnownText = wkt, CoordinateSystemId = srid }; return(DbSpatialServices.Default.CreateProviderValue(geo)); #endif #if EF5 return(DbGeometry.FromText(wkt, srid)); #endif }
public override DbGeometryWellKnownValue CreateWellKnownValue(DbGeometry geometryValue) { geometryValue.CheckNull("geometryValue"); var spatialValue = geometryValue.AsSpatialValue(); DbGeometryWellKnownValue result = CreateWellKnownValue(spatialValue, () => SpatialExceptions.CouldNotCreateWellKnownGeometryValueNoSrid("geometryValue"), () => SpatialExceptions.CouldNotCreateWellKnownGeometryValueNoWkbOrWkt("geometryValue"), (srid, wkb, wkt) => new DbGeometryWellKnownValue() { CoordinateSystemId = srid, WellKnownBinary = wkb, WellKnownText = wkt }); return(result); }
public override object CreateProviderValue(DbGeometryWellKnownValue wellKnownValue) { if (wellKnownValue == null) { throw new ArgumentNullException("wellKnownValue"); } if (wellKnownValue.WellKnownText != null) { var mysqlGeometry = new MySqlGeometry(true); MySqlGeometry.TryParse(wellKnownValue.WellKnownText.ToString(), out mysqlGeometry); return(mysqlGeometry); } else if (wellKnownValue.WellKnownBinary != null) { var mysqlGeometry = new MySqlGeometry(MySqlDbType.Geometry, wellKnownValue.WellKnownBinary); return(mysqlGeometry); } return(null); }
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(); } }
public override object CreateProviderValue(DbGeometryWellKnownValue wellKnownValue) { wellKnownValue.CheckNull("wellKnownValue"); object result = null; if (wellKnownValue.WellKnownText != null) { result = this.SqlTypes.SqlTypesGeometryFromText(wellKnownValue.WellKnownText, wellKnownValue.CoordinateSystemId); } else if (wellKnownValue.WellKnownBinary != null) { result = this.SqlTypes.SqlTypesGeometryFromBinary(wellKnownValue.WellKnownBinary, wellKnownValue.CoordinateSystemId); } else { throw SpatialExceptions.WellKnownGeometryValueNotValid("wellKnownValue"); } return(result); }
public override object CreateProviderValue(DbGeometryWellKnownValue wellKnownValue) { if (wellKnownValue == null) throw new ArgumentNullException("wellKnownValue"); if (wellKnownValue.WellKnownText != null) { var mysqlGeometry = new MySqlGeometry(true); MySqlGeometry.TryParse(wellKnownValue.WellKnownText.ToString(), out mysqlGeometry); return mysqlGeometry; } else if (wellKnownValue.WellKnownBinary != null) { var mysqlGeometry = new MySqlGeometry(MySqlDbType.Geometry, wellKnownValue.WellKnownBinary); return mysqlGeometry; } return null; }