示例#1
0
 /// <summary>
 /// Creates a new way.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="nodes"></param>
 /// <returns></returns>
 public static Way Create(long id, params long[] nodes)
 {
     Way way = new Way();
     way.Id = id;
     way.Nodes = new List<long>(nodes);
     return way;
 }
示例#2
0
 /// <summary>
 /// Creates a new way.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="nodes"></param>
 /// <param name="tags"></param>
 /// <returns></returns>
 public static Way Create(long id, TagsCollection tags, params long[] nodes)
 {
     Way way = new Way();
     way.Id = id;
     way.Nodes = new List<long>(nodes);
     way.Tags = tags;
     return way;
 }
        public override void AddWay(Way way)
        {
            if (!way.Id.HasValue)
                return;

            MaxStringLength(way.UserName, ref WayUsr);

            if (way.Tags == null)
                return;

            foreach (Tag tag in way.Tags)
            {
                MaxStringLength(tag.Key, ref WayTagsKey);
                MaxStringLength(tag.Value, ref WayTagsValue);
            }
        }
        public void TestWayAreaIsYesArea()
        {
            var node1 = new Node();
            node1.Id = 1;
            node1.Latitude = 0;
            node1.Longitude = 0;
            var node2 = new Node();
            node2.Id = 2;
            node2.Latitude = 1;
            node2.Longitude = 0;
            var node3 = new Node();
            node3.Id = 3;
            node3.Latitude = 0;
            node3.Longitude = 1;

            var way = new Way();
            way.Id = 1;
            way.Nodes = new List<long>();
            way.Nodes.Add(1);
            way.Nodes.Add(2);
            way.Nodes.Add(3);
            way.Nodes.Add(1);
            way.Tags = new TagsCollection();
            way.Tags.Add("area", "yes");

            var source = new List<OsmGeo>();
            source.Add(node1);
            source.Add(node2);
            source.Add(node3);
            source.Add(way);

            // create source stream.
            var sourceStream = new OsmSharp.Osm.Streams.Complete.OsmSimpleCompleteStreamSource(source.ToOsmStreamSource());

            // create features source.
            var featuresSourceStream = new OsmFeatureStreamSource(sourceStream);

            // pull stream.
            var features = new List<Feature>(featuresSourceStream);

            Assert.IsNotNull(features);
            Assert.AreEqual(1, features.Count);
            var feature = features[0];
            Assert.IsInstanceOf<LineairRing>(feature.Geometry);
            Assert.IsTrue(feature.Attributes.ContainsKeyValue("area", "yes"));
        }
        public void TestWayAreaIsYes()
        {
            Node node1 = new Node();
            node1.Id = 1;
            node1.Latitude = 0;
            node1.Longitude = 0;
            Node node2 = new Node();
            node2.Id = 2;
            node2.Latitude = 1;
            node2.Longitude = 0;
            Node node3 = new Node();
            node3.Id = 3;
            node3.Latitude = 0;
            node3.Longitude = 1;

            Way way = new Way();
            way.Id = 1;
            way.Nodes = new List<long>();
            way.Nodes.Add(1);
            way.Nodes.Add(2);
            way.Nodes.Add(3);
            way.Nodes.Add(1);
            way.Tags = new TagsCollection();
            way.Tags.Add("area", "yes");

            var source = new List<OsmGeo>();
            source.Add(node1);
            source.Add(node2);
            source.Add(node3);
            source.Add(way);

            // the use of natural=water implies an area-type.
            var interpreter = new SimpleFeatureInterpreter();
            var completeStreamSource = new OsmSimpleCompleteStreamSource(source.ToOsmStreamSource());

            // use the stream to interpret.
            var features = new List<Feature>(new FeatureInterpreterStreamSource(completeStreamSource, interpreter));

            Assert.AreEqual(1, features.Count);
        }
示例#6
0
        public void TestEmptyCSS()
        {
            // create 'test' objects.
            Node node1 = new Node();
            node1.Id = 1;
            node1.Latitude = 1;
            node1.Longitude = 1;

            Node node2 = new Node();
            node2.Id = 2;
            node2.Latitude = 2;
            node2.Longitude = 2;

            Way way = new Way();
            way.Id = 1;
            way.Nodes = new List<long>();
            way.Nodes.Add(1);
            way.Nodes.Add(2);

            // create the datasource.
            MemoryDataSource dataSource = new MemoryDataSource();
            dataSource.AddNode(node1);
            dataSource.AddNode(node2);
            dataSource.AddWay(way);

            // create the projection and scene objects.
            var mercator = new WebMercator();
            Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(string.Empty,
                new MapCSSDictionaryImageSource());
            interpreter.Translate(scene, mercator, dataSource, node1);
            interpreter.Translate(scene, mercator, dataSource, node2);
            interpreter.Translate(scene, mercator, dataSource, way);

            // test the scene contents.
            Assert.AreEqual(0, scene.Count);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, scene.BackColor);
        }
