Esempio n. 1
0
        private DenseNodes ReadDenseNodes()
        {
            reader.BeginReadMessage();
            var result = new DenseNodes();

            while (reader.State == ProtobufReaderState.Field)
            {
                switch (reader.FieldNumber)
                {
                case 1:
                    result.Ids.AddRange(reader.ReadPackedSInt64Array());
                    break;

                case 8:
                    result.Latitudes.AddRange(reader.ReadPackedSInt64Array());
                    break;

                case 9:
                    result.Longitudes.AddRange(reader.ReadPackedSInt64Array());
                    break;

                case 10:
                    result.KeysValues.AddRange(reader.ReadPackedInt64Array().Select(x => (int)x));
                    break;

                default:
                    reader.Skip();
                    break;
                }
            }
            reader.EndReadMessage();
            return(result);
        }
Esempio n. 2
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);
                }
            }
        }