Ejemplo n.º 1
0
        public static OsmWay ConvertTo(SimpleWay way, List<long> nodes)
        {
            OsmWay new_way = new OsmWay();
            new_way.Id = way.Id.Value;
            new_way.Nds = nodes;
            new_way.Tags = PrimitiveExtensions.ConvertTo(way.Tags);

            return new_way;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Updates a way.
 /// </summary>
 /// <param name="way"></param>
 public void UpdateWay(SimpleWay way)
 {
     _ways[way.Id.Value] = way;
 }
        public override void AddWay(SimpleWay way)
        {
            DataRow way_row = _way_table.NewRow();

            // format data and create parameters.
            long? id = way.Id.Value; // id should always contain a value.
            way_row["id"] = id.ConvertToDBValue<long>();

            long? changeset_id = way.ChangeSetId;
            way_row["changeset_id"] = changeset_id.ConvertToDBValue<long>();

            bool? visible = way.Visible;
            int visible_int = 1;
            if (!visible.HasValue || !visible.Value)
            {
                visible_int = 0;
            }
            way_row["visible"] = visible_int;

            DateTime? timestamp = way.TimeStamp;
            way_row["timestamp"] = timestamp.ConvertToDBValue<DateTime>();

            ulong? version = way.Version;
            way_row["version"] = version.ConvertToDBValue<ulong>();

            // set the usr
            way_row["usr"] = way.UserName.ToStringEmptyWhenNull();
            way_row["usr_id"] = way.UserId.ConvertToDBValue<long>();

            // add the way and it's tags.
            _way_table.Rows.Add(way_row);

            // tags.
            if (way.Tags != null)
            {
                foreach (KeyValuePair<string, string> tag in way.Tags)
                {
                    string key = tag.Key;
                    string value = tag.Value;

                    if (key == null || key.Length == 0)
                    {
                        //throw new Exception();
                    }
                    else
                    {
                        DataRow tag_row = _way_tags_table.NewRow();
                        tag_row["way_id"] = id;
                        tag_row["key"] = key.Truncate(255);
                        tag_row["value"] = value.Truncate(255);

                        _way_tags_table.Rows.Add(tag_row);
                    }
                }
            }

            // insert way nodes.
            if (way.Nodes != null)
            {
                long way_id = way.Id.Value;
                for (int idx = 0; idx < way.Nodes.Count; idx++)
                {
                    long node_id = way.Nodes[idx];

                    DataRow tag_row = _way_nodes_table.NewRow();
                    tag_row["way_id"] = id;
                    tag_row["node_id"] = node_id;
                    tag_row["sequence_id"] = idx;

                    _way_nodes_table.Rows.Add(tag_row);
                }
            }

            // bulk insert if needed.
            if (_way_table.Rows.Count >= _batch_ways)
            {
                this.BulkCopy(_way_table, "way");
                this.BulkCopy(_way_tags_table, "way_tags");
                this.BulkCopy(_way_nodes_table, "way_nodes");
                this.CreateWayTables();
            }
        }
        /// <summary>
        /// Modifies the given way.
        /// </summary>
        /// <param name="way"></param>
        private void Modify(SimpleWay way)
        {
            OracleCommand command;

            string sql = string.Empty;

            DateTime? timestamp = way.TimeStamp;
            if (timestamp.HasValue)
            {
                sql = "update way set changeset_id=:changeset_id,visible=:visible,timestamp=to_date('{0}','YYYY/MM/DD HH24:MI'),version=:version, usr=:usr, usr_id=:usr_id where id = :id";
                sql = string.Format(sql, timestamp.Value.ToString("yyyy/MM/dd HH:mm"));
            }
            else
            {
                sql = "update way set changeset_id=:changeset_id,visible=:visible,timestamp=null,version=:version where id = :id";
            }
            command = this.CreateCommand(sql);

            // format data and create parameters.
            long? id = way.Id;
            command.Parameters.Add(new OracleParameter("id", id.ConvertToDBValue<long>()));

            long? changeset_id = way.ChangeSetId;
            command.Parameters.Add(new OracleParameter("changeset_id", changeset_id.ConvertToDBValue<long>()));

            bool? visible = way.Visible;
            int visible_int = 1;
            if (!visible.HasValue || !visible.Value)
            {
                visible_int = 0;
            }
            command.Parameters.Add("visible", visible_int);

            long? version = (long)way.Version;
            command.Parameters.Add(new OracleParameter("version", version.ConvertToDBValue<long>()));

            command.Parameters.Add("usr", way.UserName);
            command.Parameters.Add("usr_id", way.UserId);

            command.ExecuteNonQuery();
            command.Dispose();
            if (this.Exists("way", way.Id.Value))
            {
                // update tags.
                this.ModifyTags(way.Id.Value, way.Tags, "way_tags", "way_id");

                // modify nodes.
                this.ModifyWayNodes(way.Id.Value, way.Nodes);
            }

            // raise the modified event.
            this.RaiseChange(SimpleChangeType.Modify, SimpleOsmGeoType.Way, way.Id.Value);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Converts simple primitives.
        /// </summary>
        /// <param name="pbf_primitive"></param>
        /// <returns></returns>
        internal SimpleOsmGeo Convert(KeyValuePair<PrimitiveBlock, object> pbf_primitive)
        {
            if (pbf_primitive.Value == null || pbf_primitive.Key == null)
            {
                throw new ArgumentNullException("pbf_primitive");
            }

            PrimitiveBlock block = pbf_primitive.Key; // get the block properties this object comes from.
            if (pbf_primitive.Value is Node)
            {
                Node node = (pbf_primitive.Value as Node);
                SimpleNode simple_node = new SimpleNode();
                simple_node.ChangeSetId = node.info.changeset;
                simple_node.Id = node.id;
                simple_node.Latitude = .000000001 * ((double)block.lat_offset
                    + ((double)block.granularity * (double)node.lat));
                simple_node.Longitude = .000000001 * ((double)block.lon_offset
                    + ((double)block.granularity * (double)node.lon));
                simple_node.Tags = new Dictionary<string, string>();
                for (int tag_idx = 0; tag_idx < node.keys.Count; tag_idx++)
                {
                    string key = ASCIIEncoding.ASCII.GetString(block.stringtable.s[(int)node.keys[tag_idx]]);
                    string value = ASCIIEncoding.ASCII.GetString(block.stringtable.s[(int)node.vals[tag_idx]]);

                    if (!simple_node.Tags.ContainsKey(key))
                    {
                        simple_node.Tags.Add(new KeyValuePair<string, string>(key, value));
                    }
                }
                simple_node.TimeStamp = OsmSharp.Tools.Utilities.FromUnixTime((long)node.info.timestamp *
                    (long)block.date_granularity);
                simple_node.Visible = true;
                simple_node.Version = (uint)node.info.version;
                simple_node.UserId = node.info.uid;
                simple_node.UserName = ASCIIEncoding.ASCII.GetString(block.stringtable.s[node.info.user_sid]);
                simple_node.Version = (ulong)node.info.version;
                simple_node.Visible = true;

                return simple_node;
            }
            else if (pbf_primitive.Value is Way)
            {
                Way way = (pbf_primitive.Value as Way);

                SimpleWay simple_way = new SimpleWay();
                simple_way.Id = way.id;
                simple_way.Nodes = new List<long>(way.refs.Count);
                long node_id = 0;
                for (int node_idx = 0; node_idx < way.refs.Count; node_idx++)
                {
                    node_id = node_id + way.refs[node_idx];
                    simple_way.Nodes.Add(node_id);
                }
                simple_way.Tags = new Dictionary<string, string>();
                for (int tag_idx = 0; tag_idx < way.keys.Count; tag_idx++)
                {
                    string key = ASCIIEncoding.ASCII.GetString(block.stringtable.s[(int)way.keys[tag_idx]]);
                    string value = ASCIIEncoding.ASCII.GetString(block.stringtable.s[(int)way.vals[tag_idx]]);

                    if (!simple_way.Tags.ContainsKey(key))
                    {
                        simple_way.Tags.Add(new KeyValuePair<string, string>(key, value));
                    }
                }
                if (way.info != null)
                { // add the metadata if any.
                    simple_way.ChangeSetId = way.info.changeset;
                    simple_way.TimeStamp = OsmSharp.Tools.Utilities.FromUnixTime((long)way.info.timestamp *
                        (long)block.date_granularity);
                    simple_way.UserId = way.info.uid;
                    simple_way.UserName = ASCIIEncoding.ASCII.GetString(block.stringtable.s[way.info.user_sid]);
                    simple_way.Version = (ulong)way.info.version;
                }
                simple_way.Visible = true;

                return simple_way;
            }
            else if (pbf_primitive.Value is Relation)
            {
                Relation relation = (pbf_primitive.Value as Relation);

                SimpleRelation simple_relation = new SimpleRelation();
                simple_relation.Id = relation.id;
                simple_relation.Members = new List<SimpleRelationMember>();
                long member_id = 0;
                for (int member_idx = 0; member_idx < relation.types.Count; member_idx++)
                {
                    member_id = member_id + relation.memids[member_idx];
                    string role = ASCIIEncoding.ASCII.GetString(
                        block.stringtable.s[relation.roles_sid[member_idx]]);
                    SimpleRelationMember member = new SimpleRelationMember();
                    member.MemberId = member_id;
                    member.MemberRole = role;
                    switch(relation.types[member_idx])
                    {
                        case Relation.MemberType.NODE:
                            member.MemberType = SimpleRelationMemberType.Node;
                            break;
                        case Relation.MemberType.WAY:
                            member.MemberType = SimpleRelationMemberType.Way;
                            break;
                        case Relation.MemberType.RELATION:
                            member.MemberType = SimpleRelationMemberType.Relation;
                            break;
                    }

                    simple_relation.Members.Add(member);
                }
                simple_relation.Tags = new Dictionary<string, string>();
                for (int tag_idx = 0; tag_idx < relation.keys.Count; tag_idx++)
                {
                    string key = ASCIIEncoding.ASCII.GetString(block.stringtable.s[(int)relation.keys[tag_idx]]);
                    string value = ASCIIEncoding.ASCII.GetString(block.stringtable.s[(int)relation.vals[tag_idx]]);

                    if (!simple_relation.Tags.ContainsKey(key))
                    {
                        simple_relation.Tags.Add(new KeyValuePair<string, string>(key, value));
                    }
                }
                if (relation.info != null)
                { // read metadata if any.
                    simple_relation.ChangeSetId = relation.info.changeset;
                    simple_relation.TimeStamp = OsmSharp.Tools.Utilities.FromUnixTime((long)relation.info.timestamp *
                        (long)block.date_granularity);
                    simple_relation.UserId = relation.info.uid;
                    simple_relation.UserName = ASCIIEncoding.ASCII.GetString(block.stringtable.s[relation.info.user_sid]);
                    simple_relation.Version = (ulong)relation.info.version;
                }
                simple_relation.Visible = true;

                return simple_relation;
            }
            throw new Exception(string.Format("PBF primitive with type {0} not supported!",
                pbf_primitive.GetType().ToString()));
        }
Ejemplo n.º 6
0
        public void init()
        {
            // initialize the connection.
            APIConnection api_instance = new APIConnection(
            "http://api06.dev.openstreetmap.org/",
            "osmsharp", "osmsharp");

            // open a changeset.
            long changeset_id = api_instance.ChangeSetOpen("An example comment!");

            // initialize the nodes.
            SimpleNode node1 = new SimpleNode();
            node1.Latitude = -0.494497;
            node1.Longitude = -24.119325;
            node1.Tags = new Dictionary<string, string>();
            node1.Tags.Add("type", "testnode1");
            node1.Visible = true;
            node1 = api_instance.NodeCreate(node1); // create
            SimpleNode node2 = new SimpleNode();
            node2.Latitude = -0.494497 + 0.0001f;
            node2.Longitude = -24.119325 + 0.0001f;
            node2.Tags = new Dictionary<string, string>();
            node2.Tags.Add("type", "testnode2");
            node2.Visible = true;
            node2 = api_instance.NodeCreate(node2); // create

            // initialize the way.
            SimpleWay way = new SimpleWay();
            way.Tags = new Dictionary<string, string>();
            way.Tags.Add("type", "testway");
            way.Nodes = new List<long>();
            way.Visible = true;
            way.Nodes.Add(node1.Id.Value);
            way.Nodes.Add(node2.Id.Value);
            way = api_instance.WayCreate(way); // create

            // initialize the relation.
            SimpleRelation relation = new SimpleRelation();
            relation.Tags = new Dictionary<string, string>();
            relation.Tags.Add("type", "testrelation");
            relation.Members = new List<SimpleRelationMember>();
            relation.Visible = true;
            relation.Members.Add(new SimpleRelationMember()
            {
                MemberId = node1.Id.Value,
                MemberRole = "some_nodes_role",
                MemberType = SimpleRelationMemberType.Node
            });
            relation.Members.Add(new SimpleRelationMember()
            {
                MemberId = node2.Id.Value,
                MemberRole = "some_nodes_role",
                MemberType = SimpleRelationMemberType.Node
            });
            relation.Members.Add(new SimpleRelationMember()
            {
                MemberId = way.Id.Value,
                MemberRole = "some_ways_role",
                MemberType = SimpleRelationMemberType.Way
            });

            // save the relation.
            relation = api_instance.RelationCreate(relation);

            // close the changeset.
            api_instance.ChangeSetClose();
        }
 /// <summary>
 /// Adds a way.
 /// </summary>
 /// <param name="way"></param>
 public override void AddWay(SimpleWay way)
 {
 }
Ejemplo n.º 8
0
        internal static SimpleWay ConvertToSimple(Osm.Xml.v0_6.way wa)
        {
            SimpleWay way = new SimpleWay();

            // set id
            if (wa.idSpecified)
            {
                way.Id = wa.id;
            }

            // set changeset.
            if (wa.changesetSpecified)
            {
                way.ChangeSetId = wa.changeset;
            }

            // set visible.
            if (wa.visibleSpecified)
            {
                way.Visible = wa.visible;
            }
            else
            { // if visible is not specified it is default true.
                way.Visible = true;
            }

            // set timestamp.
            if (wa.timestampSpecified)
            {
                way.TimeStamp = wa.timestamp;
            }

            // set uid
            if (wa.uidSpecified)
            {
                way.UserId = wa.uid;
            }

            // set version
            if (wa.versionSpecified)
            {
                way.Version = wa.version;
            }

            // set user
            way.UserName = wa.user;

            // set tags.
            way.Tags = XmlSimpleConverter.ConvertToTags(wa.tag);

            // set nodes.
            if (wa.nd != null && wa.nd.Length > 0)
            {
                way.Nodes = new List<long>();
                for (int idx = 0; idx < wa.nd.Length; idx++)
                {
                    way.Nodes.Add(wa.nd[idx].@ref);
                }
            }

            return way;
        }
Ejemplo n.º 9
0
        public void APITestWayCreateGet()
        {
            // intialize the connection.
            APIConnection api_instance = new APIConnection("http://api06.dev.openstreetmap.org/",
                "osmsharp", "osmsharp");

            // open a changeset.
            long changeset_id = api_instance.ChangeSetOpen("Simple Way Creation Test");

            // initialize the way.
            SimpleWay way = new SimpleWay();
            way.Tags = new Dictionary<string, string>();
            way.Tags.Add("type", "testway");
            way.Nodes = new List<long>();
            way.Visible = true;

            // initialize the nodes.
            SimpleNode node = new SimpleNode();
            node.Latitude = -0.494497;
            node.Longitude = -24.119325;
            node.Tags = new Dictionary<string, string>();
            node.Tags.Add("type", "testnode1");
            node.Visible = true;
            node = api_instance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);
            node = new SimpleNode();
            node.Latitude = -0.494497 + 0.0001f;
            node.Longitude = -24.119325 + 0.0001f;
            node.Tags = new Dictionary<string, string>();
            node.Tags.Add("type", "testnode2");
            node.Visible = true;
            node = api_instance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);

            // save the way.
            way = api_instance.WayCreate(way);

            // close the changeset.
            api_instance.ChangeSetClose();

            // check if the id now has a value.
            Assert.IsTrue(way.Id.HasValue);

            // get the new way id.
            long way_id = way.Id.Value;

            // get the way from the api.
            SimpleWay way_api = api_instance.WayGet(way.Id.Value);
            Assert.AreEqual(way_id, way_api.Id.Value);
            Assert.AreEqual(way.Tags.Count, way_api.Tags.Count);
            Assert.AreEqual(way.Visible, way_api.Visible);
            Assert.IsTrue(way_api.ChangeSetId.HasValue);
            Assert.AreEqual(changeset_id, way_api.ChangeSetId.Value);
            Assert.AreEqual(way.Nodes[0], way_api.Nodes[0]);
            Assert.AreEqual(way.Nodes[1], way_api.Nodes[1]);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Converts this relation into it's simple counterpart.
        /// </summary>
        /// <returns></returns>
        public override SimpleOsmGeo ToSimple()
        {
            SimpleWay way = new SimpleWay();
            way.Id = this.Id;
            way.ChangeSetId = this.ChangeSetId;
            way.Tags = this.Tags;
            way.TimeStamp = this.TimeStamp;
            way.UserId = this.UserId;
            way.UserName = this.User;
            way.Version = (ulong?)this.Version;
            way.Visible = this.Visible;

            way.Nodes = new List<long>();
            foreach (Node node in this.Nodes)
            {
                way.Nodes.Add(node.Id);
            }
            return way;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Converts an API v6 xml node to a SimpleWay object.
        /// </summary>
        /// <param name="xml_way"></param>
        /// <returns></returns>
        private SimpleWay Convertv6XmlWay(way xml_way)
        {
            SimpleWay way = new SimpleWay();
            way.Id = xml_way.id;

            if (xml_way.tag != null)
            {
                way.Tags = new Dictionary<string, string>();
                foreach (Osm.Xml.v0_6.tag xml_tag in xml_way.tag)
                {
                    way.Tags.Add(xml_tag.k, xml_tag.v);
                }
            }

            if (xml_way.nd != null)
            {
                way.Nodes = new List<long>();
                foreach (Osm.Xml.v0_6.nd xml_nd in xml_way.nd)
                {
                    way.Nodes.Add(xml_nd.@ref);
                }
            }

            way.ChangeSetId = xml_way.changeset;
            way.TimeStamp = xml_way.timestamp;
            way.UserName = xml_way.user;
            way.UserId = xml_way.uid;
            way.Version = xml_way.version;
            way.Visible = xml_way.visible;

            return way;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Updates the given way by adding it's changes to the current changeset.
        /// </summary>
        /// <param name="way"></param>
        public void WayUpdate(SimpleWay way)
        {
            if (_current_changeset == null)
            {
                throw new InvalidOperationException("No open changeset found!");
            }
            if (!way.Id.HasValue)
            {
                throw new ArgumentOutOfRangeException("Cannot update an object without an id!");
            }

            // build a new node.
            way xml_way = way.ConvertTo();
            xml_way.changeset = _current_changeset.id;
            xml_way.changesetSpecified = true;

            // encapsulate into an osm object.
            OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm();
            osm.way = new Osm.Xml.v0_6.way[1];
            osm.way[0] = xml_way;

            // serialize the changeset.
            XmlSerializer serializer = new XmlSerializer(typeof(OsmSharp.Osm.Xml.v0_6.osm));
            MemoryStream mem_stream = new MemoryStream();
            Stream stream = mem_stream;
            serializer.Serialize(stream, osm);
            stream.Flush();
            mem_stream.Flush();
            byte[] put_data = mem_stream.ToArray();

            // do the api call.
            string response_string = this.DoApiCall(true, string.Format("api/0.6/way/{0}", way.Id.Value),
                Method.PUT, put_data);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a new way by adding it to the current changeset.
        /// </summary>
        /// <param name="way"></param>
        public SimpleWay WayCreate(SimpleWay way)
        {
            if (_current_changeset == null)
            {
                throw new InvalidOperationException("No open changeset found!");
            }

            // build a new node.
            way xml_way = way.ConvertTo();
            xml_way.changeset = _current_changeset.id;
            xml_way.changesetSpecified = true;

            // encapsulate into an osm object.
            OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm();
            osm.way = new Osm.Xml.v0_6.way[1];
            osm.way[0] = xml_way;

            // serialize the changeset.
            XmlSerializer serializer = new XmlSerializer(typeof(OsmSharp.Osm.Xml.v0_6.osm));
            MemoryStream mem_stream = new MemoryStream();
            Stream stream = mem_stream;
            serializer.Serialize(stream, osm);
            stream.Flush();
            mem_stream.Flush();
            byte[] put_data = mem_stream.ToArray();

            // do the api call.
            string response_string = this.DoApiCall(true, "api/0.6/way/create",
                Method.PUT, put_data);

            // get the id-response.
            long id;
            if (!long.TryParse(response_string, out id))
            { // invalid response!
                throw new APIException(string.Format("Invalid response when creating a new way: {0}", response_string));
            }
            way.Id = id;
            return way;
        }
        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;
            }
        }
        /// <summary>
        /// Adds a given way.
        /// </summary>
        /// <param name="simple_way"></param>
        public override void AddWay(SimpleWay simple_way)
        {
            Way way = OsmBaseFactory.CreateWayFrom(_string_table, simple_way, _nodes);
            if (way != null)
            {
                _ways[way.Id] = way;

                _source.AddWay(way);
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Adds a way.
 /// </summary>
 /// <param name="way"></param>
 public void AddWay(SimpleWay way)
 {
     _ways[way.Id.Value] = way;
 }
Ejemplo n.º 17
0
        public void APITestWayCreateGetDelete()
        {
            // intialize the connection.
            APIConnection api_instance = new APIConnection("http://api06.dev.openstreetmap.org/",
                "osmsharp", "osmsharp");

            // open a changeset.
            long changeset_id = api_instance.ChangeSetOpen("Simple Way Creation Test");

            // initialize the way.
            SimpleWay way = new SimpleWay();
            way.Tags = new Dictionary<string, string>();
            way.Tags.Add("type", "testway");
            way.Nodes = new List<long>();
            way.Visible = true;

            // initialize the nodes.
            SimpleNode node = new SimpleNode();
            node.Latitude = -0.494497;
            node.Longitude = -24.119325;
            node.Tags = new Dictionary<string, string>();
            node.Tags.Add("type", "testnode1");
            node.Visible = true;
            node = api_instance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);
            node = new SimpleNode();
            node.Latitude = -0.494497 + 0.0001f;
            node.Longitude = -24.119325 + 0.0001f;
            node.Tags = new Dictionary<string, string>();
            node.Tags.Add("type", "testnode2");
            node.Visible = true;
            node = api_instance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);

            // save the way.
            way = api_instance.WayCreate(way);

            // close the changeset.
            api_instance.ChangeSetClose();

            // check if the id now has a value.
            Assert.IsTrue(way.Id.HasValue);

            // get the new way id.
            long way_id = way.Id.Value;

            // get the way again: a way can only be deleted using the correct changesetid and version.
            way = api_instance.WayGet(way.Id.Value);

            // open new changeset.
            changeset_id = api_instance.ChangeSetOpen("Simple Way Delete Test");

            // get the way.
            api_instance.WayDelete(way);

            // close the current changeset.
            api_instance.ChangeSetClose();

            // get the way.
            SimpleWay api_way = api_instance.WayGet(way.Id.Value);
            Assert.IsNull(api_way);
        }
Ejemplo n.º 18
0
        public void APITestWayCreateGetUpdate()
        {
            // intialize the connection.
            APIConnection api_instance = new APIConnection("http://api06.dev.openstreetmap.org/",
                "osmsharp", "osmsharp");

            // open a changeset.
            long changeset_id = api_instance.ChangeSetOpen("Simple Way Creation Test");

            // initialize the way.
            SimpleWay way = new SimpleWay();
            way.Tags = new Dictionary<string, string>();
            way.Tags.Add("type", "testway");
            way.Nodes = new List<long>();
            way.Visible = true;

            // initialize the nodes.
            SimpleNode node = new SimpleNode();
            node.Latitude = -0.494497;
            node.Longitude = -24.119325;
            node.Tags = new Dictionary<string, string>();
            node.Tags.Add("type", "testnode1");
            node.Visible = true;
            node = api_instance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);
            node = new SimpleNode();
            node.Latitude = -0.494497 + 0.0001f;
            node.Longitude = -24.119325 + 0.0001f;
            node.Tags = new Dictionary<string, string>();
            node.Tags.Add("type", "testnode2");
            node.Visible = true;
            node = api_instance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);

            // save the way.
            way = api_instance.WayCreate(way);

            // close the changeset.
            api_instance.ChangeSetClose();

            // check if the id now has a value.
            Assert.IsTrue(way.Id.HasValue);

            // get the new way id.
            long way_id = way.Id.Value;

            // open new changeset.
            changeset_id = api_instance.ChangeSetOpen("Simple Way Update Test");

            // get the way.
            SimpleWay api_way = api_instance.WayGet(way.Id.Value);
            api_way.Tags.Add("another_tag", "test adding a tag!");
            api_instance.WayUpdate(api_way);

            // close the current changeset.
            api_instance.ChangeSetClose();

            // get the api way.
            api_way = api_instance.WayGet(way.Id.Value);

            Assert.AreEqual(2, api_way.Tags.Count);
            Assert.IsTrue(api_way.Tags.ContainsKey("another_tag"));
            Assert.AreEqual("test adding a tag!", api_way.Tags["another_tag"]);
        }
        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;
            }
        }
        private void Create(SimpleWay way)
        {
            OracleCommand command;

            DateTime? timestamp = way.TimeStamp;
            string timestamp_str = timestamp.Value.ToString("HH:mm dd/MM/yyyy");

            command = this.CreateCommand(string.Format(
                "insert into way (id,changeset_id,timestamp,visible,version,usr,usr_id) values (:id,:changeset_id,to_date('{0}','HH24:MI DD/MM/YYYY'),:visible,:version,:usr,:usr_id)",
                timestamp_str));

            // format data and create parameters.
            long? id = way.Id;
            command.Parameters.Add(new OracleParameter("id", id.ConvertToDBValue<long>()));

            long? changeset_id = way.ChangeSetId;
            command.Parameters.Add(new OracleParameter("changeset_id", changeset_id.ConvertToDBValue<long>()));

            bool? visible = way.Visible;
            int visible_int = 1;
            if (!visible.HasValue)
            {
                visible_int = 0;
            }
            command.Parameters.Add(new OracleParameter("visible", visible_int));

            long? version = (long)way.Version;
            command.Parameters.Add(new OracleParameter("version", version.ConvertToDBValue<long>()));

            command.Parameters.Add("usr", way.UserName);
            command.Parameters.Add("usr_id", way.UserId);

            command.ExecuteNonQuery();
            command.Dispose();

            // insert tags.
            this.CreateTags(way.Id.Value, way.Tags, "way_tags", "way_id");

            // insert way_nodes.
            this.CreateWayNodes(way.Id.Value, way.Nodes);
        }
        /// <summary>
        /// Adds a way to the target.
        /// </summary>
        /// <param name="way"></param>
        public override void AddWay(SimpleWay way)
        {
            if (_base_objects == null)
            { // the base object collection is null.
                throw new InvalidOperationException("No target collection set!");
            }

            // add the way to the collection.
            _base_objects.Add(way);
        }
        private void Delete(SimpleWay way)
        {
            OracleCommand command;

            command = this.CreateCommand("delete from way_nodes where way_id = :way_id");
            command.Parameters.Add(new OracleParameter("way_id", way.Id.Value));
            command.ExecuteNonQuery();
            command.Dispose();

            command = this.CreateCommand("delete from way_tags where way_id = :way_id");
            command.Parameters.Add(new OracleParameter("way_id", way.Id.Value));
            command.ExecuteNonQuery();
            command.Dispose();

            command = this.CreateCommand("delete from way where id = :id");
            command.Parameters.Add(new OracleParameter("id", way.Id.Value));
            command.ExecuteNonQuery();
            command.Dispose();
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Adds a way to the target.
 /// </summary>
 /// <param name="way"></param>
 public abstract void AddWay(SimpleWay way);
Ejemplo n.º 24
0
        /// <summary>
        /// Adds a way to this database.
        /// </summary>
        /// <param name="way"></param>
        public override void AddWay(SimpleWay way)
        {
            // converts the way.
            OsmWay new_way = PrimitiveExtensions.ConvertTo(way, way.Nodes);

            // only insert it if it is an highway.
            if (new_way.IsHighway)
            {
                string way_key = new_way.GetRedisKey();
                _way_type_client.SetEntry(way_key, new_way);

                // add all the needed nodes.
                foreach (long id in way.Nodes)
                {
                    SimpleNode node = null;
                    OsmNode new_node = null;
                    if (_cached_nodes.TryGetValue(id, out node)
                        && !_nodes_in_ways.TryGetValue(id, out new_node))
                    {
                        // convert to the new node.
                        new_node = PrimitiveExtensions.ConvertTo(node);
                        _nodes_in_ways.Add(id, new_node);
                    }
                    if (new_node != null)
                    {
                        new_node.Ways.Add(way.Id.Value);
                    }
                }
            }
        }