提交 fa334ffb2c0093c7693eddeb1cd559371122ed66

作者 LJH 李佳桓
1 个父辈 0900d00d

add

  1 +/**************************************************************************
  2 +* file: dmpesribundlev1provider.cpp
  3 +
  4 +* Author: wanzhongping
  5 +* Date: 2021-05-31 10:55:51
  6 +* Email: zhongpingw@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include "dmpwmtsutils.h"
  10 +#include "dmpesribundlev1provider.h"
  11 +#include <iostream>
  12 +namespace DmpWmts
  13 +{
  14 + DmpEsriBundleV1Provider::DmpEsriBundleV1Provider()
  15 + {
  16 + _rootPath ="/mnt/d/Data/tile/GDMap/_alllayers";
  17 + }
  18 + void DmpEsriBundleV1Provider::WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response)
  19 + {
  20 + int packSize = _packetSize;
  21 + int rGroup = (int)row/packSize;
  22 + rGroup = rGroup * packSize;
  23 + int cGroup = (int)col/packSize;
  24 + cGroup = cGroup*packSize;
  25 +
  26 + std::string bundleBase = GetBundlePath(level,rGroup,cGroup);
  27 + std::string bundleFilePath = bundleBase + ".bundle";
  28 + std::string bundlxFilePath = bundleBase + ".bundlx";
  29 +
  30 + int index = packSize * (col - cGroup) + (row - rGroup);
  31 +
  32 + //读取bundlx文件存储该切片的位置,计算偏移量
  33 + std::ifstream freadx(bundlxFilePath, std::ifstream::binary);
  34 + if(!freadx)
  35 + {
  36 + response.SendError(500, "找不到瓦片:(");
  37 + return;
  38 + }
  39 + freadx.seekg(16+5*index, freadx.beg);
  40 + char* buffer = new char[5];
  41 + freadx.read(buffer,5);
  42 + freadx.close();
  43 + long offset = (long)(buffer[0]&0xff)
  44 + + (long)(buffer[1]&0xff) * 256
  45 + + (long)(buffer[2]&0xff) * 65536
  46 + + (long)(buffer[3]&0xff) * 16777216
  47 + + (long)(buffer[4]&0xff) * 4294967296L;
  48 + delete [] buffer;
  49 +
  50 + //读取bundle文件获取切片
  51 + std::ifstream fread(bundleFilePath, std::ifstream::binary);
  52 + if(!fread)
  53 + {
  54 + response.SendError(500, "找不到瓦片:(");
  55 + return;
  56 + }
  57 + fread.seekg(offset, fread.beg);
  58 + char* buff = new char[4];
  59 + fread.read(buff, 4);
  60 + long len = (long)(buff[0]&0xff)
  61 + + (long)(buff[1]&0xff) * 256
  62 + + (long)(buff[2]&0xff) * 65536
  63 + + (long)(buff[3]&0xff) * 16777216;
  64 + delete[] buff;
  65 + char* imgBuffer = new char[len];
  66 + fread.read(imgBuffer, len);
  67 + fread.close();
  68 + if(len > 0)
  69 + {
  70 + response.RemoveHeader("Content-Type");
  71 + std::string f = (format == "jpg") ? "image/jpg" : "image/png";
  72 + response.SetHeader("Content-Type", f);
  73 + response.WriteContent(imgBuffer, len);
  74 + }
  75 + else
  76 + {
  77 + response.SendError(500, "找不到瓦片:(");
  78 + }
  79 + delete[] imgBuffer;
  80 + }
  81 +}
注册登录 后发表评论