示例#7
0
        public void TestCanvasJOSMSettingsCSS()
        {
            // create CSS.
            string css = "canvas { " +
                "background-color: white; " +
                "default-points: true; " + // adds default points for every node (color: black, size: 2).
                "default-lines: true; " + // adds default lines for every way (color: red, width: 1).
                "} ";

            // create 'test' objects.
            Node node1 = new Node();
            node1.Id = 1;
            node1.Latitude = 1;
            node1.Longitude = 1;

            Node node2 = new Node();
            node2.Id = 2;
            node2.Latitude = 2;
            node2.Longitude = 2;

            Way way = new Way();
            way.Id = 1;
            way.Nodes = new List<long>();
            way.Nodes.Add(1);
            way.Nodes.Add(2);

            // create the datasource.
            MemoryDataSource dataSource = new MemoryDataSource();
            dataSource.AddNode(node1);
            dataSource.AddNode(node2);
            dataSource.AddWay(way);

            // create the projection and scene objects.
            var mercator = new WebMercator();
            Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(css,
                new MapCSSDictionaryImageSource());
            interpreter.Translate(scene, mercator, dataSource, node1);
            interpreter.Translate(scene, mercator, dataSource, node2);
            interpreter.Translate(scene, mercator, dataSource, way);

            // test the scene contents.
            Assert.AreEqual(3, scene.Count);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.White).Value, scene.BackColor);

            // test the scene point 1.
            Primitive2D primitive = scene.Get(0);
            Assert.IsNotNull(primitive);
            Assert.IsInstanceOf<Primitive2D>(primitive);
            Point2D pointObject = primitive as Point2D;
            Assert.AreEqual(2, pointObject.Size);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color);
            Assert.AreEqual(mercator.LongitudeToX(1), pointObject.X);
            Assert.AreEqual(mercator.LatitudeToY(1), pointObject.Y);

            // test the scene point 2.
            primitive = scene.Get(1);
            Assert.IsNotNull(primitive);
            Assert.IsInstanceOf<Point2D>(primitive);
            pointObject = primitive as Point2D;
            Assert.AreEqual(2, pointObject.Size);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color);
            Assert.AreEqual(mercator.LongitudeToX(2), pointObject.X);
            Assert.AreEqual(mercator.LatitudeToY(2), pointObject.Y);

            // test the scene line 2.
            primitive = scene.Get(2);
            Assert.IsNotNull(primitive);
            Assert.IsInstanceOf<Line2D>(primitive);
            Line2D line = primitive as Line2D;
            Assert.AreEqual(1, line.Width);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Red).Value, line.Color);
            Assert.IsNotNull(line.X);
            Assert.IsNotNull(line.Y);
            Assert.AreEqual(2, line.X.Length);
            Assert.AreEqual(2, line.Y.Length);
            Assert.AreEqual(mercator.LongitudeToX(1), line.X[0]);
            Assert.AreEqual(mercator.LatitudeToY(1), line.Y[0]);
            Assert.AreEqual(mercator.LongitudeToX(2), line.X[1]);
            Assert.AreEqual(mercator.LatitudeToY(2), line.Y[1]);
        }
        /// <summary>
        /// Compares a found way to an expected way.
        /// </summary>
        /// <param name="expected"></param>
        /// <param name="found"></param>
        private void CompareWays(Way expected, Way found)
        {
            Assert.IsNotNull(expected);
            Assert.IsNotNull(found);
            Assert.AreEqual(expected.Id, found.Id);
            Assert.AreEqual(expected.ChangeSetId, found.ChangeSetId);
            Assert.AreEqual(expected.TimeStamp, found.TimeStamp);
            Assert.AreEqual(expected.Type, found.Type);
            Assert.AreEqual(expected.UserId, found.UserId);
            Assert.AreEqual(expected.UserName, found.UserName);
            Assert.AreEqual(expected.Version, found.Version);
            Assert.AreEqual(expected.Visible, found.Visible);

            if (expected.Nodes == null)
            {
                Assert.IsNull(found.Nodes);
            }
            else
            {
                Assert.IsNotNull(found.Nodes);
                Assert.AreEqual(expected.Nodes.Count, found.Nodes.Count);
                for (int idx = 0; idx < expected.Nodes.Count; idx++)
                {
                    Assert.AreEqual(expected.Nodes[idx], found.Nodes[idx]);
                }
            }

            this.CompareTags(expected.Tags, found.Tags);
        }
        public void TestWayNaturalIsWaterArea()
        {
            Node node1 = new Node();
            node1.Id = 1;
            node1.Latitude = 0;
            node1.Longitude = 0;
            Node node2 = new Node();
            node2.Id = 2;
            node2.Latitude = 1;
            node2.Longitude = 0;
            Node node3 = new Node();
            node3.Id = 3;
            node3.Latitude = 0;
            node3.Longitude = 1;

            Way way = new Way();
            way.Id = 1;
            way.Nodes = new List<long>();
            way.Nodes.Add(1);
            way.Nodes.Add(2);
            way.Nodes.Add(3);
            way.Nodes.Add(1);
            way.Tags = new SimpleTagsCollection();
            way.Tags.Add("natural", "water");

            MemoryDataSource source = new MemoryDataSource();
            source.AddNode(node1);
            source.AddNode(node2);
            source.AddNode(node3);
            source.AddWay(way);

            // the use of natural=water implies an area-type.
            GeometryInterpreter interpreter = new SimpleGeometryInterpreter();
            GeometryCollection geometries = interpreter.Interpret(way, source);

            Assert.IsNotNull(geometries);
            Assert.AreEqual(1, geometries.Count);
            Geometry geometry = geometries[0];
            Assert.IsInstanceOf<LineairRing>(geometry);
            Assert.IsTrue(geometry.Attributes.ContainsKeyValue("natural", "water"));
        }
