Exemplo n.º 1
0
        /// <summary>
        /// Reads and parses a ways (OSMPBF.Way)
        /// </summary>
        /// <param name="ways">List of ways</param>
        private void ReadWays(PrimitiveBlock primitiveBlock, List <Helpers.ReadPdb.Way> ways)
        {
            int dateGranularity = primitiveBlock.date_granularity;

            long second = 0;

            string key, val;
            int    idKey, idValue;

            TypeValueTag typeValueTag;

            // Is it possible to import on the basis of the presence of significant tags
            bool IsImportToDb;

            for (int wayIndex = 0; wayIndex < ways.Count; wayIndex++)
            {
                Helpers.ReadPdb.Way osmpbfWay = ways[wayIndex];

                DateTime stamp = new DateTime();

                if (osmpbfWay.info != null)
                {
                    Info info = osmpbfWay.info;
                    second = (info.timestamp * dateGranularity) / 1000;
                    stamp  = this.timeEpoche.AddSeconds(second);
                }
                long deltaref = 0;
                Way  way      = new Way(osmpbfWay.id, stamp);
                for (int nodeRef = 0; nodeRef < osmpbfWay.refs.Count; nodeRef++)
                {
                    deltaref += osmpbfWay.refs[nodeRef];
                    way.AddNode(_nodesOsm[deltaref]);
                }

                IsImportToDb = false;
                GeoType geoType = null;

                if (osmpbfWay.keys.Count != 0 || osmpbfWay.keys.Count != 0)
                {
                    for (int keyId = 0; keyId < osmpbfWay.keys.Count; keyId++)
                    {
                        key = UTF8Encoding.UTF8.GetString(
                            primitiveBlock.stringtable.s[Convert.ToInt32(osmpbfWay.keys[keyId])]);
                        val = UTF8Encoding.UTF8.GetString(
                            primitiveBlock.stringtable.s[Convert.ToInt32(osmpbfWay.vals[keyId])]);

                        OsmRepository.TagsRepository.AddTag(key, val, out idKey, out idValue, out typeValueTag);

                        if (typeValueTag != TypeValueTag.NoImport)
                        {
                            IsImportToDb = true;
                            this.InsertTagsAndValue(way.Id, idKey, idValue, val, typeValueTag);
                        }
                    }
                }

                //// DEBUG
                //Console.WriteLine(DateTime.Now + " Way - " + way.Id + ", " + way.Nodes.Count + " nodes");
                if (IsImportToDb)
                {
                    if (geoType != null)
                    {
                        way.GeoType = geoType;
                        _waysOsm.Add(way.Id, way);
                    }
                    else
                    {
                        way.GeoType = this.WayIsPolygonOrLine(way);
                        _waysOsm.Add(way.Id, way);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads and parses a ways (OSMPBF.Way)
        /// </summary>
        /// <param name="ways">List of ways</param>
        private void ReadWays(PrimitiveBlock primitiveBlock, List<Helpers.ReadPdb.Way> ways)
        {
            int dateGranularity = primitiveBlock.date_granularity;

            long second = 0;

            string key, val;
            int idKey, idValue;

            TypeValueTag typeValueTag;

            // Is it possible to import on the basis of the presence of significant tags
            bool IsImportToDb;

            for (int wayIndex = 0; wayIndex < ways.Count; wayIndex++)
            {
                Helpers.ReadPdb.Way osmpbfWay = ways[wayIndex];

                DateTime stamp = new DateTime();

                if (osmpbfWay.info != null)
                {
                    Info info = osmpbfWay.info;
                    second = (info.timestamp * dateGranularity) / 1000;
                    stamp = this.timeEpoche.AddSeconds(second);
                }
                long deltaref = 0;
                Way way = new Way(osmpbfWay.id, stamp);
                for (int nodeRef = 0; nodeRef < osmpbfWay.refs.Count; nodeRef++)
                {
                    deltaref += osmpbfWay.refs[nodeRef];
                    way.AddNode(_nodesOsm[deltaref]);
                }

                IsImportToDb = false;
                GeoType geoType = null;

                if (osmpbfWay.keys.Count != 0 || osmpbfWay.keys.Count != 0)
                {
                    for (int keyId = 0; keyId < osmpbfWay.keys.Count; keyId++)
                    {
                        key = UTF8Encoding.UTF8.GetString(
                            primitiveBlock.stringtable.s[Convert.ToInt32(osmpbfWay.keys[keyId])]);
                        val = UTF8Encoding.UTF8.GetString(
                                primitiveBlock.stringtable.s[Convert.ToInt32(osmpbfWay.vals[keyId])]);

                        OsmRepository.TagsRepository.AddTag(key, val, out idKey, out idValue, out typeValueTag);

                        if (typeValueTag != TypeValueTag.NoImport)
                        {
                            IsImportToDb = true;
                            this.InsertTagsAndValue(way.Id, idKey, idValue, val, typeValueTag);
                        }
                    }
                }

                //// DEBUG
                //Console.WriteLine(DateTime.Now + " Way - " + way.Id + ", " + way.Nodes.Count + " nodes");
                if (IsImportToDb)
                {
                    if (geoType != null)
                    {
                        way.GeoType = geoType;
                        _waysOsm.Add(way.Id, way);
                    }
                    else
                    {
                        way.GeoType = this.WayIsPolygonOrLine(way);
                        _waysOsm.Add(way.Id, way);
                    }
                }

            }
        }