Ejemplo n.º 1
0
        private void WriteWay(SWay way)
        {
            if (waysCount == 0)
            {
                writer.Write((byte)0);
            }

            waysCount++;

            wayIdWriter.WriteZigZag(way.Id);
            writer.Write7BitEncodedInt((ulong)way.WayType);
            writer.Write7BitEncodedInt((ulong)way.Nodes.Count);

            wayNodeIdWriter.Reset();
            wayLatWriter.Reset();
            wayLonWriter.Reset();

            foreach (var node in way.Nodes)
            {
                wayNodesCount++;
                wayNodeIdWriter.WriteZigZag((long)node.Id);
                wayLatWriter.WriteZigZag(node.Lat);
                wayLonWriter.WriteZigZag(node.Lon);
            }
        }
Ejemplo n.º 2
0
        private void Clear()
        {
            writer.Flush();
            stream.Flush();

            stream.Position = 0;
            stream.SetLength(0);

            BoundingRect.Reset();

            nodeIdWriter.Reset();
            nodeLatWriter.Reset();
            nodeLonWriter.Reset();

            wayIdWriter.Reset();
            wayNodeIdWriter.Reset();
            wayLatWriter.Reset();
            wayLonWriter.Reset();

            wayIdReader.Reset();
            wayNodeIdReader.Reset();
            wayLatReader.Reset();
            wayLonReader.Reset();

            nodesCount    = 0;
            waysCount     = 0;
            wayNodesCount = 0;
        }
        public void Add(OsmRelation relation, int typeId, IReadOnlyList <RelationItemInfo> itemInfos, BoundingRect rect)
        {
            if (relation == null)
            {
                throw new ArgumentNullException(nameof(relation));
            }
            if (itemInfos == null)
            {
                throw new ArgumentNullException(nameof(itemInfos));
            }
            if (rect == null)
            {
                throw new ArgumentNullException(nameof(rect));
            }

            startPositions.Add(new RelationLocation
            {
                Id     = relation.Id,
                Offset = stream.Position
            });

            idWriter.WriteIncrementOnly((ulong)relation.Id);
            writer.Write7BitEncodedInt((ulong)typeId);

            rect.WriteTo(writer);

            writer.Write7BitEncodedInt((ulong)relation.Items.Count);

            memberIdWriter.Reset();
            memberMidLatWriter.Reset();
            memberMidLonWriter.Reset();

            for (var index = 0; index < relation.Items.Count; index++)
            {
                var member = relation.Items[index];
                writer.Write((byte)member.MemberType);
                memberIdWriter.WriteZigZag(member.Id);
                writer.Write7BitEncodedInt(GetRoleId(member.Role));

                var info = itemInfos[index];
                memberMidLatWriter.WriteZigZag(info.MidLat);
                memberMidLonWriter.WriteZigZag(info.MidLon);
            }
        }
Ejemplo n.º 4
0
        private void WriteWayData(SWay way)
        {
            idWriter.WriteIncrementOnly((ulong)way.Id);

            var nodes = way.Nodes;

            waysWriter.Write7BitEncodedInt((ulong)nodes.Count);

            nodeIdWriter.Reset();
            latWriter.Reset();
            lonWriter.Reset();

            foreach (var node in nodes)
            {
                nodeIdWriter.WriteZigZag(node.Id);
                latWriter.WriteZigZag(node.Lat);
                lonWriter.WriteZigZag(node.Lon);
            }
        }