示例#10
0
        /// <summary>
        /// Adds a way.
        /// </summary>
        /// <param name="way"></param>
        private void AddWay(Way way)
        {
            if (_ways.ContainsKey(way.Id))
            {
                throw new InvalidOperationException("Cannot add an object that already exists in this source!" + Environment.NewLine +
                    "If there is a modification use a changeset!");
            }
            else
            {
                _ways.Add(way.Id, way);

                foreach (Node node in way.Nodes)
                {
                    if (this.GetNode(node.Id) == null)
                    {
                        this.AddNode(node);
                    }
                }

            }
        }
示例#11
0
        /// <summary>
        /// Converts a domain model way to an Xml way.
        /// </summary>
        /// <param name="way"></param>
        /// <returns></returns>
        public static way ConvertTo(this OsmSharp.Osm.Way way)
        {
            way xmlWay = new way();

            // set the changeset.
            if (way.ChangeSetId.HasValue)
            {
                xmlWay.changeset          = way.ChangeSetId.Value;
                xmlWay.changesetSpecified = true;
            }

            // set the id.
            if (way.Id.HasValue)
            {
                xmlWay.id          = way.Id.Value;
                xmlWay.idSpecified = true;
            }
            else
            {
                xmlWay.idSpecified = false;
            }

            if (way.Tags != null)
            {
                xmlWay.tag = new tag[way.Tags.Count];
                int idx = 0;
                foreach (var tag in way.Tags)
                {
                    var t = new tag();
                    t.k             = tag.Key;
                    t.v             = tag.Value;
                    xmlWay.tag[idx] = t;
                    idx++;
                }
            }

            // set the timestamp.
            if (way.TimeStamp.HasValue)
            {
                xmlWay.timestamp          = way.TimeStamp.Value;
                xmlWay.timestampSpecified = true;
            }

            // set the user data.
            if (way.UserId.HasValue)
            {
                xmlWay.uid          = way.UserId.Value;
                xmlWay.uidSpecified = true;
            }
            xmlWay.user = xmlWay.user;

            // set the version.
            if (way.Version.HasValue)
            {
                xmlWay.version          = (ulong)way.Version.Value;
                xmlWay.versionSpecified = true;
            }

            // set the visible.
            if (way.Visible.HasValue)
            {
                xmlWay.visible          = way.Visible.Value;
                xmlWay.visibleSpecified = true;
            }
            else
            {
                xmlWay.visibleSpecified = false;
            }

            // set the way-specific properties.
            xmlWay.nd = new nd[way.Nodes.Count];
            for (int i = 0; i < way.Nodes.Count; i++)
            {
                var n = new nd();
                n.@ref         = way.Nodes[i];
                n.refSpecified = true;
                xmlWay.nd[i]   = n;
            }

            return(xmlWay);
        }
示例#12
0
        /// <summary>
        /// Creates a new way.
        /// </summary>
        /// <returns></returns>
        public static CompleteWay CreateFrom(ObjectTable<string> table, Way simpleWay,
                                        IDictionary<long, Node> nodes)
        {
            if (table == null) throw new ArgumentNullException("table");
            if (simpleWay == null) throw new ArgumentNullException("simpleWay");
            if (nodes == null) throw new ArgumentNullException("nodes");
            if (simpleWay.Id == null) throw new Exception("simpleWay.id is null");

            var way = Create(table, simpleWay.Id.Value);
            way.ChangeSetId = simpleWay.ChangeSetId;
            foreach (var pair in simpleWay.Tags)
            {
                way.Tags.Add(pair);
            }
            for (int idx = 0; idx < simpleWay.Nodes.Count; idx++)
            {
                var nodeId = simpleWay.Nodes[idx];
                Node node = null;
                if (nodes.TryGetValue(nodeId, out node))
                {
                    way.Nodes.Add(node);
                }
                else
                {
                    return null;
                }
            }
            way.TimeStamp = simpleWay.TimeStamp;
            way.User = simpleWay.UserName;
            way.UserId = simpleWay.UserId;
            way.Version = simpleWay.Version.HasValue ? (long)simpleWay.Version.Value : (long?)null;
            way.Visible = simpleWay.Visible.HasValue && simpleWay.Visible.Value;
            return way;
        }
        /// <summary>
        /// Modifies the given way.
        /// </summary>
        /// <param name="way"></param>
        private void Modify(Way 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(ChangeType.Modify, OsmGeoType.Way, way.Id.Value);
        }
示例#14
0
        /// <summary>
        /// Adds a way.
        /// </summary>
        /// <param name="way"></param>
        public void AddWay(Way way)
        {
            if (way == null) throw new ArgumentNullException();
            if (!way.Id.HasValue) throw new ArgumentException("Ways without a valid id cannot be saved!");

            _ways[way.Id.Value] = way;

            if(way.Nodes != null)
            {
                foreach(long nodeId in way.Nodes)
                {
                    HashSet<long> wayIds;
                    if (!_waysPerNode.TryGetValue(nodeId, out wayIds))
                    {
                        wayIds = new HashSet<long>();
                        _waysPerNode.Add(nodeId, wayIds);
                    }
                    wayIds.Add(way.Id.Value);
                }
            }
        }
        private void AddWayNodes(Way way)
        {
            if (way.Nodes != null)
            {
                long? sequence_id = 0;
                foreach (var node in way.Nodes)
                {
                    if (_cached_way_nodes.Count == WayNodesBatchCount)
                    {
                        BatchAddWayNodes(_cached_way_nodes, _replaceWayNodesBatchCommand);
                    }

                    _cached_way_nodes.Add(new Tuple<long?, long?, long?>(way.Id, node, sequence_id));
                    ++sequence_id;
                }
            }
        }
