/// <summary> /// Returns the way for the given id. /// </summary> /// <param name="id"></param> /// <returns></returns> public override Way GetWay(long id) { string wayKey = PrimitiveExtensions.BuildWayRedisKey(id); RedisWay redisWay = _clientWay.GetValue(wayKey); Way way = null; if (redisWay != null) { way = PrimitiveExtensions.ConvertFrom(redisWay); } return(way); }
/// <summary> /// Returns the relation with the given id. /// </summary> /// <param name="id"></param> /// <returns></returns> public override Relation GetRelation(long id) { string relationKey = PrimitiveExtensions.BuildRelationRedisKey(id); RedisRelation redisRelation = _clientRelation.GetValue(relationKey); Relation relation = null; if (redisRelation != null) { relation = PrimitiveExtensions.ConvertFrom(redisRelation); } return(relation); }
/// <summary> /// Returns the node for the given id. /// </summary> /// <param name="id"></param> /// <returns></returns> public override Node GetNode(long id) { string nodeKey = PrimitiveExtensions.BuildNodeRedisKey(id); RedisNode redisNode = _clientNode.GetValue(nodeKey); Node node = null; if (redisNode != null) { node = PrimitiveExtensions.ConvertFrom(redisNode); } return(node); }
/// <summary> /// Converts the given relation from a redis relation. /// </summary> /// <param name="redisRelation"></param> /// <returns></returns> public static Relation ConvertFrom(RedisRelation redisRelation) { Relation relation = new Relation(); relation.Id = redisRelation.Id.Value; relation.ChangeSetId = redisRelation.ChangeSetId; relation.TimeStamp = redisRelation.TimeStamp; relation.UserId = redisRelation.UserId; relation.UserName = redisRelation.UserName; relation.Version = redisRelation.Version; relation.Visible = redisRelation.Visible; relation.Tags = PrimitiveExtensions.ConvertFrom(redisRelation.Tags); relation.Members = PrimitiveExtensions.ConvertFrom(redisRelation.Members); return(relation); }
/// <summary> /// Converts the given node from a redis node. /// </summary> /// <param name="redisNode"></param> /// <returns></returns> public static Node ConvertFrom(RedisNode redisNode) { Node node = new Node(); node.Id = redisNode.Id.Value; node.Latitude = redisNode.Latitude.Value; node.Longitude = redisNode.Longitude.Value; node.ChangeSetId = redisNode.ChangeSetId; node.TimeStamp = redisNode.TimeStamp; node.UserId = redisNode.UserId; node.UserName = redisNode.UserName; node.Version = redisNode.Version; node.Visible = redisNode.Visible; node.Tags = PrimitiveExtensions.ConvertFrom(redisNode.Tags); return(node); }
/// <summary> /// Converts the given way from a redis way. /// </summary> /// <param name="redisWay"></param> /// <returns></returns> public static Way ConvertFrom(RedisWay redisWay) { Way way = new Way(); way.Id = redisWay.Id.Value; way.ChangeSetId = redisWay.ChangeSetId; way.TimeStamp = redisWay.TimeStamp; way.UserId = redisWay.UserId; way.UserName = redisWay.UserName; way.Version = redisWay.Version; way.Visible = redisWay.Visible; way.Tags = PrimitiveExtensions.ConvertFrom(redisWay.Tags); if (redisWay.Nodes != null) { way.Nodes = new List <long>(redisWay.Nodes); } return(way); }
/// <summary> /// Returns all ways for the given ids. /// </summary> /// <param name="ids"></param> /// <returns></returns> public override IList <Way> GetWays(IList <long> ids) { List <string> keys = new List <string>(); foreach (int id in ids) { string wayKey = PrimitiveExtensions.BuildWayRedisKey(id); keys.Add(wayKey); } List <RedisWay> redisWays = _clientWay.GetValues(keys); List <Way> ways = new List <Way>(); foreach (RedisWay redisWay in redisWays) { Way way = PrimitiveExtensions.ConvertFrom(redisWay); ways.Add(way); } return(ways); }
/// <summary> /// Returns all relations for the given ids. /// </summary> /// <param name="ids"></param> /// <returns></returns> public override IList <Relation> GetRelations(IList <long> ids) { List <string> keys = new List <string>(); foreach (int id in ids) { string relationKey = PrimitiveExtensions.BuildRelationRedisKey(id); keys.Add(relationKey); } List <RedisRelation> redisRelations = _clientRelation.GetValues(keys); List <Relation> relations = new List <Relation>(); foreach (RedisRelation redisRelation in redisRelations) { Relation relation = PrimitiveExtensions.ConvertFrom(redisRelation); relations.Add(relation); } return(relations); }
/// <summary> /// Returns all the nodes with the given ids. /// </summary> /// <param name="ids"></param> /// <returns></returns> public override IList <Node> GetNodes(IList <long> ids) { List <string> keys = new List <string>(); foreach (int id in ids) { string nodeKey = PrimitiveExtensions.BuildNodeRedisKey(id); keys.Add(nodeKey); } List <RedisNode> redisNodes = _clientNode.GetValues(keys); List <Node> nodes = new List <Node>(); foreach (RedisNode redisNode in redisNodes) { Node node = PrimitiveExtensions.ConvertFrom(redisNode); nodes.Add(node); } return(nodes); }
/// <summary> /// Returns all objects in the given bounding box and that pass the given filter. /// </summary> /// <param name="box"></param> /// <param name="filter"></param> /// <returns></returns> public override IList <OsmGeo> Get(GeoCoordinateBox box, OsmSharp.Osm.Filters.Filter filter) { List <OsmGeo> res = new List <OsmGeo>(); // create a range or tiles around the given bounding box. TileRange range = TileRange.CreateAroundBoundingBox(box, 14); // build all redis keys for the given boxes. var hashKeys = new List <string>(); foreach (Tile tile in range) { hashKeys.Add(tile.Id.ToString()); } byte[][] box_members = _client.SUnion(hashKeys.ToArray()); HashSet <string> nodeKeys = new HashSet <string>(); foreach (byte[] box_member in box_members) { long node_id = BitConverter.ToInt64(box_member, 0); string node_key = PrimitiveExtensions.BuildNodeRedisKey(node_id); nodeKeys.Add(node_key); } List <RedisNode> redisNodes = _clientNode.GetValues(new List <string>(nodeKeys)); var nodeIds = new List <long>(); foreach (RedisNode redisNode in redisNodes) { // test if the node is in the given bb. GeoCoordinate coordinate = new GeoCoordinate(redisNode.Latitude.Value, redisNode.Longitude.Value); if (box.IsInside(coordinate)) { res.Add(PrimitiveExtensions.ConvertFrom(redisNode)); nodeIds.Add(redisNode.Id.Value); } } // load all ways that contain the nodes that have been found. res.AddRange(this.GetWaysFor(nodeIds)); // get relations containing any of the nodes or ways in the current results-list. List <Relation> relations = new List <Relation>(); HashSet <long> relationIds = new HashSet <long>(); foreach (OsmGeo osmGeo in res) { IList <Relation> relationsFor = this.GetRelationsFor(osmGeo); foreach (Relation relation in relationsFor) { if (!relationIds.Contains(relation.Id.Value)) { relations.Add(relation); relationIds.Add(relation.Id.Value); } } } // recursively add all relations containing other relations as a member. do { res.AddRange(relations); // add previous relations-list. List <Relation> newRelations = new List <Relation>(); foreach (OsmGeo osmGeo in relations) { IList <Relation> relationsFor = this.GetRelationsFor(osmGeo); foreach (Relation relation in relationsFor) { if (!relationIds.Contains(relation.Id.Value)) { newRelations.Add(relation); relationIds.Add(relation.Id.Value); } } } relations = newRelations; } while (relations.Count > 0); if (filter != null) { List <OsmGeo> filtered = new List <OsmGeo>(); foreach (OsmGeo geo in res) { if (filter.Evaluate(geo)) { filtered.Add(geo); } } } return(res); }