/// <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 CreateDataFileTest()
        {
            var oldIndexPath = @"d:\esri\R1300C6980.bundlx";
            var oldDataPath = @"d:\esri\R1300C6980.bundle";
            var newDataPath = @"d:\esri\R1300C6980new.bundle";

            EsriBundleIndexFile oldIndexFile = new EsriBundleIndexFile(oldIndexPath);
            oldIndexFile.Intiliaze();

            var allOldStorageIndices = oldIndexFile.GetAllIndices();
            EsriBundleFile oldDataFile = new EsriBundleFile(oldDataPath, allOldStorageIndices);
            oldDataFile.Intiliaze();
            EsriBundleFile newDataFile = new EsriBundleFile(oldDataFile.Config);
            newDataFile.Intiliaze();
            for (int i = 0; i < 16384; i++)
            {
                var dataBytes = oldDataFile.Read(i);

                newDataFile.Write(i, dataBytes);
            }
            newDataFile.SaveAs(newDataPath);
        }
Exemple #3
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 #4
0
        static void TestSaveAs()
        {
            var oldIndexPath = @"d:\esri\R1300C6980.bundlx";
            var oldDataPath = @"d:\esri\R1300C6980.bundle";
            var newDataPath = @"d:\esri\R1300C6980new.bundle";

            EsriBundleIndexFile oldIndexFile = new EsriBundleIndexFile(oldIndexPath);
            oldIndexFile.Intiliaze();

            var allOldStorageIndices = oldIndexFile.GetAllIndices();
            EsriBundleFile oldDataFile = new EsriBundleFile(oldDataPath, allOldStorageIndices);
            oldDataFile.Intiliaze();
            oldDataFile.SaveAs(newDataPath);
        }
Exemple #5
0
        static void ReadTest()
        {
            var oldIndexPath = @"d:\esri\R0000C0000.bundlx";
            var oldDataPath = @"d:\esri\R0000C0000.bundle";

            EsriBundleIndexFile oldIndexFile = new EsriBundleIndexFile(oldIndexPath);
            oldIndexFile.Intiliaze();

            var allOldStorageIndices = oldIndexFile.GetAllIndices();
            EsriBundleFile oldDataFile = new EsriBundleFile(oldDataPath, allOldStorageIndices);
            oldDataFile.Intiliaze();
            for (int i = 0; i < 16384; i++)
            {
                var dataBytes = oldDataFile.Read(i);
                if (dataBytes != null)
                {
                    var indexx = allOldStorageIndices[i];
                }
            }
        }
Exemple #6
0
        public void Intiliaze()
        {
            if (IsIntiliazed) return;
            if (NewFileMode)
            {
                TilesBytesDict = new Dictionary<int, byte[]>(EsriBundleFileConfig.MaxTileCount);
                AllIndices = new List<TileIndex>();
                IsIntiliazed = true;
                return;
            }

            TileDataStream = new FileStream(FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            ReadHeader(TileDataStream);
            if (AllIndices != null)
            {
                IntilizeIndicesDict();
            }
            else
            {
                var indexFilePath = Path.ChangeExtension(FilePath, EsriBundleFileConfig.BundleIndexExt);
                using (EsriBundleIndexFile indefile = new EsriBundleIndexFile(indexFilePath))
                {
                    indefile.Intiliaze();
                    AllIndices = indefile.GetAllIndices();
                }
                IntilizeIndicesDict();
            }
            IsIntiliazed = true;
        }
Exemple #7
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;
        }