/// <summary> /// Returns true if the object passes through this filter. /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Evaluate(SimpleOsmGeo obj) { string value; if (obj.Tags != null && obj.Tags.TryGetValue(_key, out value)) { return value == _value; } return false; }
private bool MoveNextRelation() { if (_relation_reader == null) { OracleCommand relation_command = new OracleCommand("select * from relation order by id"); relation_command.Connection = _connection; _relation_reader = relation_command.ExecuteReader(); if (!_relation_reader.Read()) { _relation_reader.Close(); } OracleCommand relation_tag_command = new OracleCommand("select * from relation_tags order by relation_id"); relation_tag_command.Connection = _connection; _relation_tag_reader = relation_tag_command.ExecuteReader(); if (!_relation_tag_reader.IsClosed && !_relation_tag_reader.Read()) { _relation_tag_reader.Close(); } OracleCommand relation_node_command = new OracleCommand("select * from relation_members order by relation_id,sequence_id"); relation_node_command.Connection = _connection; _relation_member_reader = relation_node_command.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 changeset_id = _relation_reader.GetInt64(1); DateTime timestamp = _relation_reader.GetDateTime(2); bool visible = _relation_reader.GetInt64(3) == 1; long version = _relation_reader.GetInt64(4); string user = _relation_reader.GetString(5); long uid = _relation_reader.GetInt64(6); SimpleRelation relation = new SimpleRelation(); relation.Id = id; relation.ChangeSetId = changeset_id; relation.TimeStamp = timestamp; relation.UserId = null; relation.UserName = null; relation.Version = (ulong)version; relation.Visible = visible; relation.UserName = user; relation.UserId = uid; if (!_relation_tag_reader.IsClosed) { long returned_id = _relation_tag_reader.GetInt64(0); while (returned_id == relation.Id.Value) { if (relation.Tags == null) { relation.Tags = new Dictionary<string, string>(); } 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(); returned_id = -1; } else { returned_id = _relation_tag_reader.GetInt64(0); } } } if (!_relation_member_reader.IsClosed) { long returned_id = _relation_member_reader.GetInt64(0); while (returned_id == relation.Id.Value) { if (relation.Members == null) { relation.Members = new List<SimpleRelationMember>(); } string member_type = _relation_member_reader.GetString(1); long member_id = _relation_member_reader.GetInt64(2); object member_role = _relation_member_reader.GetValue(3); SimpleRelationMember member = new SimpleRelationMember(); member.MemberId = member_id; if (member_role != DBNull.Value) { member.MemberRole = member_role as string; } switch (member_type) { case "Node": member.MemberType = SimpleRelationMemberType.Node; break; case "Way": member.MemberType = SimpleRelationMemberType.Way; break; case "Relation": member.MemberType = SimpleRelationMemberType.Relation; break; } relation.Members.Add(member); if (!_relation_member_reader.Read()) { _relation_member_reader.Close(); returned_id = -1; } else { returned_id = _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 = SimpleOsmGeoType.Relation; return false; } }
private bool MoveNextNode() { if (_node_reader == null) { OracleCommand node_command = new OracleCommand("select * from node order by id"); node_command.Connection = _connection; _node_reader = node_command.ExecuteReader(); if (!_node_reader.Read()) { _node_reader.Close(); } OracleCommand node_tag_command = new OracleCommand("select * from node_tags order by node_id"); node_tag_command.Connection = _connection; _node_tag_reader = node_tag_command.ExecuteReader(); if (!_node_tag_reader.Read()) { _node_tag_reader.Close(); } } // read next node. if (!_node_reader.IsClosed) { // load/parse data. long id = _node_reader.GetInt64(0); long latitude_int = _node_reader.GetInt64(1); long longitude_int = _node_reader.GetInt64(2); long changeset_id = _node_reader.GetInt64(3); bool visible = _node_reader.GetInt64(4) == 1; DateTime timestamp = _node_reader.GetDateTime(5); long tile = _node_reader.GetInt64(6); long version = _node_reader.GetInt64(7); string user = _node_reader.GetString(8); long uid = _node_reader.GetInt64(9); SimpleNode node = new SimpleNode(); node.Id = id; node.Latitude = latitude_int; node.Longitude = longitude_int; node.ChangeSetId = changeset_id; node.TimeStamp = timestamp; node.UserId = null; node.UserName = null; node.Version = (ulong)version; node.Visible = visible; node.UserName = user; node.UserId = uid; if (!_node_tag_reader.IsClosed) { long returned_id = _node_tag_reader.GetInt64(0); while (returned_id == node.Id.Value) { if (node.Tags == null) { node.Tags = new Dictionary<string, string>(); } string key = _node_tag_reader.GetString(1); string value = _node_tag_reader.GetString(2); node.Tags.Add(key, value); if (!_node_tag_reader.Read()) { _node_tag_reader.Close(); } returned_id = _node_tag_reader.GetInt64(0); } } // set the current variable! _current = node; // advance the reader(s). if (!_node_reader.Read()) { _node_reader.Close(); } if (!_node_tag_reader.IsClosed && !_node_tag_reader.Read()) { _node_tag_reader.Close(); } return true; } else { _node_reader.Close(); _node_reader.Dispose(); _node_reader = null; _node_tag_reader.Close(); _node_tag_reader.Dispose(); _node_tag_reader = null; _current_type = SimpleOsmGeoType.Way; return false; } }
/// <summary> /// Resets the current source. /// </summary> public override void Reset() { _current = null; _current_type = SimpleOsmGeoType.Node; if (_node_reader != null) { _node_reader.Close(); _node_reader.Dispose(); _node_reader = null; } if (_node_tag_reader != null) { _node_tag_reader.Close(); _node_tag_reader.Dispose(); _node_tag_reader = null; } }
/// <summary> /// Returns true if the object passed through the filter. /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Evaluate(SimpleOsmGeo obj) { return obj.Tags.ContainsKey(_tag); }
/// <summary> /// Moves this source to the next object. /// </summary> /// <returns></returns> public override bool MoveNext() { while (_reader.Read()) { if (_reader.NodeType == XmlNodeType.Element && (_reader.Name == "node" || _reader.Name == "way" || _reader.Name == "relation")) { // create a stream for only this element. string name = _reader.Name; string next_element = _reader.ReadOuterXml(); XmlReader reader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(next_element))); object osm_obj = null; // select type of element. switch (name) { case "node": osm_obj = _ser_node.Deserialize(reader); if (osm_obj is OsmSharp.Osm.Xml.v0_6.node) { _next = XmlSimpleConverter.ConvertToSimple(osm_obj as OsmSharp.Osm.Xml.v0_6.node); return true; } break; case "way": osm_obj = _ser_way.Deserialize(reader); if (osm_obj is OsmSharp.Osm.Xml.v0_6.way) { _next = XmlSimpleConverter.ConvertToSimple(osm_obj as OsmSharp.Osm.Xml.v0_6.way); return true; } break; case "relation": osm_obj = _ser_relation.Deserialize(reader); if (osm_obj is OsmSharp.Osm.Xml.v0_6.relation) { _next = XmlSimpleConverter.ConvertToSimple(osm_obj as OsmSharp.Osm.Xml.v0_6.relation); return true; } break; } } } _next = null; return false; }
/// <summary> /// Resetting this data source /// </summary> public override void Reset() { _current = null; _stream.Seek(0, SeekOrigin.Begin); }
/// <summary> /// Moves to the next object. /// </summary> /// <returns></returns> public override bool MoveNext() { if (!_relationKeepObjects && !_wayKeepNodes) { // simple here just filter! bool filter_ok = false; while (!filter_ok) { if (this.Source.MoveNext()) { SimpleOsmGeo current = this.Source.Current(); switch (current.Type) { case SimpleOsmGeoType.Node: if (_nodesFilter == null || _nodesFilter.Evaluate(current)) { _current = current; return true; } break; case SimpleOsmGeoType.Way: if (_waysFilter == null || _waysFilter.Evaluate(current)) { _current = current; return true; } break; case SimpleOsmGeoType.Relation: if (_relationsFilter == null || _relationsFilter.Evaluate(current)) { _current = current; return true; } break; } } else { // there is no more data in the source! return false; } } } return false; }
/// <summary> /// Resets this filter. /// </summary> public override void Reset() { _current = null; this.Source.Reset(); }
/// <summary> /// Returns true if this object pass through this filter. /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Evaluate(SimpleOsmGeo obj) { return obj.Type == _type; }
/// <summary> /// Evaluates the filter against the osm object. /// </summary> /// <param name="obj"></param> /// <returns></returns> public abstract bool Evaluate(SimpleOsmGeo obj);
private bool MoveNextWay() { if (_wayReader == null) { SQLiteCommand way_command = new SQLiteCommand("select * from way where id > 26478817 order by id"); way_command.Connection = _connection; _wayReader = way_command.ExecuteReader(); if (!_wayReader.Read()) { _wayReader.Close(); } SQLiteCommand way_tag_command = new SQLiteCommand("select * from way_tags where way_id > 26478817 order by way_id"); way_tag_command.Connection = _connection; _wayTagReader = way_tag_command.ExecuteReader(); if (!_wayTagReader.IsClosed && !_wayTagReader.Read()) { _wayTagReader.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; _wayNodeReader = way_node_command.ExecuteReader(); if (!_wayNodeReader.IsClosed && !_wayNodeReader.Read()) { _wayNodeReader.Close(); } } // read next way. if (!_wayReader.IsClosed) { SimpleWay way = new SimpleWay(); way.Id = _wayReader.GetInt64(0); way.ChangeSetId = _wayReader.GetInt64(1); way.TimeStamp = _wayReader.IsDBNull(3) ? DateTime.MinValue : _wayReader.GetDateTime(3); //way.UserId = _way_reader.GetInt64(6); //way.UserName = _way_reader.GetString(5); way.Version = (ulong)_wayReader.GetInt64(4); way.Visible = _wayReader.GetInt64(2) == 1; if (!_wayTagReader.IsClosed) { long returned_id = _wayTagReader.GetInt64(_wayTagReader.GetOrdinal("way_id")); while (returned_id == way.Id.Value) { if (way.Tags == null) { way.Tags = new Dictionary<string, string>(); } string key = _wayTagReader.GetString(1); string value = _wayTagReader.GetString(2); way.Tags.Add(key, value); if (!_wayTagReader.Read()) { _wayTagReader.Close(); returned_id = -1; } else { returned_id = _wayTagReader.GetInt64(0); } } } if (!_wayNodeReader.IsClosed) { long returned_id = _wayNodeReader.GetInt64(_wayNodeReader.GetOrdinal("way_id")); while (returned_id == way.Id.Value) { if (way.Nodes == null) { way.Nodes = new List<long>(); } long node_id = _wayNodeReader.GetInt64(1); way.Nodes.Add(node_id); if (!_wayNodeReader.Read()) { _wayNodeReader.Close(); returned_id = -1; } else { returned_id = _wayNodeReader.GetInt64(0); } } } // set the current variable! _current = way; // advance the reader(s). if (!_wayReader.Read()) { _wayReader.Close(); } if (!_wayTagReader.IsClosed && !_wayTagReader.Read()) { _wayTagReader.Close(); } if (!_wayNodeReader.IsClosed && !_wayNodeReader.Read()) { _wayNodeReader.Close(); } return true; } else { _wayReader.Close(); _wayReader.Dispose(); _wayReader = null; _wayTagReader.Close(); _wayTagReader.Dispose(); _wayTagReader = null; _currentType = SimpleOsmGeoType.Relation; return false; } }
private bool MoveNextNode() { if (_nodeReader == 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; _nodeReader = node_command.ExecuteReader(); if (!_nodeReader.Read()) _nodeReader.Close(); } // read next node. if (!_nodeReader.IsClosed) { // load/parse data. SimpleNode node = new SimpleNode(); node.Id = _nodeReader.GetInt64(0); node.Latitude = _nodeReader.GetInt64(1)/10000000.0; node.Longitude = _nodeReader.GetInt64(2)/10000000.0; node.ChangeSetId = _nodeReader.GetInt64(3); node.TimeStamp = _nodeReader.GetDateTime(5); node.Version = (ulong) _nodeReader.GetInt64(7); node.Visible = _nodeReader.GetInt64(4) == 1; //node.UserName = _node_reader.GetString(8); //node.UserId = _node_reader.IsDBNull(9) ? -1 : _node_reader.GetInt64(9); //Has tags? if (!_nodeReader.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 (!_nodeReader.Read()) { _nodeReader.Close(); break; } currentnode = _nodeReader.GetInt64(0); } }else if (!_nodeReader.Read()) _nodeReader.Close(); // set the current variable! _current = node; return true; } _nodeReader.Close(); _nodeReader.Dispose(); _nodeReader = null; _currentType = SimpleOsmGeoType.Way; return false; }
/// <summary> /// Initializes this source. /// </summary> public override void Initialize() { _connection = new SQLiteConnection(_connectionString); _connection.Open(); _current = null; _currentType = SimpleOsmGeoType.Node; _nodeReader = null; }
private bool MoveNextWay() { if (_way_reader == null) { OracleCommand way_command = new OracleCommand("select * from way order by id"); way_command.Connection = _connection; _way_reader = way_command.ExecuteReader(); if (!_way_reader.Read()) { _way_reader.Close(); } OracleCommand way_tag_command = new OracleCommand("select * from way_tags 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(); } OracleCommand way_node_command = new OracleCommand("select * from way_nodes 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) { // load/parse data. long id = _way_reader.GetInt64(0); long changeset_id = _way_reader.GetInt64(1); DateTime timestamp = _way_reader.GetDateTime(2); bool visible = _way_reader.GetInt64(3) == 1; long version = _way_reader.GetInt64(4); string user = _way_reader.GetString(5); long uid = _way_reader.GetInt64(6); SimpleWay way = new SimpleWay(); way.Id = id; way.ChangeSetId = changeset_id; way.TimeStamp = timestamp; way.UserId = uid; way.UserName = user; way.Version = (ulong)version; way.Visible = visible; 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 Dictionary<string, string>(); } 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 = SimpleOsmGeoType.Relation; return false; } }
/// <summary> /// Returns true if this object pass through this filter. /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Evaluate(SimpleOsmGeo obj) { switch (_op) { case FilterCombineOperatorEnum.And: return _filter1.Evaluate(obj) && _filter2.Evaluate(obj); case FilterCombineOperatorEnum.Or: return _filter1.Evaluate(obj) || _filter2.Evaluate(obj); case FilterCombineOperatorEnum.Not: return !_filter1.Evaluate(obj); } return false; }
/// <summary> /// Initialiers this oracle source. /// </summary> public override void Initialize() { _connection = new OracleConnection(_connection_string); _connection.Open(); _current = null; _current_type = SimpleOsmGeoType.Node; _node_reader = null; _node_tag_reader = null; }
/// <summary> /// Initializes this source. /// </summary> public override void Initialize() { _next = null; _ser_node = new XmlSerializer(typeof(Osm.Xml.v0_6.node)); _ser_way = new XmlSerializer(typeof(Osm.Xml.v0_6.way)); _ser_relation = new XmlSerializer(typeof(Osm.Xml.v0_6.relation)); this.Reset(); }
/// <summary> /// Returns true if the given object is relevant in the bounding box. /// </summary> /// <param name="osm_geo"></param> /// <returns></returns> private bool IsInBB(SimpleOsmGeo osm_geo) { bool is_in = false; switch (osm_geo.Type) { case SimpleOsmGeoType.Node: is_in = _box.IsInside(new GeoCoordinate( (osm_geo as SimpleNode).Latitude.Value, (osm_geo as SimpleNode).Longitude.Value)); break; case SimpleOsmGeoType.Way: foreach (long node_id in (osm_geo as SimpleWay).Nodes) { if (_nodes_in.Contains(node_id)) { is_in = true; break; } } if (is_in) { foreach (long node_id in (osm_geo as SimpleWay).Nodes) { _nodes_to_include.Add(node_id); } } break; case SimpleOsmGeoType.Relation: if (!_relations_considered.Contains(osm_geo.Id.Value)) { foreach (SimpleRelationMember member in (osm_geo as SimpleRelation).Members) { switch (member.MemberType.Value) { case SimpleRelationMemberType.Node: if (_nodes_in.Contains(member.MemberId.Value)) { is_in = true; break; } break; case SimpleRelationMemberType.Way: if (_ways_in.Contains(member.MemberId.Value)) { is_in = true; break; } break; case SimpleRelationMemberType.Relation: if (_relation_in.Contains(member.MemberId.Value)) { is_in = true; break; } break; } } if (is_in) { foreach (SimpleRelationMember member in (osm_geo as SimpleRelation).Members) { switch (member.MemberType.Value) { case SimpleRelationMemberType.Node: _nodes_to_include.Add(member.MemberId.Value); break; case SimpleRelationMemberType.Way: _ways_to_include.Add(member.MemberId.Value); break; case SimpleRelationMemberType.Relation: _relations_to_include.Add(member.MemberId.Value); break; } } } } break; } return is_in; }
/// <summary> /// Moves to the next object. /// </summary> /// <returns></returns> public override bool MoveNext() { KeyValuePair<PrimitiveBlock, object> next_pbf_primitive = this.MoveToNextPrimitive(); if (next_pbf_primitive.Value != null) { // there is a primitive. _current = this.Convert(next_pbf_primitive); return true; } return false; }