示例#16
0
        /// <summary>
        /// Converts a domain model way to an Xml way.
        /// </summary>
        /// <param name="dom_obj"></param>
        /// <returns></returns>
        public static way ConvertTo(this OsmSharp.Osm.Way dom_obj)
        {
            way xml_obj = new way();

            // set the changeset.
            if (dom_obj.ChangeSetId.HasValue)
            {
                xml_obj.changeset          = dom_obj.ChangeSetId.Value;
                xml_obj.changesetSpecified = true;
            }

            // set the id.
            if (dom_obj.Id.HasValue)
            {
                xml_obj.id          = dom_obj.Id.Value;
                xml_obj.idSpecified = true;
            }
            else
            {
                xml_obj.idSpecified = false;
            }

            if (dom_obj.Tags != null)
            {
                xml_obj.tag = new tag[dom_obj.Tags.Count];
                int idx = 0;
                foreach (var tag in dom_obj.Tags)
                {
                    tag t = new tag();
                    t.k = tag.Key;
                    t.v = tag.Value;
                    xml_obj.tag[idx] = t;
                    idx++;
                }
            }

            // set the timestamp.
            if (dom_obj.TimeStamp.HasValue)
            {
                xml_obj.timestamp          = dom_obj.TimeStamp.Value;
                xml_obj.timestampSpecified = true;
            }

            // set the user data.
            if (dom_obj.UserId.HasValue)
            {
                xml_obj.uid          = dom_obj.UserId.Value;
                xml_obj.uidSpecified = true;
            }
            xml_obj.user = xml_obj.user;

            // set the version.
            if (dom_obj.Version.HasValue)
            {
                xml_obj.version          = (ulong)dom_obj.Version.Value;
                xml_obj.versionSpecified = true;
            }

            // set the visible.
            if (dom_obj.Visible.HasValue)
            {
                xml_obj.visible          = dom_obj.Visible.Value;
                xml_obj.visibleSpecified = true;
            }
            else
            {
                xml_obj.visibleSpecified = false;
            }

            // set the way-specific properties.
            xml_obj.nd = new nd[dom_obj.Nodes.Count];
            for (int idx = 0; idx < dom_obj.Nodes.Count; idx++)
            {
                nd n = new nd();
                n.@ref          = dom_obj.Nodes[idx];
                n.refSpecified  = true;
                xml_obj.nd[idx] = n;
            }

            return(xml_obj);
        }
