示例#1
0
        /// <summary>
        /// Tests read/write and actual data file.
        /// </summary>
        protected void TestReadWriteData()
        {
            this.NotifyEmptyExpected(); // empty test database.

            // create the target and pull the data from the test-file into the sqlite database.
            OsmStreamTarget    target = this.CreateDataStreamTarget();
            PBFOsmStreamSource source = new PBFOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf"));

            target.RegisterSource(source);
            target.Pull();

            IDataSourceReadOnly dataSource   = this.CreateDataSource();
            MemoryDataSource    memorySource = MemoryDataSource.CreateFrom(source);

            foreach (Node node in memorySource.GetNodes())
            {
                Node dbNode = dataSource.GetNode(node.Id.Value);
                this.CompareNodes(node, dbNode);
            }
            foreach (Way way in memorySource.GetWays())
            {
                Way dbWay = dataSource.GetWay(way.Id.Value);
                this.CompareWays(way, dbWay);
            }
            foreach (Relation relation in memorySource.GetRelations())
            {
                Relation dbRelation = dataSource.GetRelation(relation.Id.Value);
                this.CompareRelations(relation, dbRelation);
            }
        }
示例#2
0
        /// <summary>
        /// Returns the node with the given id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public override Node GetNode(long id)
        {
            Node node;

            if (!_nodesCache.TryGet(id, out node))
            { // cache miss.
                node = _source.GetNode(id);
                _nodesCache.Add(id, node);
            }
            return(node);
        }
示例#3
0
        /// <summary>
        /// Creates a new way from a SimpleWay.
        /// </summary>
        /// <param name="simpleWay"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        public static CompleteWay CreateFrom(Way simpleWay, IDataSourceReadOnly cache)
        {
            if (simpleWay == null)
            {
                throw new ArgumentNullException("simpleWay");
            }
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (simpleWay.Id == null)
            {
                throw new Exception("simpleWay.id is null");
            }

            CompleteWay way = Create(simpleWay.Id.Value);

            way.ChangeSetId = simpleWay.ChangeSetId;
            if (simpleWay.Tags != null)
            {
                foreach (Tag pair in simpleWay.Tags)
                {
                    way.Tags.Add(pair);
                }
            }
            for (int idx = 0; idx < simpleWay.Nodes.Count; idx++)
            {
                long nodeId = simpleWay.Nodes[idx];
                Node node   = cache.GetNode(nodeId);
                if (node != null)
                {
                    way.Nodes.Add(CompleteNode.CreateFrom(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);
        }
示例#4
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);
        }
示例#5
0
        /// <summary>
        /// Tests if the data present is the data from api.osm.
        /// </summary>
        private void TestData(IDataSourceReadOnly data)
        {
            // test what data is present in the datasource.
            Node node_291738780 = data.GetNode(291738780);
            Assert.IsNotNull(node_291738780);
            Assert.AreEqual(291738780, node_291738780.Id);

            Node node_1727654333 = data.GetNode(1727654333);
            Assert.IsNotNull(node_1727654333);
            Assert.AreEqual(1727654333, node_1727654333.Id);

            Way way_87281441 = data.GetWay(87281441);
            Assert.IsNotNull(way_87281441);
            Assert.AreEqual(87281441, way_87281441.Id);

            Way way_76705106 = data.GetWay(76705106);
            Assert.IsNotNull(way_76705106);
            Assert.AreEqual(76705106, way_76705106.Id);
        }