コード例 #1
0
        /// <summary>
        /// Creates a new instaance of the OsmDatabase class and loads data from specific IOsmReader into it.
        /// </summary>
        /// <param name="reader">The IOsmReader to read data from.</param>
        /// <returns>New instance of the OsmDAtabase class with data loaded from specified reader.</returns>
        public static OsmEntityInfoDatabase Load(IOsmReader reader)
        {
            OsmEntityInfoDatabase db = new OsmEntityInfoDatabase();

            IEntityInfo entityInfo = null;

            while ((entityInfo = reader.Read()) != null)
            {
                switch (entityInfo.EntityType)
                {
                case EntityType.Node: db.Nodes.Add((NodeInfo)entityInfo); break;

                case EntityType.Way: db.Ways.Add((WayInfo)entityInfo); break;

                case EntityType.Relation: db.Relations.Add((RelationInfo)entityInfo); break;
                }
            }

            return(db);
        }
コード例 #2
0
        private void TestReader(IOsmReader reader)
        {
            IEntityInfo info = null;
            int         nodesCount = 0, waysCount = 0, relationsCount = 0;

            while ((info = reader.Read()) != null)
            {
                switch (info.EntityType)
                {
                case EntityType.Node: nodesCount++; break;

                case EntityType.Way: waysCount++; break;

                case EntityType.Relation: relationsCount++; break;
                }
            }

            Assert.Equal(TestFileNodesCount, nodesCount);
            Assert.Equal(TestFileWaysCount, waysCount);
            Assert.Equal(TestFileRelationsCount, relationsCount);
        }
コード例 #3
0
        private void TestReader(IOsmReader reader)
        {
            IEntityInfo info = null;
            int nodesCount = 0, waysCount = 0, relationsCount = 0;
            while ((info = reader.Read()) != null) {
                switch (info.EntityType) {
                    case EntityType.Node: nodesCount++; break;
                    case EntityType.Way: waysCount++; break;
                    case EntityType.Relation: relationsCount++; break;
                }
            }

            Assert.Equal(TestFileNodesCount, nodesCount);
            Assert.Equal(TestFileWaysCount, waysCount);
            Assert.Equal(TestFileRelationsCount, relationsCount);
        }
コード例 #4
0
        /// <summary>
        /// Creates a new instaance of the OsmDatabase class and loads data from specific IOsmReader into it.
        /// </summary>
        /// <param name="reader">The IOsmReader to read data from.</param>
        /// <param name="ignoreReferentialErrors">A value indicatings whether Load function should skip geometries that reference miising geometries.</param>
        /// <returns>New instance of the OsmDatabase class with data loaded from specified reader.</returns>
        public static OsmGeometryDatabase Load(IOsmReader reader, bool ignoreReferentialErrors)
        {
            OsmGeometryDatabase db = new OsmGeometryDatabase();

            List <RelationInfo> relations = new List <RelationInfo>();

            IEntityInfo entityInfo = null;

            while ((entityInfo = reader.Read()) != null)
            {
                switch (entityInfo.EntityType)
                {
                case EntityType.Node: db.Nodes.Add(Node.FromNodeInfo(entityInfo as NodeInfo)); break;

                case EntityType.Way:
                    Way toAdd = Way.FromWayInfo(entityInfo as WayInfo, db, !ignoreReferentialErrors);
                    if (toAdd == null)
                    {
                        if (!ignoreReferentialErrors)
                        {
                            throw new ArgumentException(string.Format("Way (ID = {0}) references missing node.", entityInfo.ID));
                        }
                    }
                    else
                    {
                        db.Ways.Add(toAdd);
                    }

                    break;

                case EntityType.Relation:
                    RelationInfo ri = entityInfo as RelationInfo;
                    db.Relations.Add(new Relation(ri.ID)
                    {
                        Tags = ri.Tags, Metadata = ri.Metadata
                    });
                    relations.Add(ri);
                    break;
                }
            }

            foreach (var relationInfo in relations)
            {
                Relation relation = db.Relations[relationInfo.ID];

                foreach (var memberInfo in relationInfo.Members)
                {
                    RelationMember member = RelationMember.FromRelationMemberInfo(memberInfo, db, false);
                    if (member == null)
                    {
                        if (!ignoreReferentialErrors)
                        {
                            throw new ArgumentException(string.Format("Relation (ID = {0}) references missing OSM entity.", memberInfo.Reference));
                        }

                        db.Relations.Remove(relation);
                    }
                    else
                    {
                        relation.Geometries.Add(member);
                    }
                }
            }

            return(db);
        }