示例#17
0
        /// <summary>
        /// Creates a relation from a SimpleRelation.
        /// </summary>
        /// <param name="simpleRelation"></param>
        /// <param name="osmGeoSource"></param>
        /// <param name="ways"></param>
        /// <param name="relations"></param>
        /// <returns></returns>
        public static CompleteRelation CreateFrom(Relation simpleRelation, IOsmGeoSource osmGeoSource,
                                                  IDictionary <long, CompleteWay> ways,
                                                  IDictionary <long, CompleteRelation> relations)
        {
            if (simpleRelation == null)
            {
                throw new ArgumentNullException("simpleRelation");
            }
            if (osmGeoSource == null)
            {
                throw new ArgumentNullException("osmGeoSource");
            }
            if (simpleRelation.Id == null)
            {
                throw new Exception("simpleRelation.Id is null");
            }

            CompleteRelation relation = Create(simpleRelation.Id.Value);

            relation.ChangeSetId = simpleRelation.ChangeSetId;
            foreach (Tag pair in simpleRelation.Tags)
            {
                relation.Tags.Add(pair);
            }
            for (int idx = 0; idx < simpleRelation.Members.Count; idx++)
            {
                long   memberId = simpleRelation.Members[idx].MemberId.Value;
                string role     = simpleRelation.Members[idx].MemberRole;

                var member = new CompleteRelationMember();
                member.Role = role;
                switch (simpleRelation.Members[idx].MemberType.Value)
                {
                case OsmGeoType.Node:
                    Node simpleNode = osmGeoSource.GetNode(memberId);
                    if (simpleNode != null)
                    {
                        member.Member = CompleteNode.CreateFrom(simpleNode);
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Way:
                    CompleteWay completeWay;
                    if (!ways.TryGetValue(memberId, out completeWay))
                    {
                        Way simpleWay = osmGeoSource.GetWay(memberId);
                        if (simpleWay != null)
                        {
                            completeWay = CompleteWay.CreateFrom(simpleWay, osmGeoSource);
                        }
                    }
                    if (completeWay != null)
                    {
                        member.Member = completeWay;
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Relation:
                    CompleteRelation completeRelation;
                    if (!relations.TryGetValue(memberId, out completeRelation))
                    {
                        Relation simpleRelationMember = osmGeoSource.GetRelation(memberId);
                        if (simpleRelationMember != null)
                        {
                            completeRelation = CompleteRelation.CreateFrom(simpleRelationMember, osmGeoSource);
                        }
                    }
                    if (completeRelation != null)
                    {
                        member.Member = completeRelation;
                    }
                    else
                    {
                        return(null);
                    }
                    break;
                }
                relation.Members.Add(member);
            }
            relation.TimeStamp = simpleRelation.TimeStamp;
            relation.User      = simpleRelation.UserName;
            relation.UserId    = simpleRelation.UserId;
            relation.Version   = simpleRelation.Version.HasValue ? (long)simpleRelation.Version.Value : (long?)null;
            relation.Visible   = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value;

            return(relation);
        }
示例#18
0
        /// <summary>
        /// Adds a relation.
        /// </summary>
        /// <param name="way"></param>
        public void AddWay(Way way)
        {
            _ways[way.Id] = way;

            foreach (Node node in way.Nodes)
            {
                if (node != null)
                {
                    this.AddNode(node);

                    IList<Way> ways = null;
                    if (!_ways_per_node.TryGetValue(node.Id, out ways))
                    {
                        ways = new List<Way>();
                        _ways_per_node.Add(node.Id, ways);
                    }
                    ways.Add(way);
                }
            }
        }
示例#19
0
        /// <summary>
        /// Creates a new way.
        /// </summary>
        /// <returns></returns>
        public static CompleteWay CreateFrom(Way simpleWay, INodeSource nodeSource)
        {
            if (simpleWay == null) throw new ArgumentNullException("simpleWay");
            if (nodeSource == null) throw new ArgumentNullException("nodeSource");
            if (simpleWay.Id == null) throw new Exception("simpleWay.id is null");

            var way = Create(simpleWay.Id.Value);
            way.ChangeSetId = simpleWay.ChangeSetId;
            if (simpleWay.Tags != null)
            {
                foreach (var pair in simpleWay.Tags)
                {
                    way.Tags.Add(pair);
                }
            }
            if (simpleWay.Nodes != null)
            {
                for (int idx = 0; idx < simpleWay.Nodes.Count; idx++)
                {
                    var nodeId = simpleWay.Nodes[idx];
                    var node = nodeSource.GetNode(nodeId);
                    if (node == null)
                    {
                        return null;
                    }
                    var completeNode = node;
                    if (completeNode != null)
                    {
                        way.Nodes.Add(completeNode);
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            way.TimeStamp = simpleWay.TimeStamp;
            way.User = simpleWay.UserName;
            way.UserId = simpleWay.UserId;
            way.Version = simpleWay.Version.HasValue ? (long)simpleWay.Version.Value : (long?)null;
            way.Visible = simpleWay.Visible.HasValue && simpleWay.Visible.Value;
            return way;
        }
示例#20
0
 private void WayCachePut(Way way)
 {
     _ways.Add(way.Id, way);
 }
示例#21
0
 /// <summary>
 /// Converts this relation into it's simple counterpart.
 /// </summary>
 /// <returns></returns>
 public override OsmGeo ToSimple()
 {
     var way = new Way();
     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.Value);
     }
     return way;
 }
        /// <summary>
        /// Converts the given way from a redis way.
        /// </summary>
        /// <param name="redisWay"></param>
        /// <returns></returns>
        public static Way ConvertFrom(RedisWay redisWay)
        {
            Way way = new Way();
            way.Id = redisWay.Id.Value;
            way.ChangeSetId = redisWay.ChangeSetId;
            way.TimeStamp = redisWay.TimeStamp;
            way.UserId = redisWay.UserId;
            way.UserName = redisWay.UserName;
            way.Version = redisWay.Version;
            way.Visible = redisWay.Visible;
            way.Tags = PrimitiveExtensions.ConvertFrom(redisWay.Tags);
            if (redisWay.Nodes != null)
            {
                way.Nodes = new List<long>(redisWay.Nodes);
            }

            return way;
        }
示例#23
0
 /// <summary>
 /// Adds the node-way relations for the given way.
 /// </summary>
 /// <param name="way"></param>
 private void RegisterNodeWayRelation(Way way)
 {
     foreach (Node node in way.Nodes)
     {
         if (!_ways_per_node.ContainsKey(node.Id))
         {
             _ways_per_node.Add(node.Id, new List<long>());
         }
         _ways_per_node[node.Id].Add(way.Id);
     }
 }
        /// <summary>
        /// Converts the given way to a redis way.
        /// </summary>
        /// <param name="way"></param>
        /// <returns></returns>
        public static RedisWay ConvertTo(Way way)
        {
            RedisWay redisWay = new RedisWay();
            redisWay.Id = way.Id.Value;
            redisWay.ChangeSetId = way.ChangeSetId;
            redisWay.TimeStamp = way.TimeStamp;
            redisWay.UserId = way.UserId;
            redisWay.UserName = way.UserName;
            redisWay.Version = way.Version;
            redisWay.Visible = way.Visible;
            redisWay.Tags = PrimitiveExtensions.ConvertTo(way.Tags);
            if (way.Nodes != null)
            {
                redisWay.Nodes = new List<long>(way.Nodes);
            }

            return redisWay;
        }
        /// <summary>
        /// Compares a found way to an expected way.
        /// </summary>
        public static void CompareSimple(Way expected, Way actual)
        {
            Assert.IsNotNull(expected);
            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.ChangeSetId, actual.ChangeSetId);
            Assert.AreEqual(expected.TimeStamp, actual.TimeStamp);
            Assert.AreEqual(expected.Type, actual.Type);
            Assert.AreEqual(expected.UserId, actual.UserId);
            Assert.AreEqual(expected.UserName, actual.UserName);
            Assert.AreEqual(expected.Version, actual.Version);
            Assert.AreEqual(expected.Visible, actual.Visible);

            if (expected.Nodes == null)
            {
                Assert.IsNull(actual.Nodes);
            }
            else
            {
                Assert.IsNotNull(actual.Nodes);
                Assert.AreEqual(expected.Nodes.Count, actual.Nodes.Count);
                for (int idx = 0; idx < expected.Nodes.Count; idx++)
                {
                    Assert.AreEqual(expected.Nodes[idx], actual.Nodes[idx]);
                }
            }

            ComparisonHelpers.CompareTags(expected.Tags, actual.Tags);
        }
示例#26
0
        public void APITestWayCreateGet()
        {
            // intialize the connection.
            var apiInstance = new APIConnection("http://api06.dev.openstreetmap.org/",
                "osmsharp", "osmsharp");

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

            // initialize the way.
            var way = new Way();
            way.Tags = new TagsCollection();
            way.Tags.Add("type", "testway");
            way.Nodes = new List<long>();
            way.Visible = true;

            // initialize the nodes.
            var node = new Node();
            node.Latitude = -0.494497;
            node.Longitude = -24.119325;
            node.Tags = new TagsCollection();
            node.Tags.Add("type", "testnode1");
            node.Visible = true;
            node = apiInstance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);
            node = new Node();
            node.Latitude = -0.494497 + 0.0001f;
            node.Longitude = -24.119325 + 0.0001f;
            node.Tags = new TagsCollection();
            node.Tags.Add("type", "testnode2");
            node.Visible = true;
            node = apiInstance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);

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

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

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

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

            // get the way from the api.
            Way wayAPI = apiInstance.WayGet(way.Id.Value);
            Assert.AreEqual(wayId, wayAPI.Id.Value);
            Assert.AreEqual(way.Tags.Count, wayAPI.Tags.Count);
            Assert.AreEqual(way.Visible, wayAPI.Visible);
            Assert.IsTrue(wayAPI.ChangeSetId.HasValue);
            Assert.AreEqual(changesetId, wayAPI.ChangeSetId.Value);
            Assert.AreEqual(way.Nodes[0], wayAPI.Nodes[0]);
            Assert.AreEqual(way.Nodes[1], wayAPI.Nodes[1]);
        }
        /// <summary>
        /// Tests read/writing a way.
        /// </summary>
        protected void TestWayReadWrite()
        {
            this.NotifyEmptyExpected(); // empty test database.

            // create a test-way.
            Way way = new Way();
            way.Id = 1;

            // create a target, add the way, create a source and verify way in db.
            var target = this.CreateDataStreamTarget();
            target.Initialize();
            target.AddWay(way);
            target.Flush();
            target.Close();
            var dataSource = this.CreateDataSource();
            Way foundWay = dataSource.GetWay(1);
            this.CompareWays(way, foundWay);

            this.NotifyEmptyExpected(); // empty test database.

            // create a test-way.
            way = new Way();
            way.Id = 1;
            way.UserName = "******";

            // create a target, add the way, create a source and verify way in db.
            target = this.CreateDataStreamTarget();
            target.Initialize();
            target.AddWay(way);
            target.Flush();
            target.Close();
            dataSource = this.CreateDataSource();
            foundWay = dataSource.GetWay(1);
            this.CompareWays(way, foundWay);

            this.NotifyEmptyExpected(); // empty test database.

            // create a test-way.
            way = new Way();
            way.Id = 1;
            way.UserName = "******";
            way.UserId = 10;

            // create a target, add the way, create a source and verify way in db.
            target = this.CreateDataStreamTarget();
            target.Initialize();
            target.AddWay(way);
            target.Flush();
            target.Close();
            dataSource = this.CreateDataSource();
            foundWay = dataSource.GetWay(1);
            this.CompareWays(way, foundWay);

            this.NotifyEmptyExpected(); // empty test database.

            // create a test-way.
            way = new Way();
            way.Id = 1;
            way.UserName = "******";
            way.UserId = 10;
            way.Version = 1;

            // create a target, add the way, create a source and verify way in db.
            target = this.CreateDataStreamTarget();
            target.Initialize();
            target.AddWay(way);
            target.Flush();
            target.Close();
            dataSource = this.CreateDataSource();
            foundWay = dataSource.GetWay(1);
            this.CompareWays(way, foundWay);

            this.NotifyEmptyExpected(); // empty test database.

            // create a test-way.
            way = new Way();
            way.Id = 1;
            way.UserName = "******";
            way.UserId = 10;
            way.Version = 1;
            way.Visible = true;

            // create a target, add the way, create a source and verify way in db.
            target = this.CreateDataStreamTarget();
            target.Initialize();
            target.AddWay(way);
            target.Flush();
            target.Close();
            dataSource = this.CreateDataSource();
            foundWay = dataSource.GetWay(1);
            this.CompareWays(way, foundWay);

            this.NotifyEmptyExpected(); // empty test database.

            // create a test-way.
            way = new Way();
            way.Id = 1;
            way.UserName = "******";
            way.UserId = 10;
            way.Version = 1;
            way.Visible = true;
            way.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

            // create a target, add the way, create a source and verify way in db.
            target = this.CreateDataStreamTarget();
            target.Initialize();
            target.AddWay(way);
            target.Flush();
            target.Close();
            dataSource = this.CreateDataSource();
            foundWay = dataSource.GetWay(1);
            this.CompareWays(way, foundWay);

            this.NotifyEmptyExpected(); // empty test database.

            // create a test-way.
            way = new Way();
            way.Id = 1;
            way.UserName = "******";
            way.UserId = 10;
            way.Version = 1;
            way.Visible = true;
            way.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            way.Tags = new SimpleTagsCollection();
            way.Tags.Add("tag", "value");

            // create a target, add the way, create a source and verify way in db.
            target = this.CreateDataStreamTarget();
            target.Initialize();
            target.AddWay(way);
            target.Flush();
            target.Close();
            dataSource = this.CreateDataSource();
            foundWay = dataSource.GetWay(1);
            this.CompareWays(way, foundWay);

            this.NotifyEmptyExpected(); // empty test database.

            // create a test-way.
            way = new Way();
            way.Id = 1;
            way.UserName = "******";
            way.UserId = 10;
            way.Version = 1;
            way.Visible = true;
            way.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            way.Nodes = new List<long>();
            way.Nodes.Add(1);
            way.Nodes.Add(2);
            way.Nodes.Add(3);
            way.Nodes.Add(1);

            // create a target, add the way, create a source and verify way in db.
            target = this.CreateDataStreamTarget();
            target.Initialize();
            target.AddWay(way);
            target.Flush();
            target.Close();
            dataSource = this.CreateDataSource();
            foundWay = dataSource.GetWay(1);
            this.CompareWays(way, foundWay);
        }
