private static string approach_one(string polygonWkt) { var result = ""; try { // Create a DbGeography instance from a WKT string DbGeography polygon = DbGeography.FromText(polygonWkt); // If the polygon area is larger than an earth hemisphere (510 Trillion m2 / 2), we know it needs to be fixed if (polygon.Area.HasValue && polygon.Area.Value > 255000000000000L) { // Convert our DbGeography polygon into a SqlGeography object for the ReorientObject() call var sqlPolygon = SqlGeography.STGeomFromWKB(new System.Data.SqlTypes.SqlBytes(polygon.AsBinary()), 4326); // ReorientObject will flip the polygon so the outside becomes the inside sqlPolygon = sqlPolygon.ReorientObject(); // Convert the SqlGeography object back into a WKT string polygon = DbGeography.FromBinary(sqlPolygon.STAsBinary().Value); result = polygon.AsText(); } } catch (Exception ex) { result = string.Empty; } return(result); }
public static DbGeography ToDbGeography(this SqlGeography sqlGeography) { if (sqlGeography == null) { return(null); } return(DbGeography.FromBinary(sqlGeography.STAsBinary().Buffer, sqlGeography.STSrid.Value)); }
public static DbGeography ToDbGeography(this IGeometry self) { if (self == null) { return(null); } if (self.SRID != 4326) { throw new ArgumentException(); } return(DbGeography.FromBinary(self.AsBinary())); }
private DbGeography GetValueByIndex(int columnIndex, IDataReader dataReader) { byte[] dbBytes = null; int bufferLength = (int)dataReader.GetBytes(columnIndex, 0, null, 0, 0); // initialize it byte[] byteArray = new byte[bufferLength]; // fill it dataReader.GetBytes(columnIndex, 0, byteArray, 0, bufferLength); var sqlBytes = new SqlBytes(byteArray); //dbBytes = SqlGeography.Deserialize(sqlBytes).AsBinaryZM().Value; return(DbGeography.FromBinary(dbBytes)); }
public static bool IsOverlap(this DbGeography polygon1, DbGeography polygon2) { SqlGeography sqlPolygon1 = SqlGeography.STGeomFromWKB(new System.Data.SqlTypes.SqlBytes(polygon1.AsBinary()), DbGeography.DefaultCoordinateSystemId).MakeValid(); sqlPolygon1 = sqlPolygon1.ReorientObject(); polygon1 = DbGeography.FromBinary(sqlPolygon1.STAsBinary().Value); SqlGeography sqlPolygon2 = SqlGeography.STGeomFromWKB(new System.Data.SqlTypes.SqlBytes(polygon2.AsBinary()), DbGeography.DefaultCoordinateSystemId).MakeValid(); sqlPolygon2 = sqlPolygon2.ReorientObject(); polygon2 = DbGeography.FromBinary(sqlPolygon2.STAsBinary().Value); return(polygon1.Intersects(polygon2)); }
public async void SaveArea() { var json = await Request.Content.ReadAsStringAsync(); var telemetry = new Microsoft.ApplicationInsights.TelemetryClient(); telemetry.TrackEvent("STH", new Dictionary <string, string> { { "body", json.Replace(@"\", "").TrimStart('"').TrimEnd('"') } }); telemetry.Flush(); var dbGeo = JsonConvert.DeserializeObject <Polygon>(json.Replace(@"\", "").TrimStart('"').TrimEnd('"')).ToDbGeography(); var sqlGeography = MakePolygonValid(dbGeo); sqlGeography = sqlGeography.Reduce(1); var newPolygon = DbGeography.FromBinary(sqlGeography.STAsBinary().Value); using (var context = new PttContext()) { var intersectingAreas = context.CoveredAreas.Where(x => x.Geo.Intersects(newPolygon)).ToList(); var user = UserHelper.GetUser(context, RequestContext); if (newPolygon.Length != null) { user.Statistic.DistanceWalked += (double)newPolygon.Length; } foreach (var intersectingArea in intersectingAreas) { if (intersectingArea.User == user) { intersectingArea.Geo = intersectingArea.Geo.Difference(newPolygon); } } context.CoveredAreas.Add(new CoveredArea() { User = user, Geo = newPolygon }); context.SaveChanges(); } }
static void Test(string p_wkt) { try { var v_geo1 = DbGeography.FromText(p_wkt); var v_wkb1 = v_geo1.AsBinary(); var v_geo2 = Utils.GeometryFromWkb(v_wkb1); var v_wkb2 = Utils.GeometryToWkb(v_geo2); var v_geo3 = DbGeography.FromBinary(v_wkb2); var v_IsEqual = System.Data.Entity.Spatial.DbSpatialServices.Default.SpatialEquals(v_geo1, v_geo3); Console.WriteLine("passed: " + p_wkt); } catch { Console.WriteLine("failed: " + p_wkt); } }
public static bool IsInside(this DbGeography point, DbGeography polygon) { //DbGeography point = DbGeography.FromText(string.Format("POINT({1} {0})", latitude.ToString().Replace(',', '.'), longitude.ToString().Replace(',', '.')), DbGeography.DefaultCoordinateSystemId); // If the polygon area is larger than an earth hemisphere (510 Trillion m2 / 2), we know it needs to be fixed /*if (polygon.Area.HasValue && polygon.Area.Value > 255000000000000L) * { * * }*/ SqlGeography sqlPolygon = SqlGeography.STGeomFromWKB(new System.Data.SqlTypes.SqlBytes(polygon.AsBinary()), DbGeography.DefaultCoordinateSystemId).MakeValid(); sqlPolygon = sqlPolygon.ReorientObject(); polygon = DbGeography.FromBinary(sqlPolygon.STAsBinary().Value); return(point.Intersects(polygon)); }
/// <summary> /// Create a <see cref="DbGeography"/> or <see cref="DbGeometry"/> from <paramref name="jsonObject"/>. /// </summary> /// <param name="jsonObject"> /// The JSON object. /// </param> /// <param name="objectType"> /// The object type. /// </param> /// <returns> /// The <see cref="DbGeography"/> or <see cref="DbGeometry"/> /// </returns> /// <exception cref="ArgumentException"> /// <paramref name="objectType"/> is not a <see cref="DbGeography"/> or <see cref="DbGeometry"/>. /// </exception> private static object CreateDbGeo(JObject jsonObject, Type objectType) { Func <Tuple <byte[], int>, object> returnValue; int defaultCoordinateSystemId; if (typeof(DbGeography).IsAssignableFrom(objectType)) { returnValue = x => (object)DbGeography.FromBinary(x.Item1, x.Item2); defaultCoordinateSystemId = DbGeography.DefaultCoordinateSystemId; } else if (typeof(DbGeometry).IsAssignableFrom(objectType)) { returnValue = x => (object)DbGeometry.FromBinary(x.Item1, x.Item2); defaultCoordinateSystemId = DbGeometry.DefaultCoordinateSystemId; } else { throw new ArgumentException(string.Format("Expected a DbGeography or DbGeometry objectType. Got {0}", objectType.CSharpName()), "objectType"); } return(jsonObject.Type == JTokenType.Null || jsonObject.Type == JTokenType.None ? null : returnValue(GetWellKnownBinary(jsonObject, defaultCoordinateSystemId))); }
/// <inheritdoc/> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { Func <Tuple <byte[], int>, object> returnValue; int defaultCoordinateSystemId; if (typeof(DbGeography).IsAssignableFrom(objectType)) { returnValue = x => (object)DbGeography.FromBinary(x.Item1, x.Item2); defaultCoordinateSystemId = DbGeography.DefaultCoordinateSystemId; } else if (typeof(DbGeometry).IsAssignableFrom(objectType)) { returnValue = x => (object)DbGeometry.FromBinary(x.Item1, x.Item2); defaultCoordinateSystemId = DbGeometry.DefaultCoordinateSystemId; } else { throw new ArgumentException(string.Format("Expected a DbGeography or DbGeometry objectType. Got {0}", objectType.FullName), "objectType"); } return(reader.TokenType == JsonToken.Null ? null : returnValue(GetWellKnownBinary(reader, defaultCoordinateSystemId))); }
private static IEnumerable <MethodInfo> GetSupportedMethods() { yield return(GetStaticMethod(() => DbGeography.FromText(default(string)))); yield return(GetStaticMethod(() => DbGeography.FromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeography.PointFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeography.LineFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeography.PolygonFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeography.MultiPointFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeography.MultiLineFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeography.MultiPolygonFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeography.GeographyCollectionFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeography.FromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeography.FromBinary(default(byte[])))); yield return(GetStaticMethod(() => DbGeography.PointFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeography.LineFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeography.PolygonFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeography.MultiPointFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeography.MultiLineFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeography.MultiPolygonFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeography.GeographyCollectionFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeography.FromGml(default(string)))); yield return(GetStaticMethod(() => DbGeography.FromGml(default(string), default(int)))); yield return(GetInstanceMethod((DbGeography geo) => geo.AsBinary())); yield return(GetInstanceMethod((DbGeography geo) => geo.AsGml())); yield return(GetInstanceMethod((DbGeography geo) => geo.AsText())); yield return(GetInstanceMethod((DbGeography geo) => geo.SpatialEquals(default(DbGeography)))); yield return(GetInstanceMethod((DbGeography geo) => geo.Disjoint(default(DbGeography)))); yield return(GetInstanceMethod((DbGeography geo) => geo.Intersects(default(DbGeography)))); yield return(GetInstanceMethod((DbGeography geo) => geo.Buffer(default(double)))); yield return(GetInstanceMethod((DbGeography geo) => geo.Distance(default(DbGeography)))); yield return(GetInstanceMethod((DbGeography geo) => geo.Intersection(default(DbGeography)))); yield return(GetInstanceMethod((DbGeography geo) => geo.Union(default(DbGeography)))); yield return(GetInstanceMethod((DbGeography geo) => geo.Difference(default(DbGeography)))); yield return(GetInstanceMethod((DbGeography geo) => geo.SymmetricDifference(default(DbGeography)))); yield return(GetInstanceMethod((DbGeography geo) => geo.ElementAt(default(int)))); yield return(GetInstanceMethod((DbGeography geo) => geo.PointAt(default(int)))); yield return(GetStaticMethod(() => DbGeometry.FromText(default(string)))); yield return(GetStaticMethod(() => DbGeometry.FromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeometry.PointFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeometry.LineFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeometry.PolygonFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeometry.MultiPointFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeometry.MultiLineFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeometry.MultiPolygonFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeometry.GeometryCollectionFromText(default(string), default(int)))); yield return(GetStaticMethod(() => DbGeometry.FromBinary(default(byte[])))); yield return(GetStaticMethod(() => DbGeometry.FromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeometry.PointFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeometry.LineFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeometry.PolygonFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeometry.MultiPointFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeometry.MultiLineFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeometry.MultiPolygonFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeometry.GeometryCollectionFromBinary(default(byte[]), default(int)))); yield return(GetStaticMethod(() => DbGeometry.FromGml(default(string)))); yield return(GetStaticMethod(() => DbGeometry.FromGml(default(string), default(int)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.AsBinary())); yield return(GetInstanceMethod((DbGeometry geo) => geo.AsGml())); yield return(GetInstanceMethod((DbGeometry geo) => geo.AsText())); yield return(GetInstanceMethod((DbGeometry geo) => geo.SpatialEquals(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Disjoint(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Intersects(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Touches(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Crosses(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Within(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Contains(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Overlaps(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Relate(default(DbGeometry), default(string)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Buffer(default(double)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Distance(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Intersection(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Union(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.Difference(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.SymmetricDifference(default(DbGeometry)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.ElementAt(default(int)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.PointAt(default(int)))); yield return(GetInstanceMethod((DbGeometry geo) => geo.InteriorRingAt(default(int)))); }
/// <summary> /// Create new instance of <see cref="ObjectMapper" />. /// </summary> public ObjectMapper() { var assemblyName = new AssemblyName("Dextrys_ILEmit_TypeMaps"); _moduleBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave) .DefineDynamicModule(assemblyName.Name, assemblyName.Name + ".dll", false); _converters = new ConverterCollection(this); _converters.Add(new PrimitiveConverter { Intrinsic = true }); _converters.Add(new ObjectToStringConverter { Intrinsic = true }); _converters.Add(new FromStringConverter { Intrinsic = true }); #region bool Converters // sbyte -> bool Converters.AddIntrinsic((sbyte source) => source != 0); // byte -> bool Converters.AddIntrinsic((byte source) => source != 0); // char -> bool Converters.AddIntrinsic((char source) => source != 0); // int -> bool Converters.AddIntrinsic((int source) => source != 0); // uint -> bool Converters.AddIntrinsic((uint source) => source != 0); // long -> bool Converters.AddIntrinsic((long source) => source != 0); // ulong -> bool Converters.AddIntrinsic((ulong source) => source != 0); // short -> bool Converters.AddIntrinsic((short source) => source != 0); // ushort -> bool Converters.AddIntrinsic((ushort source) => source != 0); // decimal -> bool Converters.AddIntrinsic((decimal source) => source != 0); // float -> bool Converters.AddIntrinsic((float source) => source != 0); // double -> bool Converters.AddIntrinsic((double source) => source != 0); // bool -> int Converters.AddIntrinsic((bool source) => (source ? 1 : 0)); // bool -> char Converters.AddIntrinsic((bool source) => source ? 'T' : 'F'); // bool -> byte Converters.AddIntrinsic((bool source) => (byte)(source ? 1 : 0)); // bool -> short Converters.AddIntrinsic((bool source) => (short)(source ? 1 : 0)); // bool -> ushort Converters.AddIntrinsic((bool source) => (ushort)(source ? 1 : 0)); // bool -> uint Converters.AddIntrinsic((bool source) => (uint)(source ? 1 : 0)); // bool -> long Converters.AddIntrinsic((bool source) => (long)(source ? 1 : 0)); // bool -> ulong Converters.AddIntrinsic((bool source) => (ulong)(source ? 1 : 0)); // bool -> decimal Converters.AddIntrinsic((bool source) => (decimal)(source ? 1 : 0)); // bool -> float Converters.AddIntrinsic((bool source) => (float)(source ? 1 : 0)); // bool -> double Converters.AddIntrinsic((bool source) => (double)(source ? 1 : 0)); // bool -> sbyte Converters.AddIntrinsic((bool source) => (sbyte)(source ? 1 : 0)); #endregion #region DateTime Converters // DateTime -> long Converters.AddIntrinsic((DateTime source) => source.Ticks); // DateTime -> ulong Converters.AddIntrinsic((DateTime source) => (ulong)source.Ticks); // sbyte -> DateTime Converters.AddIntrinsic((sbyte source) => new DateTime(source)); // byte -> DateTime Converters.AddIntrinsic((byte source) => new DateTime(source)); // char -> DateTime Converters.AddIntrinsic((char source) => new DateTime(source)); // int -> DateTime Converters.AddIntrinsic((int source) => new DateTime(source)); // uint -> DateTime Converters.AddIntrinsic((uint source) => new DateTime(source)); // long -> DateTime Converters.AddIntrinsic((long source) => new DateTime(source)); // ulong -> DateTime Converters.AddIntrinsic((ulong source) => new DateTime((long)source)); // short -> DateTime Converters.AddIntrinsic((short source) => new DateTime(source)); // ushort -> DateTime Converters.AddIntrinsic((ushort source) => new DateTime(source)); // decimal -> DateTime Converters.AddIntrinsic((decimal source) => new DateTime((long)source)); // float -> DateTime Converters.AddIntrinsic((float source) => new DateTime((long)source)); // double -> DateTime Converters.AddIntrinsic((double source) => new DateTime((long)source)); #endregion #region TimeSpan Converters // TimeSpan -> long Converters.AddIntrinsic((TimeSpan source) => source.Ticks); // TimeSpan -> ulong Converters.AddIntrinsic((TimeSpan source) => (ulong)source.Ticks); // sbyte -> TimeSpan Converters.AddIntrinsic((sbyte source) => new TimeSpan(source)); // byte -> TimeSpan Converters.AddIntrinsic((byte source) => new TimeSpan(source)); // char -> TimeSpan Converters.AddIntrinsic((char source) => new TimeSpan(source)); // int -> TimeSpan Converters.AddIntrinsic((int source) => new TimeSpan(source)); // uint -> TimeSpan Converters.AddIntrinsic((uint source) => new TimeSpan(source)); // long -> TimeSpan Converters.AddIntrinsic((long source) => new TimeSpan(source)); // ulong -> TimeSpan Converters.AddIntrinsic((ulong source) => new TimeSpan((long)source)); // short -> TimeSpan Converters.AddIntrinsic((short source) => new TimeSpan(source)); // ushort -> TimeSpan Converters.AddIntrinsic((ushort source) => new TimeSpan(source)); // decimal -> TimeSpan Converters.AddIntrinsic((decimal source) => new TimeSpan((long)source)); // float -> TimeSpan Converters.AddIntrinsic((float source) => new TimeSpan((long)source)); // double -> TimeSpan Converters.AddIntrinsic((double source) => new TimeSpan((long)source)); #endregion #region Byte Array Converters // bool -> byte[] Converters.AddIntrinsic((bool source) => BitConverter.GetBytes(source)); // byte[] -> bool Converters.AddIntrinsic((byte[] source) => source != null && BitConverter.ToBoolean(source, 0)); // char -> byte[] Converters.AddIntrinsic((char source) => BitConverter.GetBytes(source)); // byte[] -> char Converters.AddIntrinsic((byte[] source) => source == null ? '\0' : BitConverter.ToChar(source, 0)); // double -> byte[] Converters.AddIntrinsic((double source) => BitConverter.GetBytes(source)); // byte[] -> double Converters.AddIntrinsic((byte[] source) => source == null ? (double)0 : BitConverter.ToDouble(source, 0)); // float -> byte[] Converters.AddIntrinsic((float source) => BitConverter.GetBytes(source)); // byte[] -> float Converters.AddIntrinsic((byte[] source) => source == null ? (float)0 : BitConverter.ToSingle(source, 0)); // short -> byte[] Converters.AddIntrinsic((short source) => BitConverter.GetBytes(source)); // byte[] -> short Converters.AddIntrinsic((byte[] source) => source == null ? (short)0 : BitConverter.ToInt16(source, 0)); // ushort -> byte[] Converters.AddIntrinsic((ushort source) => BitConverter.GetBytes(source)); // byte[] -> ushort Converters.AddIntrinsic((byte[] source) => source == null ? (ushort)0 : BitConverter.ToUInt16(source, 0)); // int -> byte[] Converters.AddIntrinsic((int source) => BitConverter.GetBytes(source)); // byte[] -> int Converters.AddIntrinsic((byte[] source) => source == null ? 0 : BitConverter.ToInt32(source, 0)); // uint -> byte[] Converters.AddIntrinsic((uint source) => BitConverter.GetBytes(source)); // byte[] -> uint Converters.AddIntrinsic((byte[] source) => source == null ? (uint)0 : BitConverter.ToUInt32(source, 0)); // long -> byte[] Converters.AddIntrinsic((long source) => BitConverter.GetBytes(source)); // byte[] -> long Converters.AddIntrinsic((byte[] source) => source == null ? (long)0 : BitConverter.ToInt64(source, 0)); // ulong -> byte[] Converters.AddIntrinsic((ulong source) => BitConverter.GetBytes(source)); // byte[] -> ulong Converters.AddIntrinsic((byte[] source) => source == null ? (ulong)0 : BitConverter.ToUInt64(source, 0)); #endregion #region Spartial Converters.AddIntrinsic((DbGeography source) => source); Converters.AddIntrinsic((DbGeography source) => source == null ? null : source.AsText()); Converters.AddIntrinsic((DbGeography source) => source == null ? null : source.AsBinary()); Converters.AddIntrinsic((string source) => string.IsNullOrWhiteSpace(source) ? null : DbGeography.FromText(source)); Converters.AddIntrinsic((DbGeography source) => source.AsBinary()); Converters.AddIntrinsic((byte[] source) => source == null ? null : DbGeography.FromBinary(source)); Converters.AddIntrinsic((DbGeometry source) => source); Converters.AddIntrinsic((DbGeometry source) => source.AsText()); Converters.AddIntrinsic((string source) => string.IsNullOrWhiteSpace(source) ? null : DbGeometry.FromText(source)); Converters.AddIntrinsic((DbGeometry source) => source.AsBinary()); Converters.AddIntrinsic((byte[] source) => source == null ? null : DbGeometry.FromBinary(source)); #endregion #region Misc Converters // DateTime -> DateTimeOffset Converters.AddIntrinsic((DateTime source) => new DateTimeOffset(source)); // Guid -> byte[] Converters.AddIntrinsic((Guid source) => source.ToByteArray()); // byte[] -> Guid Converters.AddIntrinsic((byte[] source) => source == null ? Guid.Empty : new Guid(source)); // byte[] -> IPAddress Converters.AddIntrinsic((byte[] source) => source != null ? new IPAddress(source) : null); // IPAddress -> byte[] Converters.AddIntrinsic((IPAddress source) => source == null ? (byte[])null : source.GetAddressBytes()); // Type -> string Converters.AddIntrinsic((Type source) => source == null ? null : source.AssemblyQualifiedName); // TimeZoneInfo -> string Converters.AddIntrinsic((TimeZoneInfo source) => source == null ? null : source.ToSerializedString()); // string -> Uri Converters.AddIntrinsic((string source) => string.IsNullOrWhiteSpace(source) ? null : new Uri(source.Trim())); // string -> Type Converters.AddIntrinsic( (string source) => string.IsNullOrWhiteSpace(source) ? null : HostingEnvironment.IsHosted ? BuildManager.GetType(source, true) : Type.GetType(source.Trim(), true)); // string -> TimeZoneInfo Converters.AddIntrinsic( (string source) => string.IsNullOrWhiteSpace(source) ? null : TimeZoneInfo.FromSerializedString(source.Trim())); #endregion Conventions.Add <MatchNameConvention>(); }
private static Dictionary <MethodInfo, string> GetRenamedMethodFunctions() { var result = new Dictionary <MethodInfo, string>(); result.Add(GetStaticMethod(() => DbGeography.FromText(default(string))), "GeographyFromText"); result.Add(GetStaticMethod(() => DbGeography.FromText(default(string), default(int))), "GeographyFromText"); result.Add(GetStaticMethod(() => DbGeography.PointFromText(default(string), default(int))), "GeographyPointFromText"); result.Add(GetStaticMethod(() => DbGeography.LineFromText(default(string), default(int))), "GeographyLineFromText"); result.Add( GetStaticMethod(() => DbGeography.PolygonFromText(default(string), default(int))), "GeographyPolygonFromText"); result.Add( GetStaticMethod(() => DbGeography.MultiPointFromText(default(string), default(int))), "GeographyMultiPointFromText"); result.Add( GetStaticMethod(() => DbGeography.MultiLineFromText(default(string), default(int))), "GeographyMultiLineFromText"); result.Add( GetStaticMethod(() => DbGeography.MultiPolygonFromText(default(string), default(int))), "GeographyMultiPolygonFromText"); result.Add( GetStaticMethod(() => DbGeography.GeographyCollectionFromText(default(string), default(int))), "GeographyCollectionFromText"); result.Add(GetStaticMethod(() => DbGeography.FromBinary(default(byte[]), default(int))), "GeographyFromBinary"); result.Add(GetStaticMethod(() => DbGeography.FromBinary(default(byte[]))), "GeographyFromBinary"); result.Add( GetStaticMethod(() => DbGeography.PointFromBinary(default(byte[]), default(int))), "GeographyPointFromBinary"); result.Add(GetStaticMethod(() => DbGeography.LineFromBinary(default(byte[]), default(int))), "GeographyLineFromBinary"); result.Add( GetStaticMethod(() => DbGeography.PolygonFromBinary(default(byte[]), default(int))), "GeographyPolygonFromBinary"); result.Add( GetStaticMethod(() => DbGeography.MultiPointFromBinary(default(byte[]), default(int))), "GeographyMultiPointFromBinary"); result.Add( GetStaticMethod(() => DbGeography.MultiLineFromBinary(default(byte[]), default(int))), "GeographyMultiLineFromBinary"); result.Add( GetStaticMethod(() => DbGeography.MultiPolygonFromBinary(default(byte[]), default(int))), "GeographyMultiPolygonFromBinary"); result.Add( GetStaticMethod(() => DbGeography.GeographyCollectionFromBinary(default(byte[]), default(int))), "GeographyCollectionFromBinary"); result.Add(GetStaticMethod(() => DbGeography.FromGml(default(string))), "GeographyFromGml"); result.Add(GetStaticMethod(() => DbGeography.FromGml(default(string), default(int))), "GeographyFromGml"); result.Add(GetInstanceMethod((DbGeography geo) => geo.AsBinary()), "AsBinary"); result.Add(GetInstanceMethod((DbGeography geo) => geo.AsGml()), "AsGml"); result.Add(GetInstanceMethod((DbGeography geo) => geo.AsText()), "AsText"); result.Add(GetInstanceMethod((DbGeography geo) => geo.SpatialEquals(default(DbGeography))), "SpatialEquals"); result.Add(GetInstanceMethod((DbGeography geo) => geo.Disjoint(default(DbGeography))), "SpatialDisjoint"); result.Add(GetInstanceMethod((DbGeography geo) => geo.Intersects(default(DbGeography))), "SpatialIntersects"); result.Add(GetInstanceMethod((DbGeography geo) => geo.Buffer(default(double))), "SpatialBuffer"); result.Add(GetInstanceMethod((DbGeography geo) => geo.Distance(default(DbGeography))), "Distance"); result.Add(GetInstanceMethod((DbGeography geo) => geo.Intersection(default(DbGeography))), "SpatialIntersection"); result.Add(GetInstanceMethod((DbGeography geo) => geo.Union(default(DbGeography))), "SpatialUnion"); result.Add(GetInstanceMethod((DbGeography geo) => geo.Difference(default(DbGeography))), "SpatialDifference"); result.Add( GetInstanceMethod((DbGeography geo) => geo.SymmetricDifference(default(DbGeography))), "SpatialSymmetricDifference"); result.Add(GetInstanceMethod((DbGeography geo) => geo.ElementAt(default(int))), "SpatialElementAt"); result.Add(GetInstanceMethod((DbGeography geo) => geo.PointAt(default(int))), "PointAt"); result.Add(GetStaticMethod(() => DbGeometry.FromText(default(string))), "GeometryFromText"); result.Add(GetStaticMethod(() => DbGeometry.FromText(default(string), default(int))), "GeometryFromText"); result.Add(GetStaticMethod(() => DbGeometry.PointFromText(default(string), default(int))), "GeometryPointFromText"); result.Add(GetStaticMethod(() => DbGeometry.LineFromText(default(string), default(int))), "GeometryLineFromText"); result.Add(GetStaticMethod(() => DbGeometry.PolygonFromText(default(string), default(int))), "GeometryPolygonFromText"); result.Add( GetStaticMethod(() => DbGeometry.MultiPointFromText(default(string), default(int))), "GeometryMultiPointFromText"); result.Add( GetStaticMethod(() => DbGeometry.MultiLineFromText(default(string), default(int))), "GeometryMultiLineFromText"); result.Add( GetStaticMethod(() => DbGeometry.MultiPolygonFromText(default(string), default(int))), "GeometryMultiPolygonFromText"); result.Add( GetStaticMethod(() => DbGeometry.GeometryCollectionFromText(default(string), default(int))), "GeometryCollectionFromText"); result.Add(GetStaticMethod(() => DbGeometry.FromBinary(default(byte[]))), "GeometryFromBinary"); result.Add(GetStaticMethod(() => DbGeometry.FromBinary(default(byte[]), default(int))), "GeometryFromBinary"); result.Add(GetStaticMethod(() => DbGeometry.PointFromBinary(default(byte[]), default(int))), "GeometryPointFromBinary"); result.Add(GetStaticMethod(() => DbGeometry.LineFromBinary(default(byte[]), default(int))), "GeometryLineFromBinary"); result.Add( GetStaticMethod(() => DbGeometry.PolygonFromBinary(default(byte[]), default(int))), "GeometryPolygonFromBinary"); result.Add( GetStaticMethod(() => DbGeometry.MultiPointFromBinary(default(byte[]), default(int))), "GeometryMultiPointFromBinary"); result.Add( GetStaticMethod(() => DbGeometry.MultiLineFromBinary(default(byte[]), default(int))), "GeometryMultiLineFromBinary"); result.Add( GetStaticMethod(() => DbGeometry.MultiPolygonFromBinary(default(byte[]), default(int))), "GeometryMultiPolygonFromBinary"); result.Add( GetStaticMethod(() => DbGeometry.GeometryCollectionFromBinary(default(byte[]), default(int))), "GeometryCollectionFromBinary"); result.Add(GetStaticMethod(() => DbGeometry.FromGml(default(string))), "GeometryFromGml"); result.Add(GetStaticMethod(() => DbGeometry.FromGml(default(string), default(int))), "GeometryFromGml"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.AsBinary()), "AsBinary"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.AsGml()), "AsGml"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.AsText()), "AsText"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.SpatialEquals(default(DbGeometry))), "SpatialEquals"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Disjoint(default(DbGeometry))), "SpatialDisjoint"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Intersects(default(DbGeometry))), "SpatialIntersects"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Touches(default(DbGeometry))), "SpatialTouches"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Crosses(default(DbGeometry))), "SpatialCrosses"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Within(default(DbGeometry))), "SpatialWithin"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Contains(default(DbGeometry))), "SpatialContains"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Overlaps(default(DbGeometry))), "SpatialOverlaps"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Relate(default(DbGeometry), default(string))), "SpatialRelate"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Buffer(default(double))), "SpatialBuffer"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Distance(default(DbGeometry))), "Distance"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Intersection(default(DbGeometry))), "SpatialIntersection"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Union(default(DbGeometry))), "SpatialUnion"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.Difference(default(DbGeometry))), "SpatialDifference"); result.Add( GetInstanceMethod((DbGeometry geo) => geo.SymmetricDifference(default(DbGeometry))), "SpatialSymmetricDifference"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.ElementAt(default(int))), "SpatialElementAt"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.PointAt(default(int))), "PointAt"); result.Add(GetInstanceMethod((DbGeometry geo) => geo.InteriorRingAt(default(int))), "InteriorRingAt"); return(result); }
public static DbGeography ToDbGeography(this IGeometryObject geometryObject) { DbGeography value = DbGeography.FromBinary(WkbEncode.Encode(geometryObject)); return(value); }
static public DbGeography GeometryToDbGeography(GeoJSON.Net.Geometry.IGeometryObject p_Geometry) { return(DbGeography.FromBinary(WkbEncode.Encode(p_Geometry))); }
public static DbGeography GeographyFromGeometry(DbGeometry ogrGeometry) { // Not enforcing 4326 here, but am explicitly passing through relevant starting CoordinateSystemId. return(DbGeography.FromBinary(ogrGeometry.AsBinary(), ogrGeometry.CoordinateSystemId)); }
public static DbGeography ToDbGeography(this IGeometryObject geometryObject, int coordinateSystemId = 4326) { return(DbGeography.FromBinary(WkbEncode.Encode(geometryObject), coordinateSystemId)); }
public static DbGeography GeographyFromGeometry(DbGeometry ogrGeometry) { return(DbGeography.FromBinary(ogrGeometry.AsBinary())); }