public int date_granularity = 1000;                                        // 18

        internal static PrimitiveBlock Read(Stream stream)
        {
            PrimitiveBlock obj = new PrimitiveBlock();
            int            b   = stream.ReadByte();

            if (b != 10)
            {
                throw new NotImplementedException();
            }
            obj.stringtable = StringTable.Read(stream);
            b = stream.ReadByte();
            while (b == 18)
            {
                obj.primitivegroup.Add(PrimitiveGroup.Read(stream));
                b = stream.ReadByte();
            }
            // NOTE: looks like those OSMSharp broken up files don't have any of these
            if (b == 136)
            {
                obj.granularity = (int)OSMReader.ReadVarInt(stream);
                b = stream.ReadByte();
            }
            if (b == 152)
            {
                obj.lat_offset = OSMReader.ReadVarInt(stream);
                b = stream.ReadByte();
            }
            if (b == 160)
            {
                obj.lon_offset = OSMReader.ReadVarInt(stream);
                b = stream.ReadByte();
            }
            if (b == 144)
            {
                obj.date_granularity = (int)OSMReader.ReadVarInt(stream);
                b = stream.ReadByte();
            }
            if (b != -1)
            {
                throw new NotImplementedException();
            }
            return(obj);
        }
Exemple #2
0
        internal static StringTable Read(Stream stream)
        {
            StringTable obj    = new StringTable();
            long        length = OSMReader.ReadVarInt(stream);
            long        end    = stream.Position + length;

            obj.vals = new List <string>();
            while (stream.Position < end)
            {
                int b = stream.ReadByte();
                if (b != 10)
                {
                    throw new NotImplementedException();
                }
                obj.vals.Add(OSMReader.ReadString(stream));
            }
            if (stream.Position != end)
            {
                throw new NotImplementedException();
            }
            return(obj);
        }
Exemple #3
0
        public List <long> refs = new List <long>(); // 8, packed, signed, delta coded

        internal static Way Read(Stream stream)
        {
            Way  obj           = new Way();
            long lengthInBytes = OSMReader.ReadVarInt(stream);
            long end           = stream.Position + lengthInBytes;
            int  b             = stream.ReadByte();

            if (b != 8)
            {
                throw new NotImplementedException();
            }
            obj.id = OSMReader.ReadVarInt(stream);
            b      = stream.ReadByte();
            if (b == 18)
            {
                obj.keys = OSMReader.ReadPackedVarInts(stream).ConvertAll(x => (int)x).ToList();
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 26)
            {
                obj.vals = OSMReader.ReadPackedVarInts(stream).ConvertAll(x => (int)x).ToList();
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 34)
            {
                //obj.info = Info.Read(stream);
                OSMReader.SkipBytes(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 66)
            {
                obj.refs = OSMReader.ReadPackedDeltaCodedVarInts(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            throw new NotImplementedException();
        }
Exemple #4
0
        internal static DenseNodes ReadNodeStart(MemoryStream stream)
        {
            DenseNodes obj           = new DenseNodes();
            long       lengthInBytes = OSMReader.ReadVarInt(stream);
            long       end           = stream.Position + lengthInBytes;
            int        b             = stream.ReadByte();

            if (b == 10)
            {
                obj.id = new List <long>();
                long length = OSMReader.ReadVarInt(stream);
                if (length > 0)
                {
                    obj.id.Add(OSMReader.ReadSignedVarInt(stream));
                }
                stream.Seek(end, SeekOrigin.Begin);
                return(obj);
            }
            if (b == 42)
            {
                OSMReader.SkipBytes(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 66)
            {
                OSMReader.SkipBytes(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 74)
            {
                OSMReader.SkipBytes(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 82)
            {
                OSMReader.SkipBytes(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            throw new NotImplementedException();
        }
Exemple #5
0
        public List <int> keys_vals = new List <int>();  // 10, packed

        internal static DenseNodes Read(Stream stream)
        {
            DenseNodes obj           = new DenseNodes();
            long       lengthInBytes = OSMReader.ReadVarInt(stream);
            long       end           = stream.Position + lengthInBytes;
            int        b             = stream.ReadByte();

            if (b == 10)
            {
                obj.id = OSMReader.ReadPackedDeltaCodedVarInts(stream);
                b      = stream.ReadByte();
            }
            if (b == 42)
            {
                //obj.denseinfo = DenseInfo.Read(stream);
                OSMReader.SkipBytes(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 66)
            {
                obj.lat = OSMReader.ReadPackedDeltaCodedVarInts(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 74)
            {
                obj.lon = OSMReader.ReadPackedDeltaCodedVarInts(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 82)
            {
                //obj.keys_vals = OSM.ReadPackedVarInts(stream).ConvertAll(x => (int)x).ToList();
                OSMReader.SkipBytes(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            throw new NotImplementedException();
        }
        private void LoadDetailsFromSource(ISector sector)
        {
            BlobCollection blobs = OSMReader.GetAllBlobs(sector);

            foreach (var way in blobs.EnumerateWays(false))
            {
                for (int i = 0; i < way.refs.Count; i++)
                {
                    long ref1 = way.refs[i];
                    long ref2 = way.refs[(i + 1) % way.refs.Count];
                    if (ref1 == ref2)
                    {
                        continue;
                    }
                    Vector2d v1       = blobs.nodes[ref1];
                    Vector2d v2       = blobs.nodes[ref2];
                    LongLat  longLat1 = new SphereVector(sector.ProjectToSphereCoordinates(v1)).ToLongLat();
                    LongLat  longLat2 = new SphereVector(sector.ProjectToSphereCoordinates(v2)).ToLongLat();
                    // hmm, this logic will ignore edges that brush up exactly against the top or left of their sector (ex: nodes 6151473219, 6151473220 in way 146849673)
                    // I have to compensate for this elswhere
                    ISector sector1 = GetContainingSector(longLat1, 8);
                    ISector sector2 = GetContainingSector(longLat2, 8);
                    if (!sector1.Equals(sector2))
                    {
                        var e = new EdgeInfo()
                        {
                            wayID = way.id, node1 = ref1, node2 = ref2, longLat1 = longLat1, longLat2 = longLat2
                        };
                        if (!edgeInfo.Contains(e))
                        {
                            edgeInfo.Add(e);
                        }
                        List <int> wKeys = new List <int>();
                        List <int> wVals = new List <int>();
                        foreach (var pair in way.keyValues)
                        {
                            wKeys.Add(LoadIntoStringTable(pair.Key));
                            wVals.Add(LoadIntoStringTable(pair.Value));
                        }
                        var w = new WayInfo()
                        {
                            id = way.id, keys = wKeys, values = wVals, startNode = way.refs.First(), endNode = way.refs.Last(), relations = new List <long>()
                        };
                        if (!wayInfo.ContainsKey(w.id))
                        {
                            wayInfo[w.id] = w;
                        }
                    }
                }
            }
            HashSet <long> extraWays = new HashSet <long>();

            foreach (var relation in blobs.EnumerateRelations())
            {
                foreach (var way in relation.memids)
                {
                    extraWays.Add(way);
                    if (wayInfo.ContainsKey(way) && !relationInfo.ContainsKey(relation.id))
                    {
                        List <int> rKeys  = new List <int>();
                        List <int> rVals  = new List <int>();
                        List <int> rRoles = new List <int>();
                        foreach (var pair in relation.keyValues)
                        {
                            rKeys.Add(LoadIntoStringTable(pair.Key));
                            rVals.Add(LoadIntoStringTable(pair.Value));
                        }
                        foreach (var role in relation.roleValues)
                        {
                            rRoles.Add(LoadIntoStringTable(role));
                        }
                        var r = new RelationInfo()
                        {
                            id = relation.id, keys = rKeys, values = rVals, roleValues = rRoles, memids = relation.memids, types = relation.types
                        };
                        relationInfo[r.id] = r;
                    }
                }
            }
            foreach (var way in blobs.EnumerateWays(false))
            {
                if (!extraWays.Contains(way.id))
                {
                    continue;
                }
                List <int> wKeys = new List <int>();
                List <int> wVals = new List <int>();
                foreach (var pair in way.keyValues)
                {
                    wKeys.Add(LoadIntoStringTable(pair.Key));
                    wVals.Add(LoadIntoStringTable(pair.Value));
                }
                var w = new WayInfo()
                {
                    id = way.id, keys = wKeys, values = wVals, startNode = way.refs.First(), endNode = way.refs.Last()
                };
                if (!wayInfo.ContainsKey(w.id))
                {
                    wayInfo[w.id] = w;
                }
            }
        }
Exemple #7
0
        public List <bool> visible;   // 6, packed

        internal static DenseInfo Read(Stream stream)
        {
            DenseInfo obj           = new DenseInfo();
            long      lengthInBytes = OSMReader.ReadVarInt(stream);
            long      end           = stream.Position + lengthInBytes;
            int       b             = stream.ReadByte();

            if (b == 10)
            {
                obj.version = OSMReader.ReadPackedVarInts(stream).ConvertAll(x => (int)x).ToList();
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 18)
            {
                obj.timestamp = OSMReader.ReadPackedDeltaCodedVarInts(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 26)
            {
                obj.changeset = OSMReader.ReadPackedDeltaCodedVarInts(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 34)
            {
                obj.uid = OSMReader.ReadPackedDeltaCodedVarInts(stream).ConvertAll(x => (int)x).ToList();
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 42)
            {
                obj.user_sid = OSMReader.ReadPackedDeltaCodedVarInts(stream).ConvertAll(x => (int)x).ToList();
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 50)
            {
                OSMReader.SkipBytes(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            throw new NotImplementedException();
        }
Exemple #8
0
        public bool visible;     // 6

        internal static Info Read(Stream stream)
        {
            Info obj           = new Info();
            long lengthInBytes = OSMReader.ReadVarInt(stream);
            long end           = stream.Position + lengthInBytes;
            int  b             = stream.ReadByte();

            if (b == 8)
            {
                obj.version = (int)OSMReader.ReadVarInt(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 16)
            {
                obj.timestamp = (int)OSMReader.ReadVarInt(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 24)
            {
                obj.changeset = OSMReader.ReadVarInt(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 32)
            {
                obj.uid = (int)OSMReader.ReadVarInt(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 40)
            {
                obj.user_sid = (int)OSMReader.ReadVarInt(stream);
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            if (b == 48)
            {
                obj.visible = OSMReader.ReadVarInt(stream) == 1;
                if (stream.Position > end)
                {
                    throw new NotImplementedException();
                }
                if (stream.Position == end)
                {
                    return(obj);
                }
                b = stream.ReadByte();
            }
            throw new NotImplementedException();
        }
        public List <ChangeSet> changesets = new List <ChangeSet>();  // 5

        internal static PrimitiveGroup Read(Stream stream)
        {
            PrimitiveGroup obj           = new PrimitiveGroup();
            long           lengthInBytes = OSMReader.ReadVarInt(stream);
            long           end           = stream.Position + lengthInBytes;
            int            b             = stream.ReadByte();

            while (b == 10 || b == 18 || b == 26 || b == 34 || b == 42)
            {
                if (b == 10)
                {
                    OSMReader.SkipBytes(stream);
                    if (stream.Position > end)
                    {
                        throw new NotImplementedException();
                    }
                    if (stream.Position == end)
                    {
                        return(obj);
                    }
                    b = stream.ReadByte();
                }
                else if (b == 18)
                {
                    obj.dense.Add(DenseNodes.Read(stream));
                    if (stream.Position > end)
                    {
                        throw new NotImplementedException();
                    }
                    if (stream.Position == end)
                    {
                        return(obj);
                    }
                    b = stream.ReadByte();
                }
                else if (b == 26)
                {
                    obj.ways.Add(Way.Read(stream));
                    if (stream.Position > end)
                    {
                        throw new NotImplementedException();
                    }
                    if (stream.Position == end)
                    {
                        return(obj);
                    }
                    b = stream.ReadByte();
                }
                else if (b == 34)
                {
                    obj.relations.Add(Relation.Read(stream));
                    if (stream.Position > end)
                    {
                        throw new NotImplementedException();
                    }
                    if (stream.Position == end)
                    {
                        return(obj);
                    }
                    b = stream.ReadByte();
                }
                else if (b == 42)
                {
                    OSMReader.SkipBytes(stream);
                    if (stream.Position > end)
                    {
                        throw new NotImplementedException();
                    }
                    if (stream.Position == end)
                    {
                        return(obj);
                    }
                    b = stream.ReadByte();
                }
            }
            throw new NotImplementedException();
        }