arcgis 10.2 的紧凑型瓦片是bundle和bundlx组成的 v1格式
arcgis 10.3的的紧凑瓦片是bundle一个文件 v2格式
网上版本大多是c#的,写了个c++的。直接上代码
bool pie_datasource_bundle_readTile(const std::string &bundleFilePath, long long offset,
std::unique_ptr<char[]> &byteArray, int &arrayCount) {
std::ifstream in_stream;
in_stream.open(bundleFilePath, std::ios::in | std::ios::binary);
if (in_stream.is_open()) {
//切片长度 数据
char data_buffer[4]{0};
//从文件头,跳过offset字节
in_stream.seekg(offset, std::ios_base::beg);
//读取块长度
if (in_stream.read(data_buffer, sizeof(char) * 4).eof())//如果包含到结尾则返回失败
{
in_stream.close();
return false;
}
//数据块长度
int blobSize = 0;
blobSize=(int)(data_buffer[0]&0xff)
+(int)(data_buffer[1]&0xff)*256
+(int)(data_buffer[2]&0xff)*65536
+(int)(data_buffer[3]&0xff)*16777216;
if (blobSize <= 0) {
in_stream.close();
return false;
}
arrayCount = blobSize;
byteArray = std::unique_ptr<char[]>(new char[arrayCount]);
if (in_stream.read(byteArray.get(), arrayCount).eof())//如果包含到结尾则返回失败
{
in_stream.close();
return false;
}
in_stream.close();
return true;
}
return false;
}
bool pie_datasource_bundle_readTileFromBundleV1(const std::string &bundleFilePath, const std::string &bundlxFilePath, int index, std::unique_ptr<char[]> &byteArray, int &arrayCount) { //索引数据 长度 char buffer[5]{0}; std::ifstream in_stream; in_stream.open(bundlxFilePath, std::ios::in | std::ios::binary); if (in_stream.is_open()) { //从文件头,跳过bundlx的前16字节,并移动到index个块的位置,每个块长度为5字节 in_stream.seekg(16 + 5 * index, std::ios_base::beg); //读取块所在偏移量 if (in_stream.read(buffer, sizeof(char) * 5).eof())//如果包含到结尾则返回失败 { in_stream.close(); return false; } in_stream.close(); long long offset = 0; offset=(long long)(buffer[0]&0xff) +(long long)(buffer[1]&0xff)*256 +(long long)(buffer[2]&0xff)*65536 +(long long)(buffer[3]&0xff)*16777216 +(long long)(buffer[4]&0xff)*4294967296L; return pie_datasource_bundle_readTile(bundleFilePath, offset, byteArray, arrayCount); } return false; } bool pie_datasource_bundle_readTileFromBundleV2(const std::string &bundleFilePath, int index, std::unique_ptr<char[]> &byteArray, int &arrayCount) { //索引数据 长度 char buffer[4]{0}; std::ifstream in_stream; in_stream.open(bundleFilePath, std::ios::in | std::ios::binary); if (in_stream.is_open()) { //从文件头,跳过bundle的前64字节,并移动到index个块的位置,每个块长度为8字节 in_stream.seekg(64 + 8 * index, std::ios_base::beg); //读取块所在偏移量 if (in_stream.read(buffer, sizeof(char) * 4).eof())//如果包含到结尾则返回失败 { in_stream.close(); return false; } in_stream.close(); int offset = 0; offset=(int)(buffer[0]&0xff) +(int)(buffer[1]&0xff)*256 +(int)(buffer[2]&0xff)*65536 +(int)(buffer[3]&0xff)*16777216;//长度偏移量 auto lengthoffset = offset - 4; return pie_datasource_bundle_readTile(bundleFilePath, lengthoffset, byteArray, arrayCount); } return false; }
内容来源于网络如有侵权请私信删除
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!