示例#28
0
        public void APITestWayCreateGetDelete()
        {
            // intialize the connection.
            var apiInstance = new APIConnection("http://api06.dev.openstreetmap.org/",
                "osmsharp", "osmsharp");

            // open a changeset.
            apiInstance.ChangeSetOpen("Simple Way Creation Test");

            // initialize the way.
            var way = new Way();
            way.Tags = new TagsCollection();
            way.Tags.Add("type", "testway");
            way.Nodes = new List<long>();
            way.Visible = true;

            // initialize the nodes.
            var node = new Node();
            node.Latitude = -0.494497;
            node.Longitude = -24.119325;
            node.Tags = new TagsCollection();
            node.Tags.Add("type", "testnode1");
            node.Visible = true;
            node = apiInstance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);
            node = new Node();
            node.Latitude = -0.494497 + 0.0001f;
            node.Longitude = -24.119325 + 0.0001f;
            node.Tags = new TagsCollection();
            node.Tags.Add("type", "testnode2");
            node.Visible = true;
            node = apiInstance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);

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

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

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

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

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

            // open new changeset.
            apiInstance.ChangeSetOpen("Simple Way Delete Test");

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

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

            // get the way.
            Way apiWay = apiInstance.WayGet(way.Id.Value);
            Assert.IsNull(apiWay);
        }
示例#29
0
        /// <summary>
        /// Returns the ways for the given ids.
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public override IList<Way> GetWays(IList<long> ids)
        {
            if (ids.Count > 0)
            {
                SQLiteConnection con = this.CreateConnection();

                // STEP2: Load ways.
                Dictionary<long, Way> ways = new Dictionary<long, Way>();
                string sql;
                SQLiteCommand com;
                SQLiteDataReader reader;
                for (int idx_1000 = 0; idx_1000 <= ids.Count / 1000; idx_1000++)
                {
                    int start_idx = idx_1000 * 1000;
                    int stop_idx = System.Math.Min((idx_1000 + 1) * 1000, ids.Count);

                    sql = "SELECT id, changeset_id, visible, timestamp, version, usr, usr_id FROM way WHERE (id IN ({0})) ";
                    string ids_string = this.ConstructIdList(ids, start_idx, stop_idx);
                    if (ids_string.Length > 0)
                    {
                        sql = string.Format(sql, ids_string);
                        com = new SQLiteCommand(sql);
                        com.Connection = con;
                        reader = ExecuteReader(com);
                        Way way;
                        while (reader.Read())
                        {
                            long id = reader.GetInt64(0);
                            long? changeset_id = reader.IsDBNull(1) ? null : (long?)reader.GetInt64(1);
                            bool? visible = reader.IsDBNull(2) ? null : (bool?)reader.GetBoolean(2);
                            DateTime? timestamp = reader.IsDBNull(3) ? null : (DateTime?)this.ConvertDateTime(reader.GetInt64(3));
                            ulong? version = reader.IsDBNull(4) ? null : (ulong?)reader.GetInt64(4);
                            string user = reader.IsDBNull(5) ? null : reader.GetString(5);
                            long? user_id = reader.IsDBNull(6) ? null : (long?)reader.GetInt64(6);

                            // create way.
                            way = new Way();
                            way.Id = id;
                            way.Version = version;
                            way.UserName = user;
                            way.UserId = user_id;
                            way.Visible = visible;
                            way.TimeStamp = timestamp;
                            way.ChangeSetId = changeset_id;

                            ways.Add(way.Id.Value, way);
                        }
                        reader.Close();
                    }
                }

                //STEP3: Load all node-way relations
                List<long> missing_node_ids = new List<long>();
                for (int idx_1000 = 0; idx_1000 <= ids.Count / 1000; idx_1000++)
                {
                    int start_idx = idx_1000 * 1000;
                    int stop_idx = System.Math.Min((idx_1000 + 1) * 1000, ids.Count);

                    sql = "SELECT * FROM way_nodes WHERE (way_id IN ({0})) ORDER BY sequence_id";
                    string ids_string = this.ConstructIdList(ids, start_idx, stop_idx);
                    if (ids_string.Length > 0)
                    {
                        sql = string.Format(sql, ids_string);
                        com = new SQLiteCommand(sql);
                        com.Connection = con;
                        reader = ExecuteReader(com);
                        while (reader.Read())
                        {
                            long id = reader.GetInt64(0);
                            long node_id = reader.GetInt64(1);
                            long sequence_id = reader.GetInt64(2);

                            Way way;
                            if (ways.TryGetValue(id, out way))
                            {
                                if(way.Nodes == null)
                                {
                                    way.Nodes = new List<long>();
                                }
                                way.Nodes.Add(node_id);
                            }
                        }
                        reader.Close();
                    }
                }

                //STEP4: Load all tags.
                for (int idx_1000 = 0; idx_1000 <= ids.Count / 1000; idx_1000++)
                {
                    int start_idx = idx_1000 * 1000;
                    int stop_idx = System.Math.Min((idx_1000 + 1) * 1000, ids.Count);

                    sql = "SELECT * FROM way_tags WHERE (way_id IN ({0})) ";
                    string ids_string = this.ConstructIdList(ids, start_idx, stop_idx);
                    if (ids_string.Length > 0)
                    {
                        sql = string.Format(sql, ids_string);
                        com = new SQLiteCommand(sql);
                        com.Connection = con;
                        reader = ExecuteReader(com);
                        while (reader.Read())
                        {
                            long id = reader.GetInt64(0);
                            string key = reader.GetString(1);
                            object value_object = reader[2];
                            string value = string.Empty;
                            if (value_object != null && value_object != DBNull.Value)
                            {
                                value = (string)value_object;
                            }

                            Way way;
                            if (ways.TryGetValue(id, out way))
                            {
                                if (way.Tags == null)
                                {
                                    way.Tags = new TagsCollection();
                                }
                                way.Tags.Add(key, value);
                            }
                        }
                        reader.Close();
                    }
                }

                return ways.Values.ToList<Way>();
            }
            return new List<Way>();
        }
示例#30
0
        public void APITestWayCreateGetUpdate()
        {
            // intialize the connection.
            var apiInstance = new APIConnection("http://api06.dev.openstreetmap.org/",
                "osmsharp", "osmsharp");

            // open a changeset.
            apiInstance.ChangeSetOpen("Simple Way Creation Test");

            // initialize the way.
            var way = new Way();
            way.Tags = new TagsCollection();
            way.Tags.Add("type", "testway");
            way.Nodes = new List<long>();
            way.Visible = true;

            // initialize the nodes.
            var node = new Node();
            node.Latitude = -0.494497;
            node.Longitude = -24.119325;
            node.Tags = new TagsCollection();
            node.Tags.Add("type", "testnode1");
            node.Visible = true;
            node = apiInstance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);
            node = new Node();
            node.Latitude = -0.494497 + 0.0001f;
            node.Longitude = -24.119325 + 0.0001f;
            node.Tags = new TagsCollection();
            node.Tags.Add("type", "testnode2");
            node.Visible = true;
            node = apiInstance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);

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

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

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

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

            // open new changeset.
            apiInstance.ChangeSetOpen("Simple Way Update Test");

            // get the way.
            Way apiWay = apiInstance.WayGet(way.Id.Value);
            apiWay.Tags.Add("another_tag", "test adding a tag!");
            apiInstance.WayUpdate(apiWay);

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

            // get the api way.
            apiWay = apiInstance.WayGet(way.Id.Value);

            Assert.AreEqual(2, apiWay.Tags.Count);
            Assert.IsTrue(apiWay.Tags.ContainsKey("another_tag"));
            Assert.AreEqual("test adding a tag!", apiWay.Tags["another_tag"]);
        }
        private void Create(Way 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);
        }
        private void Delete(Way 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();
        }
        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;
            }
        }
示例#34
0
        /// <summary>
        /// Creates a relation from a SimpleRelation.
        /// </summary>
        /// <param name="simpleRelation"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        public static CompleteRelation CreateFrom(Relation simpleRelation, IDataSourceReadOnly cache)
        {
            if (simpleRelation == null)
            {
                throw new ArgumentNullException("simpleRelation");
            }
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (simpleRelation.Id == null)
            {
                throw new Exception("simpleRelation.Id is null");
            }

            CompleteRelation relation = Create(simpleRelation.Id.Value);

            relation.ChangeSetId = simpleRelation.ChangeSetId;
            foreach (Tag pair in simpleRelation.Tags)
            {
                relation.Tags.Add(pair);
            }
            for (int idx = 0; idx < simpleRelation.Members.Count; idx++)
            {
                long   memberId = simpleRelation.Members[idx].MemberId.Value;
                string role     = simpleRelation.Members[idx].MemberRole;

                var member = new CompleteRelationMember();
                member.Role = role;
                switch (simpleRelation.Members[idx].MemberType.Value)
                {
                case OsmGeoType.Node:
                    Node simpleNode = cache.GetNode(memberId);
                    if (simpleNode != null)
                    {
                        member.Member = CompleteNode.CreateFrom(simpleNode);
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Way:
                    Way simpleWay = cache.GetWay(memberId);
                    if (simpleWay != null)
                    {
                        member.Member = CompleteWay.CreateFrom(simpleWay, cache);
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Relation:
                    Relation simpleRelationMember = cache.GetRelation(memberId);
                    if (simpleRelationMember != null)
                    {
                        member.Member = CompleteRelation.CreateFrom(simpleRelationMember, cache);
                    }
                    else
                    {
                        return(null);
                    }
                    break;
                }
                relation.Members.Add(member);
            }
            relation.TimeStamp = simpleRelation.TimeStamp;
            relation.User      = simpleRelation.UserName;
            relation.UserId    = simpleRelation.UserId;
            relation.Version   = simpleRelation.Version.HasValue ? (long)simpleRelation.Version.Value : (long?)null;
            relation.Visible   = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value;

            return(relation);
        }