public static async Task <GeoAddress> GetGeoAddressAsync(string apiKey, string originAddress, GeoUnit geoUnit = GeoUnit.Metric, RequestOutputFormat outputFormat = RequestOutputFormat.Json) { if (apiKey.IsNotNullOrEmpty() && originAddress.IsNotNullOrEmpty()) { var path = $"{(outputFormat == RequestOutputFormat.Json ? "json" : "xml")}?key={apiKey}"; if (geoUnit != GeoUnit.Metric) { path += "&units=imperial"; } path += $"&address={originAddress}"; using (var rest = new Rest(new Uri(RequestUrl))) { var result = await rest.GetAsync <string>(path); if (result.IsNotNullOrEmpty()) { var jobject = JObject.Parse(result); if (jobject.ContainsKey("results")) { var valueResult = jobject["results"].ToObject <GeoAddress[]>(); if (valueResult?.Length > 0) { return(valueResult[0]); } } } } } return(null); }
public GeoFilter(string property, double lon, double lat, double radius, GeoUnit unit) : base(property) { this.lon = lon; this.lat = lat; this.radius = radius; this.unit = unit; }
public GeoDistanceRangeFilterDescriptor Distance(double From, double To, GeoUnit Unit) { this._FromDistance = From; this._ToDistance = To; this._GeoUnit = Enum.GetName(typeof(GeoUnit), Unit); return(this); }
public GeoDistanceRangeFilterDescriptor Distance(double From, double To, GeoUnit Unit) { this._FromDistance = From; this._ToDistance = To; this._GeoUnit = Enum.GetName(typeof(GeoUnit), Unit); return this; }
private GeoTerm(double longitude, double latitude, double distance, GeoUnit unit) { Longitude = longitude; Latitude = latitude; Distance = distance; Unit = unit; }
public GeoValue(double lon, double lat, double radius, GeoUnit unit) { _lon = lon; _lat = lat; _radius = radius; _unit = unit; }
/// <summary> /// GEODIST : https://redis.io/commands/geodist /// </summary> public Task <double?> DistanceAsync(T member1, T member2, GeoUnit unit = GeoUnit.Meters, CommandFlags flags = CommandFlags.None) { var value1 = this.Connection.Converter.Serialize(member1); var value2 = this.Connection.Converter.Serialize(member2); return(this.Connection.Database.GeoDistanceAsync(this.Key, value1, value2, unit, flags)); }
/// <summary> /// 返回两个给定位置之间的距离 /// </summary> /// <param name="key"></param> /// <param name="member1"></param> /// <param name="member2"></param> /// <param name="geoUnit"></param> /// <returns></returns> public double GeoDist(string key, string member1, string member2, GeoUnit geoUnit = GeoUnit.m) { double result = 0D; double.TryParse(RedisConnection.DoWithMutiParams(RequestType.GEODIST, key, member1, member2, geoUnit.ToString()).Data, out result); return(result); }
public GeoDistanceRangeFilterDescriptor Distance(double From, double To, GeoUnit Unit) { _.From = From; _.To = To; _.Unit = Unit; this.IsValidDistance = true; return(this); }
/// <summary> /// Creates a new GeoRadius /// </summary> public GeoRadius(RedisKey key, GeoPosition geoPosition, double radius, int maxReturnCount = -1, GeoUnit unit = GeoUnit.Meters, GeoRadiusOptions geoRadiusOptions = (GeoRadiusOptions.WithCoordinates | GeoRadiusOptions.WithDistance)) { Key = key; GeoPosition = geoPosition; Radius = radius; Unit = unit; GeoRadiusOptions = geoRadiusOptions; MaxReturnCount = maxReturnCount; }
public GeoDistanceRangeFilterDescriptor Distance(double From, double To, GeoUnit Unit) { From.ThrowIfNull("From"); To.ThrowIfNull("To"); this._FromDistance = From; this._ToDistance = To; this._GeoUnit = Enum.GetName(typeof(GeoUnit), Unit); return(this); }
public GeoDistanceRangeFilterDescriptor Distance(double From, double To, GeoUnit Unit) { From.ThrowIfNull("From"); To.ThrowIfNull("To"); this._FromDistance = From; this._ToDistance = To; this._GeoUnit = Enum.GetName(typeof(GeoUnit), Unit); return this; }
protected FilterContainer GeoDistanceFilter <TFilterOnDocument>( Expression <Func <TFilterOnDocument, object> > field, double latitude, double longitude, double distance, GeoUnit unit = GeoUnit.Miles, GeoOptimizeBBox optimize = GeoOptimizeBBox.None) where TFilterOnDocument : class { return(Filter <TFilterOnDocument> .GeoDistance(field, geo => geo .Location(latitude, longitude) .Optimize(optimize) .Distance(distance, unit))); }
public object GeoRadiusByMember(string key, string member, decimal radius, GeoUnit unit, bool withdoord, bool withdist, bool withhash, long count, Collation?collation, string storekey, string storedistkey) => Call <object>("GEORADIUSBYMEMBER" .Input(key, member, radius) .InputRaw(unit) .InputIf(withdoord, "WITHCOORD") .InputIf(withdist, "WITHDIST") .InputIf(withhash, "WITHHASH") .InputIf(count != 0, "COUNT", count) .InputIf(collation != null, collation) .InputIf(!string.IsNullOrWhiteSpace(storekey), "STORE", storekey) .InputIf(!string.IsNullOrWhiteSpace(storedistkey), "STOREDIST", storedistkey) .FlagKey(key), rt => rt.ThrowOrValue());
public GeoRadiusResult[] GeoRedius(string key, double lng, double lat, double radius, GeoUnit unit = GeoUnit.Miles, int count = -1, Order order = Order.Ascending, int db = -1) { var server = GetDataBase(db); return(server.GeoRadius(key, lng, lat, radius, unit, count, order)); }
internal static string AsRedisString(this GeoUnit value) { switch (value) { case GeoUnit.Feet: return("ft"); case GeoUnit.Kilometers: return("km"); case GeoUnit.Meters: return("m"); case GeoUnit.Miles: return("mi"); default: throw new InvalidOperationException($"Unknown unit: {value}"); } }
internal static string GetRedisUnit(GeoUnit unit) { switch (unit) { case GeoUnit.Meters: return("m"); case GeoUnit.Kilometers: return("km"); case GeoUnit.Miles: return("mi"); case GeoUnit.Feet: return("ft"); default: throw new ArgumentOutOfRangeException(nameof(unit)); } }
public static Task <DistanceMatrixResponse> GetDistanceAsync(string apiKey, List <string> originAddresses, List <string> destinationAddresses, GeoUnit geoUnit = GeoUnit.Metric, RequestOutputFormat outputFormat = RequestOutputFormat.Json) { if (apiKey.IsNotNullOrEmpty() && originAddresses?.Count > 0 && destinationAddresses?.Count() > 0) { var path = $"{(outputFormat == RequestOutputFormat.Json ? "json" : "xml")}?key={apiKey}"; if (geoUnit != GeoUnit.Metric) { path += "&units=imperial"; } var origins = string.Join("|", originAddresses.Select(item => item.Trim())); var destinations = string.Join("|", destinationAddresses.Select(item => item.Trim())); path += $"&origins={origins}&destinations={destinations}"; using (var rest = new Rest(new Uri(RequestUrl))) { return(rest.GetAsync <DistanceMatrixResponse>(path)); } } return(Task.FromResult(default(DistanceMatrixResponse))); }
public GeoDistanceFilterDescriptor Distance(double distance, GeoUnit unit) { this._Distance = distance; this._GeoUnit = Enum.GetName(typeof(GeoUnit), unit); return(this); }
public static async Task <List <DistanceMatrixDistance> > GetDistancesAsync(string apiKey, string originAddress, List <string> destinationAddresses, GeoUnit geoUnit = GeoUnit.Metric, RequestOutputFormat outputFormat = RequestOutputFormat.Json) { var result = await GetDistanceAsync(apiKey, new List <string> { originAddress }, destinationAddresses, geoUnit, outputFormat); if (result?.Status == "OK" && result.Rows?.Length > 0 && result.Rows[0].Elements?.Length > 0) { return(result.Rows[0].Elements?.ToList()); } return(null); }
public SortGeoDistanceDescriptor <T> Unit(GeoUnit unit) { unit.ThrowIfNull("unit"); Self.GeoUnit = unit; return(this); }
public GeoDistanceFilterDescriptor Distance(double distance, GeoUnit unit) { this._Distance = distance; this._GeoUnit = Enum.GetName(typeof(GeoUnit), unit); return this; }
public GeoDistanceFilterDescriptor Distance(double distance, GeoUnit unit) { ((IGeoDistanceFilter)this).Distance = distance; ((IGeoDistanceFilter)this).Unit = unit; return this; }
/// <summary> /// 找出位于指定范围内的元素, 但是 GEORADIUSBYMEMBER 的中心点是由给定的位置元素决定的, 而不是像 GEORADIUS 那样, 使用输入的经度和纬度来决定中心点 /// </summary> /// <param name="timeSpan"></param> /// <param name="key"></param> /// <param name="member"></param> /// <param name="dist"></param> /// <param name="geoUnit"></param> /// <param name="asc"></param> /// <param name="count"></param> /// <returns></returns> public async Task <List <GeoDistInfo> > GeoRandiusByMemberAsync(TimeSpan timeSpan, string key, string member, double dist, GeoUnit geoUnit = GeoUnit.m, bool asc = true, int count = 20) { var data = await _cnn.DoWithMutiParamsAsync(RequestType.GEORADIUSBYMEMBER, timeSpan, key, member, dist.ToString(), geoUnit.ToString(), "WITHDIST", "WITHCOORD", (asc ? "ASC" : "DESC"), "COUNT", count.ToString()); return(data.ToGeoDistInfos()); }
public GeoDistanceRangeFilterDescriptor Distance(double From, double To, GeoUnit Unit) { _.From = From; _.To = To; _.Unit = Unit; this.IsValidDistance = true; return this; }
/// <summary> /// 返回两个给定位置之间的距离 /// </summary> /// <param name="timeSpan"></param> /// <param name="key"></param> /// <param name="member1"></param> /// <param name="member2"></param> /// <param name="geoUnit"></param> /// <returns></returns> public async Task <double> GeoDistAsync(TimeSpan timeSpan, string key, string member1, string member2, GeoUnit geoUnit = GeoUnit.m) { double result; var data = await _cnn.DoWithMutiParamsAsync(RequestType.GEODIST, timeSpan, key, member1, member2, geoUnit.ToString()); double.TryParse(data.Data, out result); return(result); }
public GeoHashCellFilterDescriptor Distance(double distance, GeoUnit unit) { ((IGeoHashCellFilter)this).Precision = distance; ((IGeoHashCellFilter)this).Unit = unit; return this; }
public Task <GeoRadiusResult[]> GeoRadiusAsync(RedisKey key, double longitude, double latitude, double radius, GeoUnit unit = GeoUnit.Meters, int count = -1, Order?order = null, GeoRadiusOptions options = GeoRadiusOptions.Default, CommandFlags flags = CommandFlags.None) => Inner.GeoRadiusAsync(ToInner(key), longitude, latitude, radius, unit, count, order, options, flags);
public double?GeoDistance(RedisKey key, RedisValue member1, RedisValue member2, GeoUnit unit = GeoUnit.Meters, CommandFlags flags = CommandFlags.None) { return(Inner.GeoDistance(ToInner(key), member1, member2, unit, flags)); }
public GeoDistanceFilterDescriptor Distance(double distance, GeoUnit unit) { ((IGeoDistanceFilter)this).Distance = distance; ((IGeoDistanceFilter)this).Unit = unit; return(this); }
public GeoRadiusResult[] GeoRadius(RedisKey key, RedisValue member, double radius, GeoUnit unit = GeoUnit.Meters, int count = -1, Order?order = null, GeoRadiusOptions options = GeoRadiusOptions.Default, CommandFlags flags = CommandFlags.None) { return(Inner.GeoRadius(ToInner(key), member, radius, unit, count, order, options, flags)); }
/// <summary> /// 以给定的经纬度为中心, 返回键包含的位置元素当中, 与中心的距离不超过给定最大距离的所有位置元素 /// </summary> /// <param name="key"></param> /// <param name="lng"></param> /// <param name="lat"></param> /// <param name="dist"></param> /// <param name="geoUnit"></param> /// <param name="asc"></param> /// <param name="count"></param> /// <returns></returns> public List <GeoDistInfo> GeoRandius(string key, double lng, double lat, double dist, GeoUnit geoUnit = GeoUnit.m, bool asc = true, int count = 20) { return(RedisConnection.DoWithMutiParams(RequestType.GEORADIUS, key, lng.ToString(), lat.ToString(), dist.ToString(), geoUnit.ToString(), "WITHDIST", "WITHCOORD", (asc ? "ASC" : "DESC"), "COUNT", count.ToString()).ToGeoDistInfos()); }
public Task <double?> GeoDistanceAsync(RedisKey key, RedisValue member1, RedisValue member2, GeoUnit unit = GeoUnit.Meters, CommandFlags flags = CommandFlags.None) => Inner.GeoDistanceAsync(ToInner(key), member1, member2, unit, flags);
public void GeoDistAsync(string key, string member1, string member2, GeoUnit geoUnit = GeoUnit.m) { var cmd = _redisCode.Coder(RequestType.GEODIST, key, member1, member2, geoUnit.ToString()); _batchData.Add(new BatchItem(RequestType.GEODIST, cmd)); }
public GeoDistanceAggregationDescriptor <T> Unit(GeoUnit unit) { this._Unit = unit; return(this); }
/// <summary> /// GEORADIUSBYMEMBER : https://redis.io/commands/georadiusbymember /// </summary> public async Task <RedisGeoRadiusResult <T>[]> RadiusAsync(T member, double radius, GeoUnit unit = GeoUnit.Meters, int count = -1, Order?order = null, GeoRadiusOptions options = GeoRadiusOptions.Default, CommandFlags flags = CommandFlags.None) { var value = this.Connection.Converter.Serialize(member); var results = await this.Connection.Database.GeoRadiusAsync(this.Key, value, radius, unit, count, order, options, flags).ConfigureAwait(false); return(results.Select(this.Connection.Converter, (x, c) => x.ToGenerics <T>(c)).ToArray()); }