正在显示
1 个修改的文件
包含
183 行增加
和
183 行删除
| 1 | -/************************************************************************** | ||
| 2 | -* file: dmpesribundlev2provider.cpp | ||
| 3 | - | ||
| 4 | -* Author: wanzhongping | ||
| 5 | -* Date: 2021-06-02 11:29:16 | ||
| 6 | -* Email: zhongpingw@chinadci.com | ||
| 7 | -* copyright: 广州城市信息研究所有限公司 | ||
| 8 | -***************************************************************************/ | ||
| 9 | -#include "dmpesribundlev2provider.h" | ||
| 10 | -#include "dmpesribundlev1provider.h" | ||
| 11 | -#include "dmptileproviderfactory.h" | ||
| 12 | -#include "dmpwmtsutils.h" | ||
| 13 | -#include <cairo/cairo.h> | ||
| 14 | -#include "dmptilelayer.h" | ||
| 15 | - | ||
| 16 | -namespace tileserver | ||
| 17 | -{ | ||
| 18 | - DmpEsriBundleV2Provider::DmpEsriBundleV2Provider(const std::string& rootPath) | ||
| 19 | - : DmpAbstractEsriBundleProvider(rootPath) | ||
| 20 | - { | ||
| 21 | - rootPath_ ="/mnt/d/Code/tiles/SDYX_WEIP_2021_M07_FS2K/Layers/_alllayers"; | ||
| 22 | - } | ||
| 23 | - void DmpEsriBundleV2Provider::WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) | ||
| 24 | - { | ||
| 25 | - int packSize = _packetSize; | ||
| 26 | - int rGroup = (int)row/packSize; | ||
| 27 | - rGroup = rGroup * packSize; | ||
| 28 | - int cGroup = (int)col/packSize; | ||
| 29 | - cGroup = cGroup*packSize; | ||
| 30 | - | ||
| 31 | - std::string bundleBase = GetBundlePath(level,rGroup,cGroup); | ||
| 32 | - std::string bundleFilePath = bundleBase + ".bundle"; | ||
| 33 | - | ||
| 34 | - int index = packSize * (row - rGroup) + (col - cGroup); | ||
| 35 | - | ||
| 36 | - //读取bundle文件,计算偏移量 | ||
| 37 | - std::ifstream fread(bundleFilePath, std::ifstream::binary); | ||
| 38 | - if(!fread) | ||
| 39 | - { | ||
| 40 | - response.sendError(500, "找不到瓦片:("); | ||
| 41 | - } | ||
| 42 | - fread.seekg(64 + 8 * index, fread.beg); | ||
| 43 | - char* buffer = new char[4]; | ||
| 44 | - fread.read(buffer,4); | ||
| 45 | - long offset = (long)(buffer[0]&0xff) | ||
| 46 | - + (long)(buffer[1]&0xff) * 256 | ||
| 47 | - + (long)(buffer[2]&0xff) * 65536 | ||
| 48 | - + (long)(buffer[3]&0xff) * 16777216 | ||
| 49 | - -4; | ||
| 50 | - delete [] buffer; | ||
| 51 | - | ||
| 52 | - //读取bundle文件获取切片 | ||
| 53 | - fread.seekg(offset, fread.beg); | ||
| 54 | - char* buff = new char[4]; | ||
| 55 | - fread.read(buff, 4); | ||
| 56 | - long len = (long)(buff[0]&0xff) | ||
| 57 | - + (long)(buff[1]&0xff) * 256 | ||
| 58 | - + (long)(buff[2]&0xff) * 65536 | ||
| 59 | - + (long)(buff[3]&0xff) * 16777216; | ||
| 60 | - delete[] buff; | ||
| 61 | - char* imgBuffer = new char[len]; | ||
| 62 | - fread.read(imgBuffer, len); | ||
| 63 | - fread.close(); | ||
| 64 | - if(len > 0) | ||
| 65 | - { | ||
| 66 | - response.removeHeader("Content-Type"); | ||
| 67 | - std::string f = (format == "jpg") ? "image/jpg" : "image/png"; | ||
| 68 | - response.setHeader("Content-Type", f); | ||
| 69 | - response.writeContent(imgBuffer, len); | ||
| 70 | - } | ||
| 71 | - else | ||
| 72 | - { | ||
| 73 | - response.sendError(500, "找不到瓦片:("); | ||
| 74 | - } | ||
| 75 | - delete[] imgBuffer; | ||
| 76 | - } | ||
| 77 | - void DmpEsriBundleV2Provider::GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& response) | ||
| 78 | - { | ||
| 79 | - std::string tilePath=dmpTileLayer->getDataSource(); | ||
| 80 | - DmpRectangle rectangle=dmpTileLayer->extent(); | ||
| 81 | - std::string format=dmpTileLayer->getFormat(); | ||
| 82 | - // std::string lowerPoint=std::to_string(rectangle.xmin())+" "+std::to_string(rectangle.ymin()); | ||
| 83 | - // std::string upperPoint=std::to_string(rectangle.xmax())+" "+std::to_string(rectangle.ymax()); | ||
| 84 | - DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymin()); | ||
| 85 | - DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); | ||
| 86 | - std::vector<DmpTileMatrixSet*> tileMatrixSets; | ||
| 87 | - dmpTileLayer->getTileMatrixSets(tileMatrixSets); | ||
| 88 | - double resolution; | ||
| 89 | - DmpPoint origin; | ||
| 90 | - int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,buffLen; | ||
| 91 | - if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile)) | ||
| 92 | - { | ||
| 93 | - response.sendError(500, "缩略图范围错误:("); | ||
| 94 | - return; | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - int imageLen=0; | ||
| 98 | - int heigth=abs(yMaxTile-yMinTile); | ||
| 99 | - int width=abs(xMaxTile-xMinTile); | ||
| 100 | - cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256*(width+1), 256*(heigth+1)); | ||
| 101 | - cairo_t *cr =cairo_create (surface); | ||
| 102 | - for( int i = 0 ; i <= width ; i++ ) | ||
| 103 | - { | ||
| 104 | - for(int j=0;j<=heigth;j++) | ||
| 105 | - { | ||
| 106 | - std::string strBuff; | ||
| 107 | - GetTile(yMaxTile+j,xMinTile+i,iLevel,strBuff,buffLen); | ||
| 108 | - | ||
| 109 | - const char* buff=strBuff.c_str(); | ||
| 110 | - st_png_data pngData = {(unsigned char*)buff, 0}; | ||
| 111 | - cairo_surface_t *image = cairo_image_surface_create_from_png_stream(cairo_read_func,&pngData); | ||
| 112 | - TileProviderFactory::BufferCopy(image,surface,cr,i*256,j*256); | ||
| 113 | - //cairo_surface_write_to_png (surface, "./wmts.png"); | ||
| 114 | - } | ||
| 115 | - } | ||
| 116 | - std::string responseData; | ||
| 117 | - cairo_surface_write_to_png_stream(surface, TileProviderFactory::cairo_write_func, &responseData); | ||
| 118 | - | ||
| 119 | - response.removeHeader("Content-Type"); | ||
| 120 | - std::string f = (format == "jpg") ? "image/jpg" : "image/png"; | ||
| 121 | - response.setHeader("Content-Type", f); | ||
| 122 | - response.write(responseData); | ||
| 123 | - //response.writeContent(&responseData,imageLen); | ||
| 124 | - cairo_destroy (cr); | ||
| 125 | - cairo_surface_destroy (surface); | ||
| 126 | - } | ||
| 127 | - bool DmpEsriBundleV2Provider::GetTile(int row, int col, int level,std::string& refbuff,int& length ) | ||
| 128 | - { | ||
| 129 | - int packSize = _packetSize; | ||
| 130 | - int rGroup = (int)row/packSize; | ||
| 131 | - rGroup = rGroup * packSize; | ||
| 132 | - int cGroup = (int)col/packSize; | ||
| 133 | - cGroup = cGroup*packSize; | ||
| 134 | - | ||
| 135 | - std::string bundleBase = GetBundlePath(level,rGroup,cGroup); | ||
| 136 | - std::string bundleFilePath = bundleBase + ".bundle"; | ||
| 137 | - | ||
| 138 | - int index = packSize * (row - rGroup) + (col - cGroup); | ||
| 139 | - | ||
| 140 | - //读取bundle文件,计算偏移量 | ||
| 141 | - std::ifstream fread(bundleFilePath, std::ifstream::binary); | ||
| 142 | - if(!fread) | ||
| 143 | - { | ||
| 144 | - return false; | ||
| 145 | - } | ||
| 146 | - fread.seekg(64 + 8 * index, fread.beg); | ||
| 147 | - char* buffer = new char[4]; | ||
| 148 | - fread.read(buffer,4); | ||
| 149 | - long offset = (long)(buffer[0]&0xff) | ||
| 150 | - + (long)(buffer[1]&0xff) * 256 | ||
| 151 | - + (long)(buffer[2]&0xff) * 65536 | ||
| 152 | - + (long)(buffer[3]&0xff) * 16777216 | ||
| 153 | - -4; | ||
| 154 | - delete [] buffer; | ||
| 155 | - | ||
| 156 | - //读取bundle文件获取切片 | ||
| 157 | - fread.seekg(offset, fread.beg); | ||
| 158 | - char* buff = new char[4]; | ||
| 159 | - fread.read(buff, 4); | ||
| 160 | - long len = (long)(buff[0]&0xff) | ||
| 161 | - + (long)(buff[1]&0xff) * 256 | ||
| 162 | - + (long)(buff[2]&0xff) * 65536 | ||
| 163 | - + (long)(buff[3]&0xff) * 16777216; | ||
| 164 | - delete[] buff; | ||
| 165 | - | ||
| 166 | - char* imgBuffer = new char[len]; | ||
| 167 | - fread.read(imgBuffer, len); | ||
| 168 | - fread.close(); | ||
| 169 | - if(len > 0) | ||
| 170 | - { | ||
| 171 | - refbuff.append(imgBuffer,len); | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | - delete[] imgBuffer; | ||
| 175 | - return true; | ||
| 176 | - } | ||
| 177 | - cairo_status_t DmpEsriBundleV2Provider::cairo_read_func (void *closure, unsigned char *data, unsigned int length) | ||
| 178 | - { | ||
| 179 | - st_png_data* pPngData = (st_png_data*)closure; | ||
| 180 | - memcpy(data, pPngData->pdata + pPngData->length, length); | ||
| 181 | - pPngData->length += length; | ||
| 182 | - return CAIRO_STATUS_SUCCESS; | ||
| 183 | - } | 1 | +/************************************************************************** |
| 2 | +* file: dmpesribundlev2provider.cpp | ||
| 3 | + | ||
| 4 | +* Author: wanzhongping | ||
| 5 | +* Date: 2021-06-02 11:29:16 | ||
| 6 | +* Email: zhongpingw@chinadci.com | ||
| 7 | +* copyright: 广州城市信息研究所有限公司 | ||
| 8 | +***************************************************************************/ | ||
| 9 | +#include "dmpesribundlev2provider.h" | ||
| 10 | +#include "dmpesribundlev1provider.h" | ||
| 11 | +#include "dmptileproviderfactory.h" | ||
| 12 | +#include "dmpwmtsutils.h" | ||
| 13 | +#include <cairo/cairo.h> | ||
| 14 | +#include "dmptilelayer.h" | ||
| 15 | + | ||
| 16 | +namespace tileserver | ||
| 17 | +{ | ||
| 18 | + DmpEsriBundleV2Provider::DmpEsriBundleV2Provider(const std::string& rootPath) | ||
| 19 | + : DmpAbstractEsriBundleProvider(rootPath) | ||
| 20 | + { | ||
| 21 | + //rootPath_ ="/mnt/d/Code/tiles/SDYX_WEIP_2021_M07_FS2K/Layers/_alllayers"; | ||
| 22 | + } | ||
| 23 | + void DmpEsriBundleV2Provider::WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) | ||
| 24 | + { | ||
| 25 | + int packSize = _packetSize; | ||
| 26 | + int rGroup = (int)row/packSize; | ||
| 27 | + rGroup = rGroup * packSize; | ||
| 28 | + int cGroup = (int)col/packSize; | ||
| 29 | + cGroup = cGroup*packSize; | ||
| 30 | + | ||
| 31 | + std::string bundleBase = GetBundlePath(level,rGroup,cGroup); | ||
| 32 | + std::string bundleFilePath = bundleBase + ".bundle"; | ||
| 33 | + | ||
| 34 | + int index = packSize * (row - rGroup) + (col - cGroup); | ||
| 35 | + | ||
| 36 | + //读取bundle文件,计算偏移量 | ||
| 37 | + std::ifstream fread(bundleFilePath, std::ifstream::binary); | ||
| 38 | + if(!fread) | ||
| 39 | + { | ||
| 40 | + response.sendError(500, "找不到瓦片:("); | ||
| 41 | + } | ||
| 42 | + fread.seekg(64 + 8 * index, fread.beg); | ||
| 43 | + char* buffer = new char[4]; | ||
| 44 | + fread.read(buffer,4); | ||
| 45 | + long offset = (long)(buffer[0]&0xff) | ||
| 46 | + + (long)(buffer[1]&0xff) * 256 | ||
| 47 | + + (long)(buffer[2]&0xff) * 65536 | ||
| 48 | + + (long)(buffer[3]&0xff) * 16777216 | ||
| 49 | + -4; | ||
| 50 | + delete [] buffer; | ||
| 51 | + | ||
| 52 | + //读取bundle文件获取切片 | ||
| 53 | + fread.seekg(offset, fread.beg); | ||
| 54 | + char* buff = new char[4]; | ||
| 55 | + fread.read(buff, 4); | ||
| 56 | + long len = (long)(buff[0]&0xff) | ||
| 57 | + + (long)(buff[1]&0xff) * 256 | ||
| 58 | + + (long)(buff[2]&0xff) * 65536 | ||
| 59 | + + (long)(buff[3]&0xff) * 16777216; | ||
| 60 | + delete[] buff; | ||
| 61 | + char* imgBuffer = new char[len]; | ||
| 62 | + fread.read(imgBuffer, len); | ||
| 63 | + fread.close(); | ||
| 64 | + if(len > 0) | ||
| 65 | + { | ||
| 66 | + response.removeHeader("Content-Type"); | ||
| 67 | + std::string f = (format == "jpg") ? "image/jpg" : "image/png"; | ||
| 68 | + response.setHeader("Content-Type", f); | ||
| 69 | + response.writeContent(imgBuffer, len); | ||
| 70 | + } | ||
| 71 | + else | ||
| 72 | + { | ||
| 73 | + response.sendError(500, "找不到瓦片:("); | ||
| 74 | + } | ||
| 75 | + delete[] imgBuffer; | ||
| 76 | + } | ||
| 77 | + void DmpEsriBundleV2Provider::GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& response) | ||
| 78 | + { | ||
| 79 | + std::string tilePath=dmpTileLayer->getDataSource(); | ||
| 80 | + DmpRectangle rectangle=dmpTileLayer->extent(); | ||
| 81 | + std::string format=dmpTileLayer->getFormat(); | ||
| 82 | + // std::string lowerPoint=std::to_string(rectangle.xmin())+" "+std::to_string(rectangle.ymin()); | ||
| 83 | + // std::string upperPoint=std::to_string(rectangle.xmax())+" "+std::to_string(rectangle.ymax()); | ||
| 84 | + DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymin()); | ||
| 85 | + DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); | ||
| 86 | + std::vector<DmpTileMatrixSet*> tileMatrixSets; | ||
| 87 | + dmpTileLayer->getTileMatrixSets(tileMatrixSets); | ||
| 88 | + double resolution; | ||
| 89 | + DmpPoint origin; | ||
| 90 | + int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,buffLen; | ||
| 91 | + if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile)) | ||
| 92 | + { | ||
| 93 | + response.sendError(500, "缩略图范围错误:("); | ||
| 94 | + return; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + int imageLen=0; | ||
| 98 | + int heigth=abs(yMaxTile-yMinTile); | ||
| 99 | + int width=abs(xMaxTile-xMinTile); | ||
| 100 | + cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256*(width+1), 256*(heigth+1)); | ||
| 101 | + cairo_t *cr =cairo_create (surface); | ||
| 102 | + for( int i = 0 ; i <= width ; i++ ) | ||
| 103 | + { | ||
| 104 | + for(int j=0;j<=heigth;j++) | ||
| 105 | + { | ||
| 106 | + std::string strBuff; | ||
| 107 | + GetTile(yMaxTile+j,xMinTile+i,iLevel,strBuff,buffLen); | ||
| 108 | + | ||
| 109 | + const char* buff=strBuff.c_str(); | ||
| 110 | + st_png_data pngData = {(unsigned char*)buff, 0}; | ||
| 111 | + cairo_surface_t *image = cairo_image_surface_create_from_png_stream(cairo_read_func,&pngData); | ||
| 112 | + TileProviderFactory::BufferCopy(image,surface,cr,i*256,j*256); | ||
| 113 | + //cairo_surface_write_to_png (surface, "./wmts.png"); | ||
| 114 | + } | ||
| 115 | + } | ||
| 116 | + std::string responseData; | ||
| 117 | + cairo_surface_write_to_png_stream(surface, TileProviderFactory::cairo_write_func, &responseData); | ||
| 118 | + | ||
| 119 | + response.removeHeader("Content-Type"); | ||
| 120 | + std::string f = (format == "jpg") ? "image/jpg" : "image/png"; | ||
| 121 | + response.setHeader("Content-Type", f); | ||
| 122 | + response.write(responseData); | ||
| 123 | + //response.writeContent(&responseData,imageLen); | ||
| 124 | + cairo_destroy (cr); | ||
| 125 | + cairo_surface_destroy (surface); | ||
| 126 | + } | ||
| 127 | + bool DmpEsriBundleV2Provider::GetTile(int row, int col, int level,std::string& refbuff,int& length ) | ||
| 128 | + { | ||
| 129 | + int packSize = _packetSize; | ||
| 130 | + int rGroup = (int)row/packSize; | ||
| 131 | + rGroup = rGroup * packSize; | ||
| 132 | + int cGroup = (int)col/packSize; | ||
| 133 | + cGroup = cGroup*packSize; | ||
| 134 | + | ||
| 135 | + std::string bundleBase = GetBundlePath(level,rGroup,cGroup); | ||
| 136 | + std::string bundleFilePath = bundleBase + ".bundle"; | ||
| 137 | + | ||
| 138 | + int index = packSize * (row - rGroup) + (col - cGroup); | ||
| 139 | + | ||
| 140 | + //读取bundle文件,计算偏移量 | ||
| 141 | + std::ifstream fread(bundleFilePath, std::ifstream::binary); | ||
| 142 | + if(!fread) | ||
| 143 | + { | ||
| 144 | + return false; | ||
| 145 | + } | ||
| 146 | + fread.seekg(64 + 8 * index, fread.beg); | ||
| 147 | + char* buffer = new char[4]; | ||
| 148 | + fread.read(buffer,4); | ||
| 149 | + long offset = (long)(buffer[0]&0xff) | ||
| 150 | + + (long)(buffer[1]&0xff) * 256 | ||
| 151 | + + (long)(buffer[2]&0xff) * 65536 | ||
| 152 | + + (long)(buffer[3]&0xff) * 16777216 | ||
| 153 | + -4; | ||
| 154 | + delete [] buffer; | ||
| 155 | + | ||
| 156 | + //读取bundle文件获取切片 | ||
| 157 | + fread.seekg(offset, fread.beg); | ||
| 158 | + char* buff = new char[4]; | ||
| 159 | + fread.read(buff, 4); | ||
| 160 | + long len = (long)(buff[0]&0xff) | ||
| 161 | + + (long)(buff[1]&0xff) * 256 | ||
| 162 | + + (long)(buff[2]&0xff) * 65536 | ||
| 163 | + + (long)(buff[3]&0xff) * 16777216; | ||
| 164 | + delete[] buff; | ||
| 165 | + | ||
| 166 | + char* imgBuffer = new char[len]; | ||
| 167 | + fread.read(imgBuffer, len); | ||
| 168 | + fread.close(); | ||
| 169 | + if(len > 0) | ||
| 170 | + { | ||
| 171 | + refbuff.append(imgBuffer,len); | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + delete[] imgBuffer; | ||
| 175 | + return true; | ||
| 176 | + } | ||
| 177 | + cairo_status_t DmpEsriBundleV2Provider::cairo_read_func (void *closure, unsigned char *data, unsigned int length) | ||
| 178 | + { | ||
| 179 | + st_png_data* pPngData = (st_png_data*)closure; | ||
| 180 | + memcpy(data, pPngData->pdata + pPngData->length, length); | ||
| 181 | + pPngData->length += length; | ||
| 182 | + return CAIRO_STATUS_SUCCESS; | ||
| 183 | + } | ||
| 184 | } | 184 | } |
请
注册
或
登录
后发表评论