Beispiel #1
0
        static void WriteStartByte(ByteRange byteRange)
        {
            string startByte = byteRange.ToString().PadRight(ByteTiles.HeaderByteRangeLength, ' ');

            byte[] byteArray = Encoding.UTF8.GetBytes(startByte);
            FileStream.Write(byteArray, 0, byteArray.Length);
        }
Beispiel #2
0
 public byte[] GetData(ByteRange byteRange)
 {
     byte[] byteArray = new byte[byteRange.Length];
     using FileStream fileStream = new(InputFile, FileMode.Open, FileAccess.Read);
     fileStream.Seek(byteRange.Position, SeekOrigin.Begin);
     fileStream.Read(byteArray, 0, byteRange.Length);
     return(byteArray);
 }
Beispiel #3
0
        public Header(string json)
        {
            var keyValuePairs = JsonSerializer.Deserialize <Dictionary <string, string> >(json);

            Version         = keyValuePairs["version"];
            MetaData        = new ByteRange(keyValuePairs["metadata"]);
            TilesDictionary = new ByteRange(keyValuePairs["tiles_dictionary"]);

            if (keyValuePairs.ContainsKey("grids_dictionary"))
            {
                GridsDictionary = new ByteRange(keyValuePairs["grids_dictionary"]);
            }
            if (keyValuePairs.ContainsKey("grid_data_dictionary"))
            {
                GridDataDictionary = new ByteRange(keyValuePairs["grid_data_dictionary"]);
            }
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input">.mbtiles file</param>
        /// <param name="output">.bytetiles file</param>
        /// <param name="decompress">GZip decompress (for .pfb content)</param>
        public static void ParseMBTiles(string input, string output, bool decompress = false)
        {
            MBTilesReader mBTilesReader = new(input);

            Position   = 0;
            OutputFile = output;
            File.Delete(OutputFile);
            byteRangeMetadata = new Header();

            FileStream = new FileStream(OutputFile, FileMode.Append, FileAccess.Write);
            WriteTableTiles(mBTilesReader, decompress);
            WriteTableMetadata(mBTilesReader);
            ByteRange byteRange = WriteByteRangeMetadata();

            WriteStartByte(byteRange);
            FileStream.Close();
        }
Beispiel #5
0
        static void WriteTableTiles(MBTilesReader mBTilesReader, bool decompress)
        {
            var tiles = mBTilesReader.GetTiles();

            Position = 0;
            int    counter        = 0;
            string percentageDone = string.Empty;

            Dictionary <string, string> dictionaryMap = new();
            int    total = tiles.Count;
            object sync  = new();

            Parallel.ForEach(tiles,
                             tilesRow =>
            {
                byte[] bytes = tilesRow.Tile_data;
                if (decompress)
                {
                    bytes = Decompress(bytes);
                }
                lock (sync)
                {
                    ByteRange byteRange = Write(bytes);
                    string tileKey      = tilesRow.TileKey().ToString();
                    dictionaryMap.Add(tileKey, byteRange.ToString());

                    counter++;
                    double percentage        = counter * 100 / total;
                    string percentageDoneAux = percentage.ToString("#.#");
                    if (!percentageDone.Equals(percentageDoneAux))
                    {
                        percentageDone = percentageDoneAux;
                        Console.WriteLine("Completed " + percentageDone + "%");
                    }
                }
            });

            string dictionary = JsonSerializer.Serialize(dictionaryMap);

            byteRangeMetadata.TilesDictionary = Write(dictionary);
        }