/// <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> /// 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> /// Builds a redis key for this given node. /// </summary> /// <param name="node"></param> /// <returns></returns> public static string GetRedisKey(this Node node) { return(PrimitiveExtensions.BuildNodeRedisKey(node.Id.Value)); }
/// <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); }