Example #1
0
        /// <summary>
        /// Reads and parses a primitive block (PrimitiveBlock)
        /// </summary>
        /// <param name="primitiveBlock">Primitive block to parse</param>
        private void ReadPrimitiveBlock(PrimitiveBlock primitiveBlock)
        {
            double latOffset = .000000001 * primitiveBlock.lat_offset;
            double lonOffset = .000000001 * primitiveBlock.lon_offset;
            double granularity = .000000001 * primitiveBlock.granularity;

            foreach (PrimitiveGroup primitiveGroup in primitiveBlock.primitivegroup)
            {
                if (primitiveGroup.dense != null)
                {
                    ReadDenseNodes(primitiveBlock, primitiveGroup.dense, latOffset, lonOffset, granularity);
                }
                if (primitiveGroup.ways != null)
                {
                    ReadWays(primitiveBlock, primitiveGroup.ways);
                }
                if (primitiveGroup.relations != null)
                {
                    //ReadRelations(primitiveGroup.relations);
                }
            }
        }
Example #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;

                var way = new Way(osmpbfWay.id, stamp);
                for (int nodeRef = 0; nodeRef < osmpbfWay.refs.Count; nodeRef++)
                {
                    deltaref += osmpbfWay.refs[nodeRef];
                    way.Nodes.Add(this.AddNodeSimpleToNodesRefs(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);
                            if (_importConfigurator.GetTypeOGC(Type.GetType("OsmImportToSqlServer.OsmData.Way"),
                                key, out geoType))
                                way.GeoType = geoType;
                        }
                    }
                }

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

            }
        }
Example #3
0
        /// <summary>
        /// Reads and parses a dense nodes (DenseNodes)
        /// </summary>
        /// <param name="denseNodes">Dense nodes to parse</param>
        /// <param name="latOffset">Offset latitude = .000000001 * primitiveBlock.lat_offset</param>
        /// <param name="lonOffset">Longitude offset = .000000001 * primitiveBlock.lon_offset</param>
        /// <param name="granularity">Granularity = .000000001 * primitiveBlock.granularity</param>
        private void ReadDenseNodes(PrimitiveBlock primitiveBlock, DenseNodes denseNodes, double latOffset, double lonOffset, double granularity)
        {
            int l = 0;
            long deltaid = 0;
            long deltalat = 0;
            long deltalon = 0;
            long deltatimestamp = 0;
            long deltachangeset = 0;
            long deltauid = 0;
            long deltauser_sid = 0;
            int dateGranularity = primitiveBlock.date_granularity;

            string key;
            string val;
            int hashTag;
            int hashValue;

            int idKey;
            int idValue;

            TypeValueTag typeValueTag;

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

            for (int k = 0; k < denseNodes.id.Count; k++)
            {
                int has_tags = 0;
                deltaid += denseNodes.id[k];
                deltalat += denseNodes.lat[k];
                deltalon += denseNodes.lon[k];
                DateTime stamp = new DateTime();

                if (denseNodes.denseinfo != null)
                {
                    DenseInfo denseinfo = denseNodes.denseinfo;

                    deltatimestamp += denseinfo.timestamp[k];
                    //deltachangeset += denseinfo.changeset[k];
                    //deltauid += denseinfo.uid[k];
                    //deltauser_sid += denseinfo.user_sid[k];

                    stamp = this.timeEpoche.AddSeconds(deltatimestamp * dateGranularity / 1000);

                }

                Node node = new Node(deltaid, latOffset + (deltalat * granularity),
                                             lonOffset + (deltalon * granularity), stamp);

                IsImportToDb = false;

                if (l < denseNodes.keys_vals.Count)
                {
                    while (denseNodes.keys_vals[l] != 0 && l < denseNodes.keys_vals.Count)
                    {
                        if (has_tags < 1)
                        {
                            has_tags++;
                        }
                        key = UTF8Encoding.UTF8.GetString(
                            primitiveBlock.stringtable.s[denseNodes.keys_vals[l]]);
                        val = UTF8Encoding.UTF8.GetString(
                                primitiveBlock.stringtable.s[denseNodes.keys_vals[l + 1]]);

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

                        if (typeValueTag != TypeValueTag.NoImport)
                        {
                            IsImportToDb = true;
                            this.InsertTagsAndValue(node.Id, idKey, idValue, val, typeValueTag);
                        }
                        l += 2;
                    }
                    l += 1;
                }

                // Check whether there is a tags of an object
                if (IsImportToDb)
                {
                    node.GeoType = new GeoType(GeoTypeOGC.Point);
                    //_nodesOsm.Add(node.Id, node);
                    this.AddNode(node);
                }
                else
                {
                    //_nodesOsm.Add(node.Id, node);
                    this.AddNode(node);
                }

            }
        }