/// <summary>
        /// 读取指定行列号的数据
        /// </summary>
        /// <param name="level"></param>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <returns></returns>
        public Byte[] Read(int level, int row, int col)
        {
            string bundleFilePath = GetBundleFileWithouExtention(level, row, col);

            // 打开对应的索引文件
            EsriBundleIndexFile indexFile = new EsriBundleIndexFile(bundleFilePath + EsriBundleFileConfig.BundleIndexExt);
            indexFile.Intiliaze();

            // 读取所有索引
            var bundleIndices = indexFile.GetAllIndices();
            // 读取数据文件
            EsriBundleFile dataFile = new EsriBundleFile(bundleFilePath + EsriBundleFileConfig.BundleExt, bundleIndices);
            dataFile.Intiliaze();
            int index;
            EsriBundleHelper.ComputeIndex(row, col, PacketSize, out index);

            var tileBytes = dataFile.Read(index);
            indexFile.Dispose();
            dataFile.Dispose();
            return tileBytes;
        }
Exemple #2
0
        static void CreateIndexFile(string oldfilepath, string newfilepath)
        {
            EsriBundleIndexFile indexfile = new EsriBundleIndexFile(oldfilepath);
            indexfile.Intiliaze();
            //indexfile.SaveAs(newfilepath);

            EsriBundleIndexFile indexfile1 = new EsriBundleIndexFile(indexfile.GetAllIndices());
            indexfile1.Intiliaze();
            indexfile1.SaveAs(newfilepath);
            indexfile1.Dispose();
            indexfile.Dispose();
        }
Exemple #3
0
        public void NewFileModeSaveAs(string newDataPath, Dictionary<int, byte[]> tilesBytesDict)
        {
            Config.NotNullTileCount = tilesBytesDict.Count;
            Config.MaxTileSize = 0;
            IList<TileIndex> allIndices = new List<TileIndex>();
            using (Stream newDataStream = new FileStream(newDataPath, FileMode.CreateNew))
            {
                // 写入所有数据的空数据位置,每个4字节,空数据按其索引指向此位置
                newDataStream.Seek(EsriBundleFileConfig.HeaderSize, SeekOrigin.Begin);
                newDataStream.Write(new byte[EsriBundleFileConfig.MaxTileCount * 4], 0, EsriBundleFileConfig.MaxTileCount * 4);

                for (int i = 0; i < EsriBundleFileConfig.MaxTileCount; i++)
                {
                    byte[] dataBytes = null;
                    tilesBytesDict.TryGetValue(i, out dataBytes);

                    // 数据为空,只写入4个字节的长度,表示0
                    if (dataBytes == null)
                    {
                        //计算索引位置,位于空数据位置
                        allIndices.Add(new TileIndex()
                        {
                            Number = i,
                            Offset = EsriBundleFileConfig.HeaderSize + 4 * i
                        });
                    }
                    else
                    {
                        //生成有数据的文件索引
                        allIndices.Add(new TileIndex()
                        {
                            Number = i,
                            Offset = newDataStream.Position
                        });

                        //写入数据的大小和数据本身
                        newDataStream.Write(BitConverter.GetBytes(dataBytes.Length), 0, 4);
                        newDataStream.Write(dataBytes, 0, dataBytes.Length);
                        if (Config.MaxTileSize < dataBytes.Length)
                        {
                            Config.MaxTileSize = dataBytes.Length;
                        }
                    }
                }
                WriteHeaderBytes(newDataStream);
            }
            //同时生成索引文件
            EsriBundleIndexFile indexFile = new EsriBundleIndexFile(allIndices);
            indexFile.Intiliaze();
            string newIndexPath = Path.ChangeExtension(newDataPath, EsriBundleFileConfig.BundleIndexExt);
            indexFile.SaveAs(newIndexPath);
            indexFile.Dispose();
            indexFile = null;
        }