static void BatchTestSaveas() { var odlFolder = @"C:\arcgisserver\directories\arcgiscache\TestChinaMap\图层\_alllayers11111"; var newFolder = @"C:\arcgisserver\directories\arcgiscache\TestChinaMap\图层\_alllayersnew"; var allOldFiles = Directory.GetFiles(odlFolder, "*.bundle", SearchOption.AllDirectories); foreach (var oldFilePath in allOldFiles) { EsriBundleFile oldDataFile = new EsriBundleFile(oldFilePath); oldDataFile.Intiliaze(); string filename = Path.GetFileName(oldFilePath); string newDataSavepath = oldFilePath.Replace(odlFolder, newFolder).Replace(filename, ""); if (!Directory.Exists(newDataSavepath)) Directory.CreateDirectory(newDataSavepath); oldDataFile.SaveAs(Path.Combine(newDataSavepath, filename)); } }
/// <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; }
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); }
/// <summary> /// 写入指定行列号的瓦片数据,由于需要频繁打开文件然后复制,最好使用批量写入的方式 /// </summary> /// <param name="level"></param> /// <param name="row"></param> /// <param name="col"></param> /// <param name="tilebytes"></param> public void Write(int level, int row, int col, Byte[] tilebytes) { string bundleFilePath = GetBundleFileWithouExtention(level, row, col); // 将旧文件的数据首先读到新文件中,插入新的数据会造成整个文件数据的移动,因而这里采用全部读取出来,然后重新写入的方式 EsriBundleFile oldDataFile = new EsriBundleFile(bundleFilePath + EsriBundleFileConfig.BundleExt); oldDataFile.Intiliaze(); var newDataFile = new EsriBundleFile(oldDataFile.Config); newDataFile.Intiliaze(); for (int i = 0; i < EsriBundleFileConfig.MaxTileCount; i++) { var dataBytes = oldDataFile.Read(i); newDataFile.Write(i, dataBytes); } oldDataFile.Dispose(); oldDataFile = null; int index; EsriBundleHelper.ComputeIndex(row, col, PacketSize, out index); newDataFile.Write(index, tilebytes); newDataFile.SaveAs(bundleFilePath + EsriBundleFileConfig.BundleExt); newDataFile.Dispose(); }
/// <summary> /// 批量写入瓦片,此方法会缓存新创建的文件 /// </summary> /// <param name="tileDatalist"></param> public void Write(IEnumerable<TileData> tileDatalist) { /// 已经打开的文件字典,避免频繁打开文件 Dictionary<string, EsriBundleFile> newFileDict = new Dictionary<string, EsriBundleFile>(); foreach (var tileData in tileDatalist) { int level = tileData.Level; int row = tileData.Row; int col = tileData.Col; string bundleFilePath = GetBundleFileWithouExtention(level, row, col); // 尝试打开文件 EsriBundleFile newDataFile; // 查看是否在已经打开的文件里 if (newFileDict.ContainsKey(bundleFilePath)) { newDataFile = newFileDict[bundleFilePath]; } else { // 将旧文件的数据首先读到新文件中,插入新的数据会造成整个文件数据的移动,因而这里采用全部读取出来,然后重新写入的方式 EsriBundleFile oldDataFile = new EsriBundleFile(bundleFilePath + EsriBundleFileConfig.BundleExt); oldDataFile.Intiliaze(); newDataFile = new EsriBundleFile(oldDataFile.Config); newDataFile.Intiliaze(); for (int i = 0; i < EsriBundleFileConfig.MaxTileCount; i++) { var dataBytes = oldDataFile.Read(i); newDataFile.Write(i, dataBytes); } oldDataFile.Dispose(); oldDataFile = null; newFileDict.Add(bundleFilePath, newDataFile); } // 替换旧数据 int index; EsriBundleHelper.ComputeIndex(row, col, PacketSize, out index); newDataFile.Write(index, tileData.Data); } // 依次保存数据 foreach (var newfilePair in newFileDict) { var newfile = newfilePair.Value; newfile.SaveAs(newfilePair.Key + EsriBundleFileConfig.BundleExt); newfile.Dispose(); newfile = null; } }
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); }
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]; } } }
static void OutputDataFileTest() { var oldIndexPath = @"d:\esri\R1300C6980new.bundlx"; var oldDataPath = @"d:\esri\R1300C6980new.bundle"; //EsriBundleIndexFile oldIndexFile = new EsriBundleIndexFile(oldIndexPath); //oldIndexFile.Intiliaze(); EsriBundleFile oldDataFile = new EsriBundleFile(oldDataPath); oldDataFile.Intiliaze(); for (int i = 0; i < 16384; i++) { var dataBytes = oldDataFile.Read(i); if (dataBytes != null) File.WriteAllBytes(Path.Combine(@"d:\esri\R1300C6980new\", i + ".jpg"), dataBytes); } }