public static IEnumerable <GeoLatLonAlt> GetAltitudeForCoords(double lat, double lng, double distance) { distance = distance / 1000; using (var db = new BotContext()) { return (db.MapzenAlt.Where( x => 12742 * SqlCeFunctions.Asin( SqlCeFunctions.SquareRoot(SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) + SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) * SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Lat) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2))) < distance).OrderBy(x => 12742 * SqlCeFunctions.Asin( SqlCeFunctions.SquareRoot(SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) + SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) * SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Lat) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2)))).ToList()); } }
public static bool ElevationDataExists(double lat, double lng, double distance) { distance = distance / 1000; using (var db = new BotContext()) { var res = false; try { res = db.MapzenAlt.Any( x => 12742 * SqlCeFunctions.Asin( SqlCeFunctions.SquareRoot( SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) + SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) * SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Lat) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2))) < distance); } catch (Exception) { //ignore } return(res); } }
public void SqlCeFunction_passing_function_as_argument_to_another_works() { using (var context = GetArubaCeContext()) { var query = context.AllTypes.Select(a => SqlCeFunctions.Asin(SqlCeFunctions.Acos(a.c10_float))); Assert.Contains("ASIN", query.ToString().ToUpperInvariant()); Assert.Contains("ACOS", query.ToString().ToUpperInvariant()); } }
public static IEnumerable <PokemonSeen> GetPokemonSeenForCoords(double lat, double lng, double distance) { distance = distance / 1000; using (var db = new BotContext()) { return (db.PokemonSeen.Where( x => 12742 * SqlCeFunctions.Asin( SqlCeFunctions.SquareRoot(SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Latitude - lat) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Latitude - lat) / 2) + SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) * SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Latitude) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Longitude - lng) / 2) * SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Longitude - lng) / 2))) < distance).ToList()); } }