/// <summary> /// Tries to get a way tags collection from the cache /// </summary> /// <param name="id">The id of the tags collection</param> /// <param name="collection">The collection to assign</param> /// <param name="type">The type of osm geo</param> /// <returns>True if successfully fetched, false otherwise</returns> public bool TryGetTagsCollection(int id, out TagsCollectionBase collection, OsmGeoType type) { lock (_locks[type]) { return(_collections[type].TryGetValue(id, out collection)); } }
/// <summary> /// Removes a relation tags collection from the cache /// </summary> /// <param name="id">The given id to remove from the cache</param> /// <param name="type">The type of osm geo</param> /// <returns>True if the entry was removed, false if not</returns> public bool RemoveTagsCollection(int id, OsmGeoType type) { lock (_locks[type]) { return(_collections[type].Remove(id)); } }
/// <summary> /// Gets an osm object of the given type and the given id. /// </summary> public OsmGeo Get(OsmGeoType type, long id) { switch (type) { case OsmGeoType.Node: Node node; if (!_nodes.TryGetValue(id, out node)) { return null; } return node; case OsmGeoType.Way: Way way; if (!_ways.TryGetValue(id, out way)) { return null; } return way; case OsmGeoType.Relation: Relation relation; if (!_relations.TryGetValue(id, out relation)) { return null; } return relation; } return null; }
/// <summary> /// Returns all relations that have the given object as a member. /// </summary> /// <param name="type"></param> /// <param name="id"></param> /// <returns></returns> public override IList <Relation> GetRelationsFor(OsmGeoType type, long id) { List <Relation> relations = new List <Relation>(); HashSet <long> relationIds = null; switch (type) { case OsmGeoType.Node: if (!_relationsPerNode.TryGetValue(id, out relationIds)) { return(relations); } break; case OsmGeoType.Way: if (!_relationsPerWay.TryGetValue(id, out relationIds)) { return(relations); } break; case OsmGeoType.Relation: if (!_relationsPerRelation.TryGetValue(id, out relationIds)) { return(relations); } break; } foreach (long relationId in relationIds) { relations.Add(this.GetRelation(relationId)); } return(relations); }
/// <summary> /// Gets an osm object of the given type, the given id and the given version #. /// </summary> public OsmGeo Get(OsmGeoType type, long id) { switch (type) { case OsmGeoType.Node: return(_nodes.Values.Where(x => { return x.Id == id; }).OrderBy(x => - x.Version).FirstOrDefault()); case OsmGeoType.Way: return(_ways.Values.Where(x => { return x.Id == id; }).OrderBy(x => - x.Version).FirstOrDefault()); case OsmGeoType.Relation: return(_relations.Values.Where(x => { return x.Id == id; }).OrderBy(x => - x.Version).FirstOrDefault()); } throw new Exception(string.Format("Uknown OsmGeoType: {0}.", type.ToInvariantString())); }
/// <summary> /// Raises the chance event. /// </summary> /// <param name="type"></param> /// <param name="object_type"></param> /// <param name="id"></param> private void RaiseChange(ChangeType type, OsmGeoType object_type, long id) { if (Change != null) { Change(type, object_type, id); } }
/// <summary> /// Returns all relations that contain the given object. /// </summary> /// <param name="type"></param> /// <param name="id"></param> /// <returns></returns> public override IList <Relation> GetRelationsFor(OsmGeoType type, long id) { SQLiteConnection con = CreateConnection(); SQLiteCommand com; SQLiteDataReader reader; string sql = "SELECT relation_id FROM relation_members WHERE (member_id = :member_id and member_type = :member_type) ORDER BY sequence_id"; com = new SQLiteCommand(sql); com.Connection = con; com.Parameters.Add(new SQLiteParameter(@"member_type", DbType.Int64)); com.Parameters.Add(new SQLiteParameter(@"member_id", DbType.Int64)); com.Parameters[0].Value = this.ConvertMemberType(type).Value; com.Parameters[1].Value = id; HashSet <long> ids = new HashSet <long>(); reader = ExecuteReader(com); while (reader.Read()) { ids.Add(reader.GetInt64(0)); } reader.Close(); return(this.GetRelations(ids.ToList <long>())); }
/// <summary> /// Loads an index for the given tile from disk (if any). /// </summary> public static Index LoadIndex(string path, Tile tile, OsmGeoType type, bool mapped = false) { var extension = ".nodes.idx"; if (type == OsmGeoType.Way) { extension = ".ways.idx"; } else if (type == OsmGeoType.Relation) { extension = ".relations.idx"; } var location = FileSystemFacade.FileSystem.Combine(path, tile.Zoom.ToInvariantString(), tile.X.ToInvariantString(), tile.Y.ToInvariantString() + extension); if (!FileSystemFacade.FileSystem.Exists(location)) { return(null); } if (mapped) { var stream = FileSystemFacade.FileSystem.OpenRead(location); return(Index.Deserialize(stream, ArrayProfile.NoCache)); } using (var stream = FileSystemFacade.FileSystem.OpenRead(location)) { return(Index.Deserialize(stream)); } }
/// <summary> /// Gets the last id. /// </summary> public long GetLastId(OsmGeoType type) { switch (type) { case OsmGeoType.Node: if (_nodes.Count == 0) { return(-1); } return(_nodes.Keys.Select(x => x.Id).Max()); case OsmGeoType.Way: if (_ways.Count == 0) { return(-1); } return(_ways.Keys.Select(x => x.Id).Max()); case OsmGeoType.Relation: if (_relations.Count == 0) { return(-1); } return(_relations.Keys.Select(x => x.Id).Max()); } throw new Exception("Invalid OsmGeo type."); }
/// <summary> /// Gets an osm object of the given type, the given id and the given version #. /// </summary> public OsmGeo Get(OsmGeoType type, long id, int version) { var key = new Key(id, version); switch (type) { case OsmGeoType.Node: Node node; if (!_nodes.TryGetValue(key, out node)) { return(null); } return(node); case OsmGeoType.Way: Way way; if (!_ways.TryGetValue(key, out way)) { return(null); } return(way); case OsmGeoType.Relation: Relation relation; if (!_relations.TryGetValue(key, out relation)) { return(null); } return(relation); } throw new Exception(string.Format("Uknown OsmGeoType: {0}.", type.ToInvariantString())); }
public override TagsCollectionBase Evaluate(TagsCollectionBase tags, OsmGeoType type) { var a_result = _a.Evaluate(tags, type); var b_result = _b.Evaluate(tags, type); return a_result.Union(b_result); }
/// <summary> /// Evaluates if the cache has a relation tags collection /// </summary> /// <param name="id">The given id to evaluate</param> /// <param name="type">The type of osm geo</param> /// <returns>True if the cache contains the tags collection</returns> public bool ContainsTagsCollection(int id, OsmGeoType type) { lock (_locks[type]) { return(_collections[type].ContainsKey(id)); } }
public override TagsCollectionBase Evaluate(TagsCollectionBase tags, OsmGeoType type) { var a_result = _a.Evaluate(tags, type); var b_result = _b.Evaluate(tags, type); return(a_result.Union(b_result)); }
public override void Reset() { this._waysIn.Clear(); this._nodesIn.Clear(); this._currentType = OsmGeoType.Node; this._includeExtraMode = false; this.Source.Reset(); }
/// <summary> /// Resets this filter. /// </summary> public override void Reset() { _waysIn.Clear(); _nodesIn.Clear(); _currentType = OsmGeoType.Node; _includeExtraMode = false; this.Reader.Reset(); }
/// <summary> /// Gets the last visible version of the object of the given type and given id. /// </summary> public OsmGeo Get(OsmGeoType type, long id) { return(_db.Get(new OsmGeoKey[] { new OsmGeoKey() { Id = id, Type = type } }).FirstOrDefault()); }
/// <summary> /// Creates a new relation member. /// </summary> /// <param name="memberId"></param> /// <param name="memberRole"></param> /// <param name="memberType"></param> /// <returns></returns> public static RelationMember Create(int memberId, string memberRole, OsmGeoType memberType) { RelationMember member = new RelationMember(); member.MemberId = memberId; member.MemberRole = memberRole; member.MemberType = memberType; return member; }
/// <summary> /// Creates a new relation member. /// </summary> /// <param name="memberId"></param> /// <param name="memberRole"></param> /// <param name="memberType"></param> /// <returns></returns> public static RelationMember Create(int memberId, string memberRole, OsmGeoType memberType) { RelationMember member = new RelationMember(); member.MemberId = memberId; member.MemberRole = memberRole; member.MemberType = memberType; return(member); }
public override TagsCollectionBase Evaluate(TagsCollectionBase tags, OsmGeoType type) { if (tags == null) { throw new ArgumentNullException("tags"); } return(tags); }
public static RelationMember Create(int memberId, string memberRole, OsmGeoType memberType) { return(new RelationMember() { MemberId = new long?((long)memberId), MemberRole = memberRole, MemberType = new OsmGeoType?(memberType) }); }
public override TagsCollectionBase Evaluate(TagsCollectionBase tags, OsmGeoType type) { if (tags == null) { throw new ArgumentNullException("tags"); } return tags; }
public TagFilterTags(OsmGeoType type, string key) { if (string.IsNullOrEmpty("key")) { throw new ArgumentException("Must not be null or empty", "key"); } _keys = new HashSet<string>() { key }; _type = type; }
/// <summary> /// Gets the object with the given type and given id. /// </summary> public OsmGeo Get(OsmGeoType type, long id) { var res = this.Get(new OsmGeoKey[] { new OsmGeoKey() { Id = id, Type = type } }); return(res.FirstOrDefault()); }
/// <summary> /// Returns all relations for the given object. /// </summary> /// <param name="type"></param> /// <param name="id"></param> /// <returns></returns> public override IList <Relation> GetRelationsFor(OsmGeoType type, long id) { IList <Relation> relations = _source.GetRelationsFor(type, id); foreach (Relation relation in relations) { _relationsCache.Add(relation.Id.Value, relation); } return(relations); }
/// <summary> /// Initializes this source. /// </summary> public override void Initialize() { _connection = new SQLiteConnection(_connectionString); _connection.Open(); _current = null; _currentType = OsmGeoType.Node; _nodeReader = null; }
public override IList <Relation> GetRelationsFor(OsmGeoType type, long id) { IList <Relation> relationsFor = this._source.GetRelationsFor(type, id); foreach (Relation relation in (IEnumerable <Relation>)relationsFor) { this._relationsCache.Add(relation.Id.Value, relation); } return(relationsFor); }
/// <summary> /// Resets this source. /// </summary> public override void Reset() { _current = null; _currentType = OsmGeoType.Node; if (_nodeReader != null) { _nodeReader.Close(); _nodeReader.Dispose(); _nodeReader = null; } }
/// <summary> /// Adds a collection to the cache /// </summary> /// <param name="id">The id of the tags collection</param> /// <param name="collection">The tags collection</param> /// <param name="type">The type of osm geo</param> public void AddTagsCollection(int id, TagsCollectionBase collection, OsmGeoType type) { if (collection == null) { throw new ArgumentNullException("collection"); } lock (_locks[type]) { _collections[type][id] = collection; } }
/// <summary> /// Deletes the osm object with the given type, the given id without applying a changeset. /// </summary> public bool Delete(OsmGeoType type, long id) { switch (type) { case OsmGeoType.Node: return _nodes.Remove(id); case OsmGeoType.Way: return _ways.Remove(id); case OsmGeoType.Relation: return _relations.Remove(id); } return false; }
public TagFilterTags(OsmGeoType type, string key) { if (string.IsNullOrEmpty("key")) { throw new ArgumentException("Must not be null or empty", "key"); } _keys = new HashSet <string>() { key }; _type = type; }
/// <summary> /// Reads an osmGeo object from disk. /// </summary> /// <param name="id"></param> /// <param name="type"></param> private OsmGeo Read(long id, OsmGeoType type) { XmlOsmStreamSource source = new XmlOsmStreamSource(this.StoreFileName(id, type)); List <OsmGeo> readObjects = new List <OsmGeo>(source); source.Dispose(); if (readObjects != null && readObjects.Count == 1) { return(readObjects[0]); } throw new InvalidDataException("Invalid cached file read, make sure not to modify the cached while in use or to synchonize access."); }
/// <summary> /// Gets a way tags collection from the cache /// </summary> /// <param name="id">The id of the tags collection</param> /// <param name="type">The type of osm geo</param> public TagsCollectionBase GetTagsCollection(int id, OsmGeoType type) { lock (_locks[type]) { TagsCollectionBase collection; if (TryGetTagsCollection(id, out collection, type)) { return(collection); } } return(null); }
/// <summary> /// Builds a redis key for the relation members relation list. /// </summary> /// <param name="type"></param> /// <param name="id"></param> /// <returns></returns> public static string BuildMemberRelationListRedisKey(OsmGeoType type, long id) { string typeString = "1"; switch (type) { case OsmGeoType.Way: typeString = "2"; break; case OsmGeoType.Relation: typeString = "3"; break; } return string.Format("m:{0}.{1}", typeString, id); }
public override TagsCollectionBase Evaluate(TagsCollectionBase tags, OsmGeoType type) { if (tags == null) { throw new ArgumentNullException("tags"); } if (type == _type) { return(tags.KeepKeysOf(_keys)); } return(TagsCollectionBase.Empty); }
public TagFilterTags(OsmGeoType type, ICollection<string> keys) { if (keys == null) { throw new NullReferenceException("keys"); } if (keys.Count <= 0) { throw new ArgumentException("Must have at least one key", "keys"); } _keys = keys; _type = type; }
/// <summary> /// Returns the storage file name for this given object type and id. /// </summary> /// <param name="id"></param> /// <param name="type"></param> /// <returns></returns> private string StoreFileName(long id, OsmGeoType type) { switch (type) { case OsmGeoType.Node: return(Path.Combine(_cacheDirectory.FullName, string.Format("{0}.node", id.ToString()))); case OsmGeoType.Way: return(Path.Combine(_cacheDirectory.FullName, string.Format("{0}.way", id.ToString()))); case OsmGeoType.Relation: return(Path.Combine(_cacheDirectory.FullName, string.Format("{0}.relation", id.ToString()))); } throw new ArgumentOutOfRangeException(); }
public override TagsCollectionBase Evaluate(TagsCollectionBase tags, OsmGeoType type) { if (tags == null) { throw new ArgumentNullException("tags"); } var result = tags; if (type == _type) { result = TagsCollectionBase.Empty; } return result; }
/// <summary> /// Converts the member type to long. /// </summary> /// <param name="memberType"></param> /// <returns></returns> private long? ConvertMemberType(OsmGeoType? memberType) { if (memberType.HasValue) { return (long)memberType.Value; } return null; }
/// <summary> /// Returns all relations that contain the given object. /// </summary> /// <param name="type"></param> /// <param name="id"></param> /// <returns></returns> public override IList<Relation> GetRelationsFor(OsmGeoType type, long id) { SQLiteConnection con = CreateConnection(); SQLiteCommand com; SQLiteDataReader reader; string sql = "SELECT relation_id FROM relation_members WHERE (member_id = :member_id and member_type = :member_type) ORDER BY sequence_id"; com = new SQLiteCommand(sql); com.Connection = con; com.Parameters.Add(new SQLiteParameter(@"member_type", DbType.Int64)); com.Parameters.Add(new SQLiteParameter(@"member_id", DbType.Int64)); com.Parameters[0].Value = this.ConvertMemberType(type).Value; com.Parameters[1].Value = id; HashSet<long> ids = new HashSet<long>(); reader = ExecuteReader(com); while (reader.Read()) { ids.Add(reader.GetInt64(0)); } reader.Close(); return this.GetRelations(ids.ToList<long>()); }
private bool DoMoveNextWay() { if (_way_reader == null) { SQLiteCommand way_command = new SQLiteCommand("select * from way where id > 26478817 order by id"); way_command.Connection = _connection; _way_reader = way_command.ExecuteReader(); if (!_way_reader.Read()) { _way_reader.Close(); } SQLiteCommand way_tag_command = new SQLiteCommand("select * from way_tags where way_id > 26478817 order by way_id"); way_tag_command.Connection = _connection; _way_tag_reader = way_tag_command.ExecuteReader(); if (!_way_tag_reader.IsClosed && !_way_tag_reader.Read()) { _way_tag_reader.Close(); } SQLiteCommand way_node_command = new SQLiteCommand("select * from way_nodes where way_id > 26478817 order by way_id,sequence_id"); way_node_command.Connection = _connection; _way_node_reader = way_node_command.ExecuteReader(); if (!_way_node_reader.IsClosed && !_way_node_reader.Read()) { _way_node_reader.Close(); } } // read next way. if (!_way_reader.IsClosed) { Way way = new Way(); way.Id = _way_reader.GetInt64(0); way.ChangeSetId = _way_reader.GetInt64(1); way.TimeStamp = _way_reader.IsDBNull(3) ? DateTime.MinValue : _way_reader.GetDateTime(3); //way.UserId = _way_reader.GetInt64(6); //way.UserName = _way_reader.GetString(5); way.Version = (ulong)_way_reader.GetInt64(4); way.Visible = _way_reader.GetInt64(2) == 1; if (!_way_tag_reader.IsClosed) { long returned_id = _way_tag_reader.GetInt64(_way_tag_reader.GetOrdinal("way_id")); while (returned_id == way.Id.Value) { if (way.Tags == null) { way.Tags = new TagsCollection(); } string key = _way_tag_reader.GetString(1); string value = _way_tag_reader.GetString(2); way.Tags.Add(key, value); if (!_way_tag_reader.Read()) { _way_tag_reader.Close(); returned_id = -1; } else { returned_id = _way_tag_reader.GetInt64(0); } } } if (!_way_node_reader.IsClosed) { long returned_id = _way_node_reader.GetInt64(_way_node_reader.GetOrdinal("way_id")); while (returned_id == way.Id.Value) { if (way.Nodes == null) { way.Nodes = new List<long>(); } long node_id = _way_node_reader.GetInt64(1); way.Nodes.Add(node_id); if (!_way_node_reader.Read()) { _way_node_reader.Close(); returned_id = -1; } else { returned_id = _way_node_reader.GetInt64(0); } } } // set the current variable! _current = way; // advance the reader(s). if (!_way_reader.Read()) { _way_reader.Close(); } if (!_way_tag_reader.IsClosed && !_way_tag_reader.Read()) { _way_tag_reader.Close(); } if (!_way_node_reader.IsClosed && !_way_node_reader.Read()) { _way_node_reader.Close(); } return true; } else { _way_reader.Close(); _way_reader.Dispose(); _way_reader = null; _way_tag_reader.Close(); _way_tag_reader.Dispose(); _way_tag_reader = null; _current_type = OsmGeoType.Relation; return false; } }
private void BatchAddTags(List<Tuple<int, Tag>> tags, OsmGeoType type) { var i = 0; foreach (var tag in tags) { var key = tag.Item2.Key; var value = tag.Item2.Value; _replaceTagBatchCommands[type].Parameters[(i * 3) + 0].Value = tag.Item1; _replaceTagBatchCommands[type].Parameters[(i * 3) + 1].Value = key.Truncate(100); _replaceTagBatchCommands[type].Parameters[(i * 3) + 2].Value = value.Truncate(500); ++i; } _replaceTagBatchCommands[type].ExecuteNonQuery(); tags.Clear(); }
/// <summary> /// Initializes this source. /// </summary> public override void Initialize() { _current = null; _current_type = OsmGeoType.Node; _node_reader = null; }
/// <summary> /// Returns all relations that have the given object as a member. /// </summary> /// <param name="type"></param> /// <param name="id"></param> /// <returns></returns> public override IList<Relation> GetRelationsFor(OsmGeoType type, long id) { List<Relation> relations = new List<Relation>(); HashSet<long> relationIds = null; switch(type) { case OsmGeoType.Node: if (!_relationsPerNode.TryGetValue(id, out relationIds)) { return relations; } break; case OsmGeoType.Way: if (!_relationsPerWay.TryGetValue(id, out relationIds)) { return relations; } break; case OsmGeoType.Relation: if (!_relationsPerRelation.TryGetValue(id, out relationIds)) { return relations; } break; } foreach (long relationId in relationIds) { relations.Add(this.GetRelation(relationId)); } return relations; }
/// <summary> /// Resets this filter. /// </summary> public override void Reset() { _nodesIn.Clear(); _currentType = OsmGeoType.Node; this.Source.Reset(); }
/// <summary> /// Tries to get a way tags collection from the cache /// </summary> /// <param name="id">The id of the tags collection</param> /// <param name="collection">The collection to assign</param> /// <param name="type">The type of osm geo</param> /// <returns>True if successfully fetched, false otherwise</returns> public bool TryGetTagsCollection(int id, out TagsCollectionBase collection, OsmGeoType type) { lock (_locks[type]) { return _collections[type].TryGetValue(id, out collection); } }
/// <summary> /// Raises the chance event. /// </summary> /// <param name="type"></param> /// <param name="object_type"></param> /// <param name="id"></param> private void RaiseChange(ChangeType type, OsmGeoType object_type, long id) { if (Change != null) { Change(type, object_type, id); } }
private void FlushAddTags(List<Tuple<int, Tag>> tags, OsmGeoType type) { foreach (var tag in tags) { var key = tag.Item2.Key; var value = tag.Item2.Value; _replaceTagFlushCommands[type].Parameters[0].Value = tag.Item1; _replaceTagFlushCommands[type].Parameters[1].Value = key.Truncate(100); _replaceTagFlushCommands[type].Parameters[2].Value = value.Truncate(500); _replaceTagFlushCommands[type].ExecuteNonQuery(); } tags.Clear(); }
/// <summary> /// Returns true if the given object can be a routing restriction. /// </summary> /// <param name="type"></param> /// <param name="tags"></param> /// <returns></returns> public bool IsRestriction(OsmGeoType type, TagsCollectionBase tags) { // at least there need to be some tags. if (type == OsmGeoType.Relation) { // filter out relation-based turn-restrictions. if (tags != null && tags.ContainsKeyValue("type", "restriction")) { // yep, there's a restriction here! return true; } } else if(type == OsmGeoType.Node) { // a node is possibly a restriction too. if(tags != null) { return tags.ContainsKey("barrier"); } } return false; }
/// <summary> /// Returns all relations for the given object. /// </summary> /// <param name="type"></param> /// <param name="id"></param> /// <returns></returns> public override IList<Relation> GetRelationsFor(OsmGeoType type, long id) { IList<Relation> relations = _source.GetRelationsFor(type, id); foreach (Relation relation in relations) { _relationsCache.Add(relation.Id.Value, relation); } return relations; }
private bool DoMoveNextNode() { if (_node_reader == null) { SQLiteCommand node_command = new SQLiteCommand("select * from node left join node_tags on node_tags.node_id = node.id order by node.id"); node_command.Connection = _connection; _node_reader = node_command.ExecuteReader(); if (!_node_reader.Read()) _node_reader.Close(); } // read next node. if (!_node_reader.IsClosed) { // load/parse data. Node node = new Node(); node.Id = _node_reader.GetInt64(0); node.Latitude = _node_reader.GetInt64(1) / 10000000.0; node.Longitude = _node_reader.GetInt64(2) / 10000000.0; node.ChangeSetId = _node_reader.GetInt64(3); node.TimeStamp = _node_reader.GetDateTime(5); node.Version = (ulong)_node_reader.GetInt64(7); node.Visible = _node_reader.GetInt64(4) == 1; //node.UserName = _node_reader.GetString(8); //node.UserId = _node_reader.IsDBNull(9) ? -1 : _node_reader.GetInt64(9); //Has tags? if (!_node_reader.IsDBNull(10)) { //if (node.Tags == null) //node.Tags = new Dictionary<string, string>(); long currentnode = node.Id.Value; while (currentnode == node.Id.Value) { //string key = _node_reader.GetString(11); //string value = _node_reader.GetString(12); //node.Tags.Add(key, value); if (!_node_reader.Read()) { _node_reader.Close(); break; } currentnode = _node_reader.GetInt64(0); } } else if (!_node_reader.Read()) _node_reader.Close(); // set the current variable! _current = node; return true; } _node_reader.Close(); _node_reader.Dispose(); _node_reader = null; _current_type = OsmGeoType.Way; return false; }
/// <summary> /// Adds a collection to the cache /// </summary> /// <param name="id">The id of the tags collection</param> /// <param name="collection">The tags collection</param> /// <param name="type">The type of osm geo</param> public void AddTagsCollection(int id, TagsCollectionBase collection, OsmGeoType type) { if (collection == null) { throw new ArgumentNullException("collection"); } lock (_locks[type]) { _collections[type][id] = collection; } }
/// <summary> /// Initializes this source. /// </summary> public override void Initialize() { _connection = new SQLiteConnection(_connectionString); _connection.Open(); _current = null; _currentType = OsmGeoType.Node; _nodeReader = null; }
/// <summary> /// Resets this source. /// </summary> public override void Reset() { _current = null; _current_type = OsmGeoType.Node; if (_node_reader != null) { _node_reader.Close(); _node_reader.Dispose(); _node_reader = null; } }
/// <summary> /// Move to the next object. /// </summary> /// <returns></returns> private bool DoMoveNext() { if (this.Source.IsSorted || (_isSourceSorted.HasValue && _isSourceSorted.Value)) { // the source is already sorted. return this.Source.MoveNext(); } else { // leave it to this filter to sort this. if (this.Source.MoveNext()) { // make sure this object is of the correct type. bool finished = false; bool invalid = this.Current().Type != _currentType; while (this.Current().Type != _currentType) { // check if source is at the end. if (!this.Source.MoveNext()) { finished = true; break; } } if (invalid && !finished) { // an object was found but first another one was found. if (_currentType == OsmGeoType.Node) { // ok, this source is definetly not sorted. _isSourceSorted = false; } else if (_currentType == OsmGeoType.Way) { // the current type is way. if (!_firstWay) { // a way after a relation. _isSourceSorted = false; } _firstWay = false; } else if (_currentType == OsmGeoType.Relation) { // the current type is relation. if (!_firstRelation) { // a way after a relation. _isSourceSorted = false; } _firstRelation = false; } } if (!finished && this.Current().Type == _currentType) { return true; } } switch (_currentType) { case OsmGeoType.Node: this.Source.Reset(); _currentType = OsmGeoType.Way; return this.MoveNext(); case OsmGeoType.Way: this.Source.Reset(); _currentType = OsmGeoType.Relation; return this.MoveNext(); case OsmGeoType.Relation: if (!_isSourceSorted.HasValue) { // no invalid order was found. _isSourceSorted = true; } return false; } throw new InvalidOperationException("Unkown SimpleOsmGeoType"); } }
private bool DoMoveNextRelation() { if (_relation_reader == null) { var relationCommand = new SQLiteCommand("select * from relation order by id", _connection); _relation_reader = relationCommand.ExecuteReader(); if (!_relation_reader.Read()) { _relation_reader.Close(); } var relationTagCommand = new SQLiteCommand("select * from relation_tags order by relation_id", _connection); _relation_tag_reader = relationTagCommand.ExecuteReader(); if (!_relation_tag_reader.IsClosed && !_relation_tag_reader.Read()) { _relation_tag_reader.Close(); } var relationNodeCommand = new SQLiteCommand("select * from relation_members order by relation_id,sequence_id", _connection); _relation_member_reader = relationNodeCommand.ExecuteReader(); if (!_relation_member_reader.IsClosed && !_relation_member_reader.Read()) { _relation_member_reader.Close(); } } // read next relation. if (!_relation_reader.IsClosed) { // load/parse data. long id = _relation_reader.GetInt64(0); long changesetId = _relation_reader.GetInt64(1); bool visible = _relation_reader.GetInt64(2) == 1; DateTime timestamp = _relation_reader.IsDBNull(3) ? DateTime.MinValue : _relation_reader.GetDateTime(3); long version = _relation_reader.GetInt64(4); string user = _relation_reader.GetString(5); long uid = _relation_reader.GetInt64(6); var relation = new Relation { Id = id, ChangeSetId = changesetId, TimeStamp = timestamp, UserId = null, UserName = null, Version = (ulong)version, Visible = visible }; relation.UserName = user; relation.UserId = uid; if (!_relation_tag_reader.IsClosed) { long returnedId = _relation_tag_reader.GetInt64(0); while (returnedId == relation.Id.Value) { if (relation.Tags == null) { relation.Tags = new TagsCollection(); } string key = _relation_tag_reader.GetString(1); string value = _relation_tag_reader.GetString(2); relation.Tags.Add(key, value); if (!_relation_tag_reader.Read()) { _relation_tag_reader.Close(); returnedId = -1; } else { returnedId = _relation_tag_reader.GetInt64(0); } } } if (!_relation_member_reader.IsClosed) { long returnedId = _relation_member_reader.GetInt64(0); while (returnedId == relation.Id.Value) { if (relation.Members == null) { relation.Members = new List<RelationMember>(); } string memberType = _relation_member_reader.GetString(1); long memberId = _relation_member_reader.GetInt64(2); object memberRole = _relation_member_reader.GetValue(3); var member = new RelationMember(); member.MemberId = memberId; if (memberRole != DBNull.Value) { member.MemberRole = memberRole as string; } switch (memberType) { case "Node": member.MemberType = OsmGeoType.Node; break; case "Way": member.MemberType = OsmGeoType.Way; break; case "Relation": member.MemberType = OsmGeoType.Relation; break; } relation.Members.Add(member); if (!_relation_member_reader.Read()) { _relation_member_reader.Close(); returnedId = -1; } else { returnedId = _relation_member_reader.GetInt64(0); } } } // set the current variable! _current = relation; // advance the reader(s). if (!_relation_reader.Read()) { _relation_reader.Close(); } if (!_relation_tag_reader.IsClosed && !_relation_tag_reader.Read()) { _relation_tag_reader.Close(); } if (!_relation_member_reader.IsClosed && !_relation_member_reader.Read()) { _relation_member_reader.Close(); } return true; } else { _relation_reader.Close(); _relation_reader.Dispose(); _relation_reader = null; _relation_tag_reader.Close(); _relation_tag_reader.Dispose(); _relation_tag_reader = null; _current_type = OsmGeoType.Relation; return false; } }
public TagFilterNone(OsmGeoType type) { _type = type; }
/// <summary> /// Moves to the next object. /// </summary> /// <returns></returns> private bool DoMoveNext() { while (this.Source.MoveNext()) { // check the type and check if the source is sorted. var current = this.Source.Current(); switch (current.Type) { case OsmGeoType.Node: if(_currentType != OsmGeoType.Node) { // source is not sorted, a node appeared after a way/relation. throw new OsmStreamNotSortedException("OsmStreamFilterPoly - Source stream is not sorted."); } var node = current as Node; if(this.IsInsidePoly(node.Latitude.Value, node.Longitude.Value)) { // keep this node. _nodesIn.Add(node.Id.Value); return true; } break; case OsmGeoType.Way: if(_currentType == OsmGeoType.Relation) { // source is not sorted, a way appeared after a relation. throw new OsmStreamNotSortedException("OsmStreamFilterPoly - Source stream is not sorted."); } if(_currentType == OsmGeoType.Node) { // switch type to way. _currentType = OsmGeoType.Way; } var way = current as Way; if(way.Nodes != null) { for(var i = 0; i < way.Nodes.Count; i++) { if(_nodesIn.Contains(way.Nodes[i])) { _waysIn.Add(way.Id.Value); return true; } } } break; case OsmGeoType.Relation: if (_currentType == OsmGeoType.Way || _currentType == OsmGeoType.Node) { // switch type to way. _currentType = OsmGeoType.Relation; } var relation = current as Relation; if(relation.Members != null) { for(var i = 0; i < relation.Members.Count; i++) { var member = relation.Members[i]; switch(member.MemberType.Value) { case OsmGeoType.Node: if(_nodesIn.Contains(member.MemberId.Value)) { return true; } break; case OsmGeoType.Way: if(_waysIn.Contains(member.MemberId.Value)) { return true; } break; } } } break; } } return false; }
/// <summary> /// Removes a relation tags collection from the cache /// </summary> /// <param name="id">The given id to remove from the cache</param> /// <param name="type">The type of osm geo</param> /// <returns>True if the entry was removed, false if not</returns> public bool RemoveTagsCollection(int id, OsmGeoType type) { lock (_locks[type]) { return _collections[type].Remove(id); } }
/// <summary> /// Resets this filter. /// </summary> public override void Reset() { _currentType = OsmGeoType.Node; this.Source.Reset(); }
public override TagsCollectionBase Evaluate(TagsCollectionBase tags, OsmGeoType type) { if (tags == null) { throw new ArgumentNullException("tags"); } if (type == _type) { return tags.KeepKeysOf(_keys); } return TagsCollectionBase.Empty; }