Exemplo n.º 1
0
 public static void WriteBlobInfo(BinaryWriter writer, BlobIdsInfo info)
 {
     writer.Write(info.StartPosition);
     writer.Write(info.NodesCount);
     writer.Write(info.MinNodeId);
     writer.Write(info.MaxNodeId);
     writer.Write(info.WaysCount);
     writer.Write(info.RelationsCount);
 }
Exemplo n.º 2
0
 public static void WriteIdsIndex(string fileName, IEnumerable <BlobIdsInfo> infos)
 {
     using (var nodesStream = File.Open(fileName, FileMode.Create))
     {
         var writer = new BinaryWriter(nodesStream, Encoding.Unicode, true);
         foreach (var info in infos)
         {
             BlobIdsInfo.WriteBlobInfo(writer, info);
         }
     }
 }
Exemplo n.º 3
0
        public static BlobIdsInfo ReadBlobIdsInfo(BinaryReader reader)
        {
            var info = new BlobIdsInfo
            {
                StartPosition  = reader.ReadInt64(),
                NodesCount     = reader.ReadInt32(),
                MinNodeId      = reader.ReadInt64(),
                MaxNodeId      = reader.ReadInt64(),
                WaysCount      = reader.ReadInt32(),
                RelationsCount = reader.ReadInt32()
            };

            return(info);
        }
Exemplo n.º 4
0
        public static async Task Process(string fileName, string indexFileName)
        {
            var index = BlobIdsInfo.ReadIdsIndex(indexFileName).ToList();

            Console.WriteLine($"Index size: {index.Count}");

            using (var stream = File.OpenRead(fileName))
            {
                foreach (var info in index.Where(x => x.WaysCount > 0).Take(5))
                {
                    stream.Position = 0;
                    var parser = new PbfBlobParser(stream);
                    parser.SkipBlob((ulong)(info.StartPosition - 4));
                    var header = await parser.ReadBlobHeader();

                    var blob = await parser.ReadBlobAsync(header);

                    var primitiveReader = PbfPrimitiveReader.Create(blob);
                    var data            = primitiveReader.ReadData();

                    var ways = PrimitiveDecoder.DecodeWays(data).ToList();

                    Console.WriteLine();

                    foreach (var way in ways)
                    {
                        var nodeIds = way.NodeIds.Distinct().OrderBy(x => x).ToList();

                        var blobsToRead = FindBlobIdsToRead(index, nodeIds);

                        Console.WriteLine($"Id: {way.Id}, Cnt: {blobsToRead.Count}. {string.Join(", ",blobsToRead)}");
                    }
                }
            }

            Console.WriteLine("Done! Press any key....");
            Console.ReadKey();
        }