正在显示
28 个修改的文件
包含
469 行增加
和
348 行删除
@@ -37,13 +37,9 @@ SET (DMAP_SERVER_SRCS | @@ -37,13 +37,9 @@ SET (DMAP_SERVER_SRCS | ||
37 | dmpserverregistry.cpp | 37 | dmpserverregistry.cpp |
38 | python/dmppythonutils.cpp | 38 | python/dmppythonutils.cpp |
39 | python/dmpserverwrapper.cpp | 39 | python/dmpserverwrapper.cpp |
40 | -<<<<<<< Updated upstream | ||
41 | -======= | ||
42 | - #dmppgsqlutils.cpp | ||
43 | ->>>>>>> Stashed changes | ||
44 | dmphttpbase.cpp | 40 | dmphttpbase.cpp |
45 | dmphttputils.cpp | 41 | dmphttputils.cpp |
46 | - dmptilethumbnail.cpp | 42 | + |
47 | ) | 43 | ) |
48 | 44 | ||
49 | SET (DMAP_SERVER_HDRS | 45 | SET (DMAP_SERVER_HDRS |
@@ -75,7 +71,7 @@ SET (DMAP_SERVER_HDRS | @@ -75,7 +71,7 @@ SET (DMAP_SERVER_HDRS | ||
75 | python/dmppythonutils.h | 71 | python/dmppythonutils.h |
76 | dmphttpbase.h | 72 | dmphttpbase.h |
77 | dmphttputils.h | 73 | dmphttputils.h |
78 | - dmptilethumbnail.h | 74 | + |
79 | ) | 75 | ) |
80 | 76 | ||
81 | ############################################################# | 77 | ############################################################# |
@@ -17,21 +17,10 @@ | @@ -17,21 +17,10 @@ | ||
17 | #include <sstream> | 17 | #include <sstream> |
18 | #include <fstream> | 18 | #include <fstream> |
19 | #include <math.h> | 19 | #include <math.h> |
20 | -#include "dmptilethumbnail.h" | ||
21 | #include "dmptilelayer.h" | 20 | #include "dmptilelayer.h" |
22 | - | ||
23 | -<<<<<<< Updated upstream | ||
24 | - | ||
25 | #include <iostream> | 21 | #include <iostream> |
26 | #include "dmplogger.h" | 22 | #include "dmplogger.h" |
27 | - | ||
28 | -#include <math.h> | ||
29 | -#include "dmptilethumbnail.h" | ||
30 | #include "dmptilelayer.h" | 23 | #include "dmptilelayer.h" |
31 | -======= | ||
32 | ->>>>>>> Stashed changes | ||
33 | - | ||
34 | - | ||
35 | 24 | ||
36 | DmpServerManager::DmpServerManager() | 25 | DmpServerManager::DmpServerManager() |
37 | { | 26 | { |
@@ -62,7 +51,6 @@ DmpServerManager::~DmpServerManager() | @@ -62,7 +51,6 @@ DmpServerManager::~DmpServerManager() | ||
62 | void DmpServerManager::init(const boost::filesystem::path &modulePath) | 51 | void DmpServerManager::init(const boost::filesystem::path &modulePath) |
63 | { | 52 | { |
64 | serverRegistry_->init(modulePath); | 53 | serverRegistry_->init(modulePath); |
65 | -<<<<<<< Updated upstream | ||
66 | if(!loadServices()) | 54 | if(!loadServices()) |
67 | { | 55 | { |
68 | std::cout << "加载服务失败!" << std::endl; | 56 | std::cout << "加载服务失败!" << std::endl; |
@@ -138,14 +126,7 @@ bool DmpServerManager::publish(const std::string& serverName, const std::string& | @@ -138,14 +126,7 @@ bool DmpServerManager::publish(const std::string& serverName, const std::string& | ||
138 | delete project; | 126 | delete project; |
139 | return false; | 127 | return false; |
140 | } | 128 | } |
141 | - projects_[serviceName] = project; | ||
142 | - //增加缩略图处理 | ||
143 | - if(serverName=="tileserver") | ||
144 | - { | ||
145 | - DmpTileLayer *tileLayer = static_cast<DmpTileLayer *>(project->getLayer()); | ||
146 | - DmpTileThumbnail::ctreatWmtsThumbnail(tileLayer); | ||
147 | - } | ||
148 | - | 129 | + projects_[serviceName] = project; |
149 | return true; | 130 | return true; |
150 | } | 131 | } |
151 | 132 |
@@ -41,9 +41,7 @@ public: | @@ -41,9 +41,7 @@ public: | ||
41 | bool loadServices(); | 41 | bool loadServices(); |
42 | //初始化加载服务 | 42 | //初始化加载服务 |
43 | bool initServices(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData); | 43 | bool initServices(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData); |
44 | - // bool ctreatTmsThumbnail() ; | ||
45 | - // bool ctreatWmtsThumbnail() ; | ||
46 | - // bool BufferCopy(cairo_surface_t *pClsCSFrom, cairo_surface_t *pClsCSTo,cairo_t *cr,int x,int y); | 44 | + |
47 | 45 | ||
48 | private: | 46 | private: |
49 | typedef std::map<std::string, DmpProject*, ci_less> ProjectMap; | 47 | typedef std::map<std::string, DmpProject*, ci_less> ProjectMap; |
@@ -34,7 +34,7 @@ class SERVER_EXPORT DmpService | @@ -34,7 +34,7 @@ class SERVER_EXPORT DmpService | ||
34 | virtual std::string name() const = 0; | 34 | virtual std::string name() const = 0; |
35 | virtual std::string version() const = 0; | 35 | virtual std::string version() const = 0; |
36 | virtual std::string description() const = 0; | 36 | virtual std::string description() const = 0; |
37 | - virtual bool validate() { return true; } | 37 | + virtual bool validate(std::string &filePath) { return true; } |
38 | virtual bool allowMethod(DmpServerRequest::Method) const { return true; } | 38 | virtual bool allowMethod(DmpServerRequest::Method) const { return true; } |
39 | virtual void executeRequest(const DmpServerContext &context) = 0; | 39 | virtual void executeRequest(const DmpServerContext &context) = 0; |
40 | }; | 40 | }; |
src/server/dmptilethumbnail.cpp
deleted
100644 → 0
1 | -/************************************************************************** | ||
2 | -* file: dmptilethumbnail.cpp | ||
3 | - | ||
4 | -* Author: lijiahuan | ||
5 | -* Date: 2021-12-23 15:33:50 | ||
6 | -* Email: jiahuanl@chinadci.com | ||
7 | -* copyright: 广州城市信息研究所有限公司 | ||
8 | -***************************************************************************/ | ||
9 | -#include "dmptilethumbnail.h" | ||
10 | -#include <iostream> | ||
11 | -#include <string> | ||
12 | -#include <map> | ||
13 | -#include <memory> | ||
14 | -#include <math.h> | ||
15 | - | ||
16 | - | ||
17 | -bool DmpTileThumbnail::ctreatWmtsThumbnail(DmpTileLayer *tileLayer) | ||
18 | -{ | ||
19 | - | ||
20 | - std::string path = tileLayer->getDataSource(); | ||
21 | - path="/mnt/d/Code/tiles/qgis"; | ||
22 | - std::string vendor=tileLayer->getVendor(); | ||
23 | - std::string format=tileLayer->getFormat(); | ||
24 | - | ||
25 | - DmpRectangle rectangle=tileLayer->extent(); | ||
26 | - std::string lowerPoint=std::to_string(rectangle.xmin())+" "+std::to_string(rectangle.ymin()); | ||
27 | - std::string upperPoint=std::to_string(rectangle.xmax())+" "+std::to_string(rectangle.ymax()); | ||
28 | - Point minPoin{.x=107.78981494180618,.y=18.870480519260582}; | ||
29 | - Point maxPoin{.x=120.43553603935675,.y=25.999868757737033}; | ||
30 | - | ||
31 | - int tileMatrix=6; | ||
32 | - Point origin{.x=-400,.y=400}; | ||
33 | - double resolution=0.02197265625009295*256; | ||
34 | - int minCol=floor(abs(origin.x-minPoin.x)/resolution); | ||
35 | - int minRow=floor(abs(origin.y-minPoin.y)/resolution); | ||
36 | - int maxCol=floor(abs(origin.x-maxPoin.x)/resolution); | ||
37 | - int maxRow=floor(abs(origin.y-maxPoin.y)/resolution); | ||
38 | - int width=maxCol-minCol; | ||
39 | - int heigth=minRow-maxRow; | ||
40 | - cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256*(width+1), 256*(heigth+1)); | ||
41 | - cairo_t *cr =cairo_create (surface); | ||
42 | - | ||
43 | - for( int i = 0 ; i <= width ; i++ ) | ||
44 | - { | ||
45 | - for(int j=0;j<=heigth;j++) | ||
46 | - { | ||
47 | - char* buff; | ||
48 | - int length; | ||
49 | - getTile(maxRow+j,minCol+i,tileMatrix,format,buff,length); | ||
50 | - // std::string filepath=path+"/"+std::to_string(tileMatrix)+"/"+std::to_string(minCol+i)+"/"+std::to_string(maxRow+j)+".png"; | ||
51 | - // cairo_surface_t* image = cairo_image_surface_create_from_png( filepath.c_str()); | ||
52 | - | ||
53 | - st_png_data* pPngData; | ||
54 | - pPngData->pdata=(unsigned char*)buff; | ||
55 | - pPngData->length=length; | ||
56 | - cairo_surface_t* image1 = cairo_image_surface_create_from_png_stream(cairo_read_func_mine,&pPngData); | ||
57 | - | ||
58 | - BufferCopy(image1,surface,cr,0,0); | ||
59 | - cairo_surface_write_to_png (surface, "./wmts1.png"); | ||
60 | - BufferCopy(image1,surface,cr,i*256,j*256); | ||
61 | - } | ||
62 | - } | ||
63 | - | ||
64 | - cairo_destroy (cr); | ||
65 | - cairo_surface_write_to_png (surface, "./wmts.png"); | ||
66 | - cairo_surface_destroy (surface); | ||
67 | - return true; | ||
68 | -} | ||
69 | -bool DmpTileThumbnail::ctreatTmsThumbnail() | ||
70 | -{ | ||
71 | - std::string path="/mnt/d/Code/tiles/qgis"; | ||
72 | - std::string vendor="QGIS"; | ||
73 | - Point origin{.x=-400,.y=400}; | ||
74 | - Point minPoin{.x=107.78981494180618,.y=18.870480519260582}; | ||
75 | - Point maxPoin{.x=120.43553603935675,.y=25.999868757737033}; | ||
76 | - double resolution=0.02197265625009295*256; | ||
77 | - // int minCol=floor(abs(origin.x-minPoin.x)/resolution); | ||
78 | - // int minRow=floor(abs(origin.y-minPoin.y)/resolution); | ||
79 | - // int maxCol=floor(abs(origin.x-maxPoin.x)/resolution); | ||
80 | - // int maxRow=floor(abs(origin.y-maxPoin.y)/resolution); | ||
81 | - int minCol=51; | ||
82 | - int minRow=28; | ||
83 | - int maxCol=53; | ||
84 | - int maxRow=27; | ||
85 | - int width=maxCol-minCol; | ||
86 | - int heigth=minRow-maxRow; | ||
87 | - cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256*(width+1), 256*(heigth+1)); | ||
88 | - cairo_t *cr =cairo_create (surface); | ||
89 | - for( int i = 0 ; i <= width ; i++ ) | ||
90 | - { | ||
91 | - for(int j=0;j<=heigth;j++) | ||
92 | - { | ||
93 | - std::string filepath=path+"/6/"+std::to_string(minCol+i)+"/"+std::to_string(maxRow+j)+".png"; | ||
94 | - cairo_surface_t* image = cairo_image_surface_create_from_png( filepath.c_str()); | ||
95 | - | ||
96 | - BufferCopy(image,surface,cr,i*256,j*256); | ||
97 | - } | ||
98 | - } | ||
99 | - cairo_destroy (cr); | ||
100 | - cairo_surface_write_to_png (surface, "./tms.png"); | ||
101 | - cairo_surface_destroy (surface); | ||
102 | - return true; | ||
103 | -} | ||
104 | -bool DmpTileThumbnail::BufferCopy(cairo_surface_t *pClsCSFrom, cairo_surface_t *pClsCSTo, cairo_t *cr,int x,int y) | ||
105 | -{ | ||
106 | - if (pClsCSFrom == NULL||pClsCSTo == NULL) | ||
107 | - { | ||
108 | - return false; | ||
109 | - } | ||
110 | - if(cr==NULL) | ||
111 | - { | ||
112 | - cr = cairo_create (pClsCSTo); | ||
113 | - } | ||
114 | - cairo_set_source_surface(cr, pClsCSFrom, x, y); | ||
115 | - cairo_paint(cr); | ||
116 | - | ||
117 | - return true; | ||
118 | -} | ||
119 | -void DmpTileThumbnail::getTile(int row, int col, int level, std::string& format,char* refbuff,int length) | ||
120 | -{ | ||
121 | - int packSize = 128; | ||
122 | - int rGroup = (int)row/packSize; | ||
123 | - rGroup = rGroup * packSize; | ||
124 | - int cGroup = (int)col/packSize; | ||
125 | - cGroup = cGroup*packSize; | ||
126 | - std::string path="/mnt/d/Code/tiles/gdmap/_alllayers"; | ||
127 | - std::string bundleBase =GetBundlePath(level,rGroup,cGroup); | ||
128 | - std::string bundleFilePath = path+bundleBase + ".bundle"; | ||
129 | - std::string bundlxFilePath = path+bundleBase + ".bundlx"; | ||
130 | - | ||
131 | - int index = packSize * (col - cGroup) + (row - rGroup); | ||
132 | - | ||
133 | - //读取bundlx文件存储该切片的位置,计算偏移量 | ||
134 | - std::ifstream freadx(bundlxFilePath, std::ifstream::binary); | ||
135 | - if(!freadx) | ||
136 | - { | ||
137 | - | ||
138 | - return; | ||
139 | - } | ||
140 | - freadx.seekg(16+5*index, freadx.beg); | ||
141 | - char* buffer = new char[5]; | ||
142 | - freadx.read(buffer,5); | ||
143 | - freadx.close(); | ||
144 | - | ||
145 | - long offset = (long)(buffer[0]&0xff) | ||
146 | - + (long)(buffer[1]&0xff) * 256 | ||
147 | - + (long)(buffer[2]&0xff) * 65536 | ||
148 | - + (long)(buffer[3]&0xff) * 16777216 | ||
149 | - + (long)(buffer[4]&0xff) * 4294967296L; | ||
150 | - delete [] buffer; | ||
151 | - //读取bundle文件获取切片 | ||
152 | - std::ifstream fread(bundleFilePath, std::ifstream::binary); | ||
153 | - if(!fread) | ||
154 | - { | ||
155 | - | ||
156 | - return; | ||
157 | - } | ||
158 | - fread.seekg(offset, fread.beg); | ||
159 | - char* buff = new char[4]; | ||
160 | - fread.read(buff, 4); | ||
161 | - length = (long)(buff[0]&0xff) | ||
162 | - + (long)(buff[1]&0xff) * 256 | ||
163 | - + (long)(buff[2]&0xff) * 65536 | ||
164 | - + (long)(buff[3]&0xff) * 16777216; | ||
165 | - delete[] buff; | ||
166 | - char* imgBuffer = new char[length]; | ||
167 | - fread.read(imgBuffer, length); | ||
168 | - fread.close(); | ||
169 | - refbuff=imgBuffer; | ||
170 | - delete[] imgBuffer; | ||
171 | -} | ||
172 | -std::string DmpTileThumbnail::GetBundlePath(int level, int rGroup, int cGroup) | ||
173 | -{ | ||
174 | - std::string l = std::to_string(level); | ||
175 | - int len = l.length(); | ||
176 | - if (len < 2) | ||
177 | - { | ||
178 | - for (int i = 0; i < 2 - len; i++) | ||
179 | - { | ||
180 | - l = "0" + l; | ||
181 | - } | ||
182 | - } | ||
183 | - l = "L" + l; | ||
184 | - std::string r =IntToHexStr(rGroup); | ||
185 | - | ||
186 | - int rLength = r.length(); | ||
187 | - if (rLength < 4) | ||
188 | - { | ||
189 | - for (int i = 0; i < 4 - rLength; i++) | ||
190 | - { | ||
191 | - r = "0" + r; | ||
192 | - } | ||
193 | - } | ||
194 | - r = "R" + r; | ||
195 | - | ||
196 | - std::string c = IntToHexStr(cGroup); | ||
197 | - int cLength = c.length(); | ||
198 | - if (cLength < 4) | ||
199 | - { | ||
200 | - for (int i = 0; i < 4 - cLength; i++) | ||
201 | - { | ||
202 | - c = "0" + c; | ||
203 | - } | ||
204 | - } | ||
205 | - c = "C" + c; | ||
206 | - std::string rootPath; | ||
207 | - std::string bundlePath = rootPath + "/"+l+"/"+r+c; | ||
208 | - return bundlePath; | ||
209 | -} | ||
210 | -std::string DmpTileThumbnail::IntToFormatStr(const int num) | ||
211 | - { | ||
212 | - std::string str = std::to_string(num); | ||
213 | - if(num>=0 && num<10) | ||
214 | - { | ||
215 | - str = "0"+str; | ||
216 | - } | ||
217 | - return str; | ||
218 | - } | ||
219 | - | ||
220 | -std::string DmpTileThumbnail::IntToHexStr(const int num) | ||
221 | - { | ||
222 | - char* buffer = new char[8]; | ||
223 | - sprintf(buffer,"%x",num); | ||
224 | - std::string str = std::string(buffer); | ||
225 | - delete[] buffer; | ||
226 | - return str; | ||
227 | - } | ||
228 | - | ||
229 | - | ||
230 | -cairo_status_t DmpTileThumbnail::cairo_read_func_mine (void *closure, unsigned char *data, unsigned int length) | ||
231 | -{ | ||
232 | - st_png_data* pPngData = (st_png_data*)closure; | ||
233 | - memcpy(data, pPngData->pdata + pPngData->length, length); | ||
234 | - pPngData->length += length; | ||
235 | - return CAIRO_STATUS_SUCCESS; | ||
236 | -} |
src/server/dmptilethumbnail.h
deleted
100644 → 0
1 | -/************************************************************************** | ||
2 | -* file: dmptilethumbnail.h | ||
3 | - | ||
4 | -* Author: lijiahuan | ||
5 | -* Date: 2021-12-23 15:34:29 | ||
6 | -* Email: jiahuanl@chinadci.com | ||
7 | -* copyright: 广州城市信息研究所有限公司 | ||
8 | -***************************************************************************/ | ||
9 | - | ||
10 | -#ifndef __dmptilethumbnail_h__ | ||
11 | -#define __dmptilethumbnail_h__ | ||
12 | -#include <cairo/cairo.h> | ||
13 | -#include "dmptilelayer.h" | ||
14 | -// namespace tileserver | ||
15 | -// { | ||
16 | - class DmpTileThumbnail | ||
17 | - { | ||
18 | - public: | ||
19 | - | ||
20 | - static bool ctreatTmsThumbnail() ; | ||
21 | - static bool ctreatWmtsThumbnail(DmpTileLayer *tileLayer); | ||
22 | - static bool BufferCopy(cairo_surface_t *pClsCSFrom, cairo_surface_t *pClsCSTo,cairo_t *cr,int x,int y); | ||
23 | - static void getTile(int row, int col, int level, std::string& format,char* refbuff,int length); | ||
24 | - static std::string GetBundlePath(int level, int rGroup, int cGroup); | ||
25 | - static std::string IntToFormatStr(const int num); | ||
26 | - static std::string IntToHexStr(const int num); | ||
27 | - static cairo_status_t cairo_read_func_mine (void *closure, unsigned char *data, unsigned int length); | ||
28 | - const int _packetSize = 128; | ||
29 | - | ||
30 | - }; | ||
31 | - struct Point | ||
32 | - { | ||
33 | - double x; | ||
34 | - double y; | ||
35 | - }; | ||
36 | - | ||
37 | - struct st_png_data | ||
38 | - { | ||
39 | - unsigned char* pdata; | ||
40 | - unsigned int length; | ||
41 | - }; | ||
42 | -// } | ||
43 | - | ||
44 | -#endif // __dmptilethumbnail_h__ |
@@ -100,8 +100,10 @@ void DmpManagerApiHandler::regService(const DmpServerApiContext &context) const | @@ -100,8 +100,10 @@ void DmpManagerApiHandler::regService(const DmpServerApiContext &context) const | ||
100 | int flag=context.manager()->publish(serverType, name, title, capabilities, project); | 100 | int flag=context.manager()->publish(serverType, name, title, capabilities, project); |
101 | if(flag==1) { | 101 | if(flag==1) { |
102 | LOGGER_INFO("服务发布成功"); | 102 | LOGGER_INFO("服务发布成功"); |
103 | + std::string url; | ||
103 | std::string http="http://"+context.request()->domain()+":"+context.request()->port(); | 104 | std::string http="http://"+context.request()->domain()+":"+context.request()->port(); |
104 | - std::string url=http+"/DMap/Services/"+name+"/TileServer/tmsService?REQUEST=GetThumbnail"; | 105 | + |
106 | + url=http+"/DMap/Services/"+name+"/TileServer/tmsService?REQUEST=GetThumbnail"; | ||
105 | context.response()->write("{\"status\":\""+std::to_string(flag)+"\",\"url\":\""+url+"\",\"message\":\"Pulish service successful!\"}"); | 107 | context.response()->write("{\"status\":\""+std::to_string(flag)+"\",\"url\":\""+url+"\",\"message\":\"Pulish service successful!\"}"); |
106 | // std::string projData; | 108 | // std::string projData; |
107 | // DmpServerUtils::Base64Decode(project, &projData); | 109 | // DmpServerUtils::Base64Decode(project, &projData); |
@@ -232,7 +234,7 @@ void DmpManagerApiHandler::reloadServices(const DmpServerApiContext &context) co | @@ -232,7 +234,7 @@ void DmpManagerApiHandler::reloadServices(const DmpServerApiContext &context) co | ||
232 | { | 234 | { |
233 | case DmpServerRequest::Method::GET_METHOD: | 235 | case DmpServerRequest::Method::GET_METHOD: |
234 | { | 236 | { |
235 | - if(context.manager()->LoadServices()) { | 237 | + if(context.manager()->loadServices()) { |
236 | context.response()->write("{\"status\":\"true\",\"message\":\"重载服务成功\"}"); | 238 | context.response()->write("{\"status\":\"true\",\"message\":\"重载服务成功\"}"); |
237 | }else{ | 239 | }else{ |
238 | context.response()->write("{\"status\":\"false\",\"message\":\"重载服务失败\"}"); | 240 | context.response()->write("{\"status\":\"false\",\"message\":\"重载服务失败\"}"); |
@@ -3,7 +3,6 @@ | @@ -3,7 +3,6 @@ | ||
3 | 3 | ||
4 | SET (TILESERVER_SRCS | 4 | SET (TILESERVER_SRCS |
5 | dmptileserver.cpp | 5 | dmptileserver.cpp |
6 | - #dmptilethumbnail.cpp | ||
7 | wmts/dmpwmts.cpp | 6 | wmts/dmpwmts.cpp |
8 | wmts/dmpwmtsparameters.cpp | 7 | wmts/dmpwmtsparameters.cpp |
9 | wmts/dmptileproviderfactory.cpp | 8 | wmts/dmptileproviderfactory.cpp |
@@ -19,7 +18,6 @@ SET (TILESERVER_SRCS | @@ -19,7 +18,6 @@ SET (TILESERVER_SRCS | ||
19 | 18 | ||
20 | SET (TILESERVER_HDRS | 19 | SET (TILESERVER_HDRS |
21 | dmptileserver.h | 20 | dmptileserver.h |
22 | - #dmptilethumbnail.h | ||
23 | wmts/dmpwmtsparameters.h | 21 | wmts/dmpwmtsparameters.h |
24 | wmts/dmptileprovider.h | 22 | wmts/dmptileprovider.h |
25 | wmts/dmptileproviderfactory.h | 23 | wmts/dmptileproviderfactory.h |
@@ -12,7 +12,7 @@ | @@ -12,7 +12,7 @@ | ||
12 | #include "wmts/dmpwmts.h" | 12 | #include "wmts/dmpwmts.h" |
13 | #include "tms/dmptms.h" | 13 | #include "tms/dmptms.h" |
14 | #include "dmpserverresponse.h" | 14 | #include "dmpserverresponse.h" |
15 | -#include "dmptilethumbnail.h" | 15 | +#include "dmptilelayer.h" |
16 | 16 | ||
17 | namespace tileserver | 17 | namespace tileserver |
18 | { | 18 | { |
@@ -100,13 +100,16 @@ void DmpTileServer::executeRequest(DmpServerRequest &request, DmpServerResponse | @@ -100,13 +100,16 @@ void DmpTileServer::executeRequest(DmpServerRequest &request, DmpServerResponse | ||
100 | } | 100 | } |
101 | 101 | ||
102 | bool DmpTileServer::publish(const std::string &serviceName, const std::string &title, unsigned int capability, const DmpProject &project) | 102 | bool DmpTileServer::publish(const std::string &serviceName, const std::string &title, unsigned int capability, const DmpProject &project) |
103 | -{ | 103 | +{ |
104 | + //DmpTileLayer *tileLayer = static_cast<DmpTileLayer *>(project.getLayer()); | ||
105 | + //std::string filePath=tileLayer->getDataSource(); | ||
106 | + std::string filePath="/mnt/d"; | ||
104 | if(capability & DmpServiceType::WMTS) { | 107 | if(capability & DmpServiceType::WMTS) { |
105 | DmpService* wmtsservice = getService("WMTSService"); | 108 | DmpService* wmtsservice = getService("WMTSService"); |
106 | if(!wmtsservice) { | 109 | if(!wmtsservice) { |
107 | return false; | 110 | return false; |
108 | } | 111 | } |
109 | - else if(!wmtsservice->validate()) | 112 | + else if(!wmtsservice->validate(filePath)) |
110 | { | 113 | { |
111 | return false; | 114 | return false; |
112 | } | 115 | } |
@@ -116,17 +119,13 @@ bool DmpTileServer::publish(const std::string &serviceName, const std::string &t | @@ -116,17 +119,13 @@ bool DmpTileServer::publish(const std::string &serviceName, const std::string &t | ||
116 | if(!tmsservice) { | 119 | if(!tmsservice) { |
117 | return false; | 120 | return false; |
118 | } | 121 | } |
119 | - else if(!tmsservice->validate()) | 122 | + else if(!tmsservice->validate(filePath)) |
120 | { | 123 | { |
121 | return false; | 124 | return false; |
122 | } | 125 | } |
123 | } | 126 | } |
124 | DmpServerProject* serverProject = new DmpServerProject(serviceName, title, &project); | 127 | DmpServerProject* serverProject = new DmpServerProject(serviceName, title, &project); |
125 | serverProjects_[serviceName] = serverProject; | 128 | serverProjects_[serviceName] = serverProject; |
126 | - | ||
127 | - | ||
128 | - | ||
129 | - | ||
130 | return true; | 129 | return true; |
131 | } | 130 | } |
132 | 131 |
@@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
23 | #include "dmpservice.h" | 23 | #include "dmpservice.h" |
24 | #include "dmpserverutils.h" | 24 | #include "dmpserverutils.h" |
25 | #include "dmpserverproject.h" | 25 | #include "dmpserverproject.h" |
26 | -#include<cairo/cairo.h> | 26 | +#include "dmptilelayer.h" |
27 | 27 | ||
28 | namespace tileserver | 28 | namespace tileserver |
29 | { | 29 | { |
@@ -29,10 +29,21 @@ namespace DmpTms | @@ -29,10 +29,21 @@ namespace DmpTms | ||
29 | { | 29 | { |
30 | LOGGER_DEBUG("Destructing TmsService"); | 30 | LOGGER_DEBUG("Destructing TmsService"); |
31 | } | 31 | } |
32 | - | ||
33 | - void DmpTMSService::executeRequest(const DmpServerContext &context) | 32 | + bool DmpTMSService::validate(std::string &filePath) |
34 | { | 33 | { |
35 | - | 34 | + //判断切片路径 |
35 | + if(filePath.empty()) | ||
36 | + { | ||
37 | + return false; | ||
38 | + } | ||
39 | + else if (!(boost::filesystem::exists(filePath) && boost::filesystem::is_directory(filePath))) | ||
40 | + { | ||
41 | + return false; | ||
42 | + } | ||
43 | + return true; | ||
44 | + } | ||
45 | + void DmpTMSService::executeRequest(const DmpServerContext &context) | ||
46 | + { | ||
36 | if(context.request()->isRestful()) | 47 | if(context.request()->isRestful()) |
37 | { | 48 | { |
38 | std::string path=context.request()->path(); | 49 | std::string path=context.request()->path(); |
@@ -75,11 +86,24 @@ namespace DmpTms | @@ -75,11 +86,24 @@ namespace DmpTms | ||
75 | return; | 86 | return; |
76 | } | 87 | } |
77 | } | 88 | } |
78 | - else | 89 | + else |
79 | { | 90 | { |
80 | - context.response()->write("非TMS请求"); | ||
81 | - } | ||
82 | - | 91 | + std::string strQuery= context.request()->query(); |
92 | + if(!strQuery.empty()&&std::strcmp(strQuery.c_str(),"REQUEST=GetThumbnail")==0) | ||
93 | + { | ||
94 | + //生成缩略图 | ||
95 | + const DmpProject *project = context.serverProject()->project(); | ||
96 | + DmpTileLayer *tileLayer = static_cast<DmpTileLayer *>(project->getLayer()); | ||
97 | + | ||
98 | + DmpTmsTileProvider provider_=DmpTmsTileProvider(""); | ||
99 | + provider_.GetTileThumbnail(tileLayer,*context.response()); | ||
100 | + } | ||
101 | + else | ||
102 | + { | ||
103 | + context.response()->write("非TMS请求"); | ||
104 | + } | ||
105 | + } | ||
83 | } | 106 | } |
107 | + | ||
84 | 108 | ||
85 | } // namespace DmpTms | 109 | } // namespace DmpTms |
@@ -23,8 +23,10 @@ namespace DmpTms | @@ -23,8 +23,10 @@ namespace DmpTms | ||
23 | std::string name() const override { return std::string("TMSService"); } | 23 | std::string name() const override { return std::string("TMSService"); } |
24 | std::string version() const override { return std::string("1.0.0"); } | 24 | std::string version() const override { return std::string("1.0.0"); } |
25 | std::string description() const override { return std::string("TMS瓦片服务"); } | 25 | std::string description() const override { return std::string("TMS瓦片服务"); } |
26 | + bool validate(std::string &filePath) override; | ||
26 | bool allowMethod(DmpServerRequest::Method method) const override { return method == DmpServerRequest::GET_METHOD;} | 27 | bool allowMethod(DmpServerRequest::Method method) const override { return method == DmpServerRequest::GET_METHOD;} |
27 | void executeRequest(const DmpServerContext &context) override; | 28 | void executeRequest(const DmpServerContext &context) override; |
29 | + | ||
28 | }; | 30 | }; |
29 | } | 31 | } |
30 | 32 |
@@ -8,6 +8,8 @@ | @@ -8,6 +8,8 @@ | ||
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | #include "dmptmstileprovider.h" | 9 | #include "dmptmstileprovider.h" |
10 | #include "dmpserverresponse.h" | 10 | #include "dmpserverresponse.h" |
11 | +#include <math.h> | ||
12 | +#include "dmplogger.h" | ||
11 | namespace DmpTms | 13 | namespace DmpTms |
12 | { | 14 | { |
13 | DmpTmsTileProvider::DmpTmsTileProvider(const std::string& root_path) | 15 | DmpTmsTileProvider::DmpTmsTileProvider(const std::string& root_path) |
@@ -43,4 +45,104 @@ namespace DmpTms | @@ -43,4 +45,104 @@ namespace DmpTms | ||
43 | } | 45 | } |
44 | fread.close(); | 46 | fread.close(); |
45 | } | 47 | } |
48 | + void DmpTmsTileProvider::GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& respons) | ||
49 | + { | ||
50 | + int tilematrix=0; | ||
51 | + std::string tilePath=dmpTileLayer->getDataSource(); | ||
52 | + | ||
53 | + //tilePath="/mnt/d/Code/tiles/qgis"; | ||
54 | + DmpRectangle rectangle=dmpTileLayer->extent(); | ||
55 | + | ||
56 | + DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymin()); | ||
57 | + DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); | ||
58 | + tilematrix=this->screenMatrixSet(min,max); | ||
59 | + int xMinTile, yMinTile,xMaxTile,yMaxTile; | ||
60 | + this->degToNum(tilematrix,min.x(),min.y(),xMinTile,yMinTile); | ||
61 | + this->degToNum(tilematrix,max.x(),max.y(),xMaxTile,yMaxTile); | ||
62 | + int heigth=abs(yMaxTile-yMinTile); | ||
63 | + int width=abs(xMaxTile-xMinTile); | ||
64 | + | ||
65 | + cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256*(width+1), 256*(heigth+1)); | ||
66 | + cairo_t *cr =cairo_create (surface); | ||
67 | + for( int i = 0 ; i <= width ; i++ ) | ||
68 | + { | ||
69 | + for(int j=0;j<=heigth;j++) | ||
70 | + { | ||
71 | + std::string filepath=tilePath+"/"+std::to_string(tilematrix)+"/"+std::to_string(xMinTile+i)+"/"+std::to_string(yMaxTile+j)+".png"; | ||
72 | + cairo_surface_t* image = cairo_image_surface_create_from_png( filepath.c_str()); | ||
73 | + this->BufferCopy(image,surface,cr,i*256,j*256); | ||
74 | + //cairo_surface_write_to_png (surface, "./tms.png"); | ||
75 | + LOGGER_DEBUG(filepath); | ||
76 | + } | ||
77 | + } | ||
78 | + //cairo_surface_write_to_png (surface, "./tms.png"); | ||
79 | + std::string responseData; | ||
80 | + cairo_surface_write_to_png_stream(surface, cairo_write_func, &responseData); | ||
81 | + respons.removeHeader("Content-Type"); | ||
82 | + respons.setHeader("Content-Type", "image/png"); | ||
83 | + respons.write(responseData); | ||
84 | + cairo_destroy (cr); | ||
85 | + cairo_surface_destroy (surface); | ||
86 | + } | ||
87 | + //经纬度到瓦片 | ||
88 | + void DmpTmsTileProvider::degToNum(int zoom, double lon_deg, double lat_deg,int& x,int& y) | ||
89 | + { | ||
90 | + double n = pow(2.0, zoom); | ||
91 | + double xtile = n * ((lon_deg + 180) / 360); | ||
92 | + //角度转弧度 | ||
93 | + double lat_rad = lat_deg * RAD2DEG; | ||
94 | + double ytile = n * (1 - (log(tan(lat_rad) + (1 / cos(lat_rad))) / pi)) / 2; | ||
95 | + | ||
96 | + x = (int)floor(xtile); | ||
97 | + y = (int)floor(ytile); | ||
98 | + } | ||
99 | + //瓦片到经纬度 | ||
100 | + // double* DmpTmsTileProvider::numToDeg(int zoom, int xtile, int ytile) | ||
101 | + // { | ||
102 | + // double n = pow(2.0, zoom); | ||
103 | + // double lon_deg = double(xtile) / n * 360.0 - 180.0; | ||
104 | + // double lat_rad = atan(sinh(pi * (1 - 2 * ytile / n))); | ||
105 | + // double lat_deg = lat_rad * 180.0 / pi; | ||
106 | + // double lonlat[2] = {}; | ||
107 | + // lonlat[0] = lon_deg; | ||
108 | + // lonlat[1] = lat_deg; | ||
109 | + // return lonlat; | ||
110 | + // } | ||
111 | + bool DmpTmsTileProvider::BufferCopy(cairo_surface_t *pClsCSFrom, cairo_surface_t *pClsCSTo, cairo_t *cr,int x,int y) | ||
112 | + { | ||
113 | + if (pClsCSFrom == NULL||pClsCSTo == NULL) | ||
114 | + { | ||
115 | + return false; | ||
116 | + } | ||
117 | + if(cr==NULL) | ||
118 | + { | ||
119 | + cr = cairo_create (pClsCSTo); | ||
120 | + } | ||
121 | + cairo_set_source_surface(cr, pClsCSFrom, x, y); | ||
122 | + cairo_paint(cr); | ||
123 | + return true; | ||
124 | + } | ||
125 | + cairo_status_t DmpTmsTileProvider::cairo_write_func(void *pbuff, const unsigned char *data, unsigned int length) | ||
126 | + { | ||
127 | + std::string *responseData = (std::string *)pbuff; | ||
128 | + responseData->append((char *)data, length); | ||
129 | + return CAIRO_STATUS_SUCCESS; | ||
130 | + } | ||
131 | + int DmpTmsTileProvider::screenMatrixSet(DmpPoint min,DmpPoint max) | ||
132 | + { | ||
133 | + int iMatrixSet=4; | ||
134 | + for( ; iMatrixSet<=20 ; iMatrixSet++ ) | ||
135 | + { | ||
136 | + int xMinTile, yMinTile,xMaxTile,yMaxTile; | ||
137 | + this->degToNum(iMatrixSet,min.x(),min.y(),xMinTile,yMinTile); | ||
138 | + this->degToNum(iMatrixSet,max.x(),max.y(),xMaxTile,yMaxTile); | ||
139 | + int heigth=abs(yMaxTile-yMinTile); | ||
140 | + int width=abs(xMaxTile-xMinTile); | ||
141 | + if((heigth+1)*(width+1)<9 && (heigth+2)*(width+2)>10) | ||
142 | + { | ||
143 | + break; | ||
144 | + } | ||
145 | + } | ||
146 | + return iMatrixSet; | ||
147 | + } | ||
46 | } | 148 | } |
@@ -11,15 +11,25 @@ | @@ -11,15 +11,25 @@ | ||
11 | 11 | ||
12 | #include <string> | 12 | #include <string> |
13 | #include "dmpserverresponse.h" | 13 | #include "dmpserverresponse.h" |
14 | +#include "dmptilelayer.h" | ||
15 | +#include "dmpproject.h" | ||
14 | 16 | ||
15 | namespace DmpTms | 17 | namespace DmpTms |
16 | { | 18 | { |
19 | + #define RAD2DEG pi/180.0 | ||
17 | class DmpTmsTileProvider | 20 | class DmpTmsTileProvider |
18 | { | 21 | { |
19 | public: | 22 | public: |
20 | std::string ImageFormat() const; | 23 | std::string ImageFormat() const; |
21 | DmpTmsTileProvider(const std::string& root_path); | 24 | DmpTmsTileProvider(const std::string& root_path); |
22 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) ; | 25 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) ; |
26 | + void GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& respons); | ||
27 | + const double pi = 3.141592653589793238463; | ||
28 | + void degToNum(int zoom, double lon_deg, double lat_deg,int& x,int& y); | ||
29 | + //double* numToDeg(int zoom, int xtile, int ytile); | ||
30 | + bool BufferCopy(cairo_surface_t *pClsCSFrom, cairo_surface_t *pClsCSTo,cairo_t *cr,int x,int y); | ||
31 | + static cairo_status_t cairo_write_func(void *pbuff, const unsigned char *data, unsigned int length); | ||
32 | + int screenMatrixSet(DmpPoint min,DmpPoint max); | ||
23 | protected: | 33 | protected: |
24 | std::string file_rootPath; | 34 | std::string file_rootPath; |
25 | }; | 35 | }; |
@@ -15,13 +15,10 @@ | @@ -15,13 +15,10 @@ | ||
15 | #include "dmpserverresponse.h" | 15 | #include "dmpserverresponse.h" |
16 | #include "dmpcapabilitiesprovider.h" | 16 | #include "dmpcapabilitiesprovider.h" |
17 | 17 | ||
18 | - | ||
19 | - | ||
20 | using namespace std; | 18 | using namespace std; |
21 | 19 | ||
22 | namespace DmpWmts | 20 | namespace DmpWmts |
23 | -{ | ||
24 | - | 21 | +{ |
25 | class DmpCapabiliTilesOperation:public DmpCapabiliTilesProvider | 22 | class DmpCapabiliTilesOperation:public DmpCapabiliTilesProvider |
26 | { | 23 | { |
27 | private: | 24 | private: |
@@ -8,7 +8,12 @@ | @@ -8,7 +8,12 @@ | ||
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | #include "dmpwmtsutils.h" | 9 | #include "dmpwmtsutils.h" |
10 | #include "dmpesribundlev1provider.h" | 10 | #include "dmpesribundlev1provider.h" |
11 | +#include "dmptileproviderfactory.h" | ||
11 | #include <iostream> | 12 | #include <iostream> |
13 | +#include "dmptilelayer.h" | ||
14 | +#include <math.h> | ||
15 | +#include <cairo/cairo.h> | ||
16 | + | ||
12 | namespace DmpWmts | 17 | namespace DmpWmts |
13 | { | 18 | { |
14 | DmpEsriBundleV1Provider:: DmpEsriBundleV1Provider(const std::string& rootPath) | 19 | DmpEsriBundleV1Provider:: DmpEsriBundleV1Provider(const std::string& rootPath) |
@@ -79,4 +84,101 @@ namespace DmpWmts | @@ -79,4 +84,101 @@ namespace DmpWmts | ||
79 | } | 84 | } |
80 | delete[] imgBuffer; | 85 | delete[] imgBuffer; |
81 | } | 86 | } |
87 | + void DmpEsriBundleV1Provider::GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& response) | ||
88 | + { | ||
89 | + std::string tilePath=dmpTileLayer->getDataSource(); | ||
90 | + DmpRectangle rectangle=dmpTileLayer->extent(); | ||
91 | + std::string format=dmpTileLayer->getFormat(); | ||
92 | + // std::string lowerPoint=std::to_string(rectangle.xmin())+" "+std::to_string(rectangle.ymin()); | ||
93 | + // std::string upperPoint=std::to_string(rectangle.xmax())+" "+std::to_string(rectangle.ymax()); | ||
94 | + DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymin()); | ||
95 | + DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); | ||
96 | + std::vector<DmpTileMatrixSet*> tileMatrixSets; | ||
97 | + dmpTileLayer->getTileMatrixSets(tileMatrixSets); | ||
98 | + double resolution; | ||
99 | + DmpPoint origin; | ||
100 | + int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,buffLen; | ||
101 | + if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile)) | ||
102 | + { | ||
103 | + response.sendError(500, "缩略图范围错误:("); | ||
104 | + return; | ||
105 | + } | ||
106 | + std::string buff; | ||
107 | + GetTile(yMinTile,xMinTile,iLevel,buff,buffLen); | ||
108 | + response.removeHeader("Content-Type"); | ||
109 | + std::string f = (format == "jpg") ? "image/jpg" : "image/png"; | ||
110 | + response.setHeader("Content-Type", f); | ||
111 | + response.write(buff); | ||
112 | + } | ||
113 | + | ||
114 | + bool DmpEsriBundleV1Provider::GetTile(int row, int col, int level,std::string& refbuff,int& length ) | ||
115 | + { | ||
116 | + int packSize = 128; | ||
117 | + int rGroup = (int)row/packSize; | ||
118 | + rGroup = rGroup * packSize; | ||
119 | + int cGroup = (int)col/packSize; | ||
120 | + cGroup = cGroup*packSize; | ||
121 | + rootPath_="/mnt/d/Code/tiles/gdmap/_alllayers"; | ||
122 | + std::string bundleBase =GetBundlePath(level,rGroup,cGroup); | ||
123 | + std::string bundleFilePath = bundleBase + ".bundle"; | ||
124 | + std::string bundlxFilePath = bundleBase + ".bundlx"; | ||
125 | + | ||
126 | + int index = packSize * (col - cGroup) + (row - rGroup); | ||
127 | + | ||
128 | + //读取bundlx文件存储该切片的位置,计算偏移量 | ||
129 | + std::ifstream freadx(bundlxFilePath, std::ifstream::binary); | ||
130 | + if(!freadx) | ||
131 | + { | ||
132 | + return false; | ||
133 | + } | ||
134 | + freadx.seekg(16+5*index, freadx.beg); | ||
135 | + char* buffer = new char[5]; | ||
136 | + freadx.read(buffer,5); | ||
137 | + freadx.close(); | ||
138 | + | ||
139 | + long offset = (long)(buffer[0]&0xff) | ||
140 | + + (long)(buffer[1]&0xff) * 256 | ||
141 | + + (long)(buffer[2]&0xff) * 65536 | ||
142 | + + (long)(buffer[3]&0xff) * 16777216 | ||
143 | + + (long)(buffer[4]&0xff) * 4294967296L; | ||
144 | + delete [] buffer; | ||
145 | + //读取bundle文件获取切片 | ||
146 | + std::ifstream fread(bundleFilePath, std::ifstream::binary); | ||
147 | + if(!fread) | ||
148 | + { | ||
149 | + return false; | ||
150 | + } | ||
151 | + fread.seekg(offset, fread.beg); | ||
152 | + char* buff = new char[4]; | ||
153 | + fread.read(buff, 4); | ||
154 | + length = (long)(buff[0]&0xff) | ||
155 | + + (long)(buff[1]&0xff) * 256 | ||
156 | + + (long)(buff[2]&0xff) * 65536 | ||
157 | + + (long)(buff[3]&0xff) * 16777216; | ||
158 | + delete[] buff; | ||
159 | + char *imgBuffer = new char[length]; | ||
160 | + fread.read(imgBuffer, length); | ||
161 | + fread.close(); | ||
162 | + // cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256, 256); | ||
163 | + // cairo_t *cr =cairo_create (surface); | ||
164 | + // st_png_data* pPngData; | ||
165 | + // pPngData->pdata=(unsigned char*)buff; | ||
166 | + // pPngData->length=length; | ||
167 | + // cairo_surface_t *image = cairo_image_surface_create_from_png_stream (cairo_read_func,&pPngData); | ||
168 | + | ||
169 | + // TileProviderFactory::BufferCopy(image,surface,cr,0,0); | ||
170 | + // cairo_surface_write_to_png (surface, "./wmts.png"); | ||
171 | + // cairo_destroy (cr); | ||
172 | + // cairo_surface_destroy (surface); | ||
173 | + delete[] imgBuffer; | ||
174 | + return true; | ||
175 | + | ||
176 | + } | ||
177 | + // cairo_status_t cairo_read_func (void *closure, unsigned char *data, unsigned int length,DmpServerResponse& response) | ||
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 | + // } | ||
82 | } | 184 | } |
@@ -11,6 +11,9 @@ | @@ -11,6 +11,9 @@ | ||
11 | #define __dmpesribundlev1provider_h__ | 11 | #define __dmpesribundlev1provider_h__ |
12 | #include "dmptileprovider.h" | 12 | #include "dmptileprovider.h" |
13 | #include "dmpabstractesribundleprovider.h" | 13 | #include "dmpabstractesribundleprovider.h" |
14 | +#include "dmptilelayer.h" | ||
15 | +#include "dmppoint.h" | ||
16 | + | ||
14 | namespace DmpWmts | 17 | namespace DmpWmts |
15 | { | 18 | { |
16 | class DmpEsriBundleV1Provider : public DmpAbstractEsriBundleProvider | 19 | class DmpEsriBundleV1Provider : public DmpAbstractEsriBundleProvider |
@@ -18,6 +21,14 @@ namespace DmpWmts | @@ -18,6 +21,14 @@ namespace DmpWmts | ||
18 | public: | 21 | public: |
19 | DmpEsriBundleV1Provider(const std::string& rootPath); | 22 | DmpEsriBundleV1Provider(const std::string& rootPath); |
20 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) override; | 23 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) override; |
24 | + void GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& response) override; | ||
25 | + bool GetTile(const int row,const int col,const int level,std::string& refbuff,int& length); | ||
26 | + //static cairo_status_t cairo_read_func (void *closure, unsigned char *data, unsigned int length); | ||
21 | }; | 27 | }; |
28 | + // struct st_png_data | ||
29 | + // { | ||
30 | + // unsigned char* pdata; | ||
31 | + // unsigned int length; | ||
32 | + // }; | ||
22 | } | 33 | } |
23 | #endif //__dmpesribundlev1provider_h__ | 34 | #endif //__dmpesribundlev1provider_h__ |
@@ -11,6 +11,8 @@ | @@ -11,6 +11,8 @@ | ||
11 | #define __dmpesribundlev2provider_h__ | 11 | #define __dmpesribundlev2provider_h__ |
12 | #include "dmptileprovider.h" | 12 | #include "dmptileprovider.h" |
13 | #include "dmpabstractesribundleprovider.h" | 13 | #include "dmpabstractesribundleprovider.h" |
14 | +#include "dmptilelayer.h" | ||
15 | + | ||
14 | namespace DmpWmts | 16 | namespace DmpWmts |
15 | { | 17 | { |
16 | class DmpEsriBundleV2Provider : public DmpAbstractEsriBundleProvider | 18 | class DmpEsriBundleV2Provider : public DmpAbstractEsriBundleProvider |
@@ -18,6 +20,7 @@ namespace DmpWmts | @@ -18,6 +20,7 @@ namespace DmpWmts | ||
18 | public: | 20 | public: |
19 | DmpEsriBundleV2Provider(const std::string& rootPath); | 21 | DmpEsriBundleV2Provider(const std::string& rootPath); |
20 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) override; | 22 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) override; |
23 | + void GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& respons) override; | ||
21 | }; | 24 | }; |
22 | } | 25 | } |
23 | 26 |
@@ -10,6 +10,8 @@ | @@ -10,6 +10,8 @@ | ||
10 | #define __dmpesritileprovider_h__ | 10 | #define __dmpesritileprovider_h__ |
11 | #include "dmptileprovider.h" | 11 | #include "dmptileprovider.h" |
12 | #include <string> | 12 | #include <string> |
13 | +#include "dmptilelayer.h" | ||
14 | + | ||
13 | 15 | ||
14 | namespace DmpWmts | 16 | namespace DmpWmts |
15 | { | 17 | { |
@@ -18,6 +20,7 @@ namespace DmpWmts | @@ -18,6 +20,7 @@ namespace DmpWmts | ||
18 | public: | 20 | public: |
19 | DmpEsriTileProvider(const std::string& rootPath); | 21 | DmpEsriTileProvider(const std::string& rootPath); |
20 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) override; | 22 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) override; |
23 | + void GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& respons) override; | ||
21 | private: | 24 | private: |
22 | std::string IntToHex8Str(const int num); | 25 | std::string IntToHex8Str(const int num); |
23 | }; | 26 | }; |
@@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
12 | 12 | ||
13 | #include <string> | 13 | #include <string> |
14 | #include "dmpserverresponse.h" | 14 | #include "dmpserverresponse.h" |
15 | +#include "dmptilelayer.h" | ||
15 | 16 | ||
16 | namespace DmpWmts | 17 | namespace DmpWmts |
17 | { | 18 | { |
@@ -19,7 +20,8 @@ namespace DmpWmts | @@ -19,7 +20,8 @@ namespace DmpWmts | ||
19 | { | 20 | { |
20 | public: | 21 | public: |
21 | DmpTileProvider(const std::string& rootPath) { rootPath_ = rootPath ;} | 22 | DmpTileProvider(const std::string& rootPath) { rootPath_ = rootPath ;} |
22 | - virtual void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& respons) = 0; | 23 | + virtual void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& respons) = 0; |
24 | + virtual void GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& respons)=0; | ||
23 | 25 | ||
24 | protected: | 26 | protected: |
25 | std::string rootPath_; | 27 | std::string rootPath_; |
@@ -59,6 +59,7 @@ namespace DmpWmts | @@ -59,6 +59,7 @@ namespace DmpWmts | ||
59 | 59 | ||
60 | return provider; | 60 | return provider; |
61 | } | 61 | } |
62 | + | ||
62 | int TileProviderFactory::StringToVector(std::string& strVector) | 63 | int TileProviderFactory::StringToVector(std::string& strVector) |
63 | { | 64 | { |
64 | int iVector=-1; | 65 | int iVector=-1; |
@@ -80,14 +81,74 @@ namespace DmpWmts | @@ -80,14 +81,74 @@ namespace DmpWmts | ||
80 | } | 81 | } |
81 | return iVector; | 82 | return iVector; |
82 | } | 83 | } |
83 | - // CapabiliTileProviderFactory::CapabiliTileProviderFactory() | ||
84 | - // { | ||
85 | - // } | ||
86 | - // std::shared_ptr<DmpCapabiliTilesProvider> CapabiliTileProviderFactory::GetProvider() | ||
87 | - // { | ||
88 | - // std::shared_ptr<DmpCapabiliTilesProvider> provider; | ||
89 | - // provider = std::make_shared<DmpCapabiliTilesOperation>(); | ||
90 | - | ||
91 | - // return provider; | ||
92 | - // } | 84 | + int TileProviderFactory::screenTileMatrix(DmpPoint& min,DmpPoint& max,std::vector<DmpTileMatrixSet*>& tileMatrixSets,double& resolution,DmpPoint& origin) |
85 | + { | ||
86 | + int iLevel=-1; | ||
87 | + for(auto iter=tileMatrixSets.cbegin();iter!=tileMatrixSets.cend();iter++) | ||
88 | + { | ||
89 | + boost::property_tree::ptree ptLevels; | ||
90 | + DmpPoint* pOrigin=(*iter)->tileOrigin(); | ||
91 | + std::vector<TileLevel*> tileLevels=(*iter)->tileLevels(); | ||
92 | + for(auto leviter=tileLevels.cbegin();leviter!=tileLevels.cend();leviter++) | ||
93 | + { | ||
94 | + int id=(*leviter)->id; | ||
95 | + double relus = (*leviter)->resolution; | ||
96 | + relus=relus*256; | ||
97 | + origin=DmpPoint(pOrigin->y(),pOrigin->x()); | ||
98 | + int xMinTile,yMinTile,xMaxTile,yMaxTile; | ||
99 | + TileProviderFactory::PointToRowCol(min,origin,relus,xMinTile,yMinTile); | ||
100 | + TileProviderFactory::PointToRowCol(max,origin,relus,xMaxTile,yMaxTile); | ||
101 | + int heigth=abs(yMaxTile-yMinTile); | ||
102 | + int width=abs(xMaxTile-xMinTile); | ||
103 | + if((heigth+1)*(width+1)<9 && (heigth+2)*(width+2)>10) | ||
104 | + { | ||
105 | + iLevel=id; | ||
106 | + resolution=relus; | ||
107 | + break; | ||
108 | + } | ||
109 | + } | ||
110 | + } | ||
111 | + return iLevel; | ||
112 | + } | ||
113 | + //点坐标转行列号 | ||
114 | + void TileProviderFactory::PointToRowCol(DmpPoint& point,DmpPoint& origin,double resolution,int& xTile,int& yTile) | ||
115 | + { | ||
116 | + xTile=floor(abs(origin.x()-point.x())/resolution); | ||
117 | + yTile=floor(abs(origin.y()-point.y())/resolution); | ||
118 | + } | ||
119 | + bool TileProviderFactory::GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile) | ||
120 | + { | ||
121 | + std::string tilePath=dmpTileLayer->getDataSource(); | ||
122 | + DmpRectangle rectangle=dmpTileLayer->extent(); | ||
123 | + DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymin()); | ||
124 | + DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); | ||
125 | + std::vector<DmpTileMatrixSet*> tileMatrixSets; | ||
126 | + dmpTileLayer->getTileMatrixSets(tileMatrixSets); | ||
127 | + DmpPoint origin; | ||
128 | + double resolution; | ||
129 | + //筛选合适的切片层级 | ||
130 | + iLevel=TileProviderFactory::screenTileMatrix(min,max,tileMatrixSets,resolution,origin); | ||
131 | + if(iLevel==-1) | ||
132 | + { | ||
133 | + return false; | ||
134 | + } | ||
135 | + // int xMinTile,yMinTile,xMaxTile,yMaxTile; | ||
136 | + TileProviderFactory::PointToRowCol(min,origin,resolution,xMinTile,yMinTile); | ||
137 | + TileProviderFactory::PointToRowCol(max,origin,resolution,xMaxTile,yMaxTile); | ||
138 | + return true; | ||
139 | + } | ||
140 | + bool TileProviderFactory::BufferCopy(cairo_surface_t *pClsCSFrom, cairo_surface_t *pClsCSTo, cairo_t *cr,int x,int y) | ||
141 | + { | ||
142 | + if (pClsCSFrom == NULL||pClsCSTo == NULL) | ||
143 | + { | ||
144 | + return false; | ||
145 | + } | ||
146 | + if(cr==NULL) | ||
147 | + { | ||
148 | + cr = cairo_create (pClsCSTo); | ||
149 | + } | ||
150 | + cairo_set_source_surface(cr, pClsCSFrom, x, y); | ||
151 | + cairo_paint(cr); | ||
152 | + return true; | ||
153 | + } | ||
93 | } | 154 | } |
@@ -13,6 +13,11 @@ | @@ -13,6 +13,11 @@ | ||
13 | #include "dmptileprovider.h" | 13 | #include "dmptileprovider.h" |
14 | #include "dmptilelayer.h" | 14 | #include "dmptilelayer.h" |
15 | #include <memory> | 15 | #include <memory> |
16 | +#include <cairo/cairo.h> | ||
17 | +#include "dmppoint.h" | ||
18 | +#include "dmptilelayer.h" | ||
19 | +#include "dmppoint.h" | ||
20 | + | ||
16 | 21 | ||
17 | //#include "dmpcapabilitiesprovider.h" | 22 | //#include "dmpcapabilitiesprovider.h" |
18 | 23 | ||
@@ -33,8 +38,15 @@ namespace DmpWmts | @@ -33,8 +38,15 @@ namespace DmpWmts | ||
33 | public: | 38 | public: |
34 | static std::shared_ptr<DmpTileProvider> GetProvider( DmpTileLayer* dmpTileLayer); | 39 | static std::shared_ptr<DmpTileProvider> GetProvider( DmpTileLayer* dmpTileLayer); |
35 | static int StringToVector(std::string& strVector); | 40 | static int StringToVector(std::string& strVector); |
41 | + static bool BufferCopy(cairo_surface_t *pClsCSFrom, cairo_surface_t *pClsCSTo,cairo_t *cr,int x,int y); | ||
42 | + static int screenTileMatrix(DmpPoint& min,DmpPoint& max,std::vector<DmpTileMatrixSet*>& tileMatrixSets,double& resolution,DmpPoint& origin); | ||
43 | + static void PointToRowCol(DmpPoint& point,DmpPoint& origin,double resolution,int& xTile,int& yTile); | ||
44 | + static bool GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile); | ||
45 | + | ||
36 | private: | 46 | private: |
37 | TileProviderFactory(); | 47 | TileProviderFactory(); |
38 | }; | 48 | }; |
49 | + | ||
50 | + | ||
39 | } | 51 | } |
40 | #endif //__dmptileproviderfactory_h__ | 52 | #endif //__dmptileproviderfactory_h__ |
@@ -22,6 +22,7 @@ | @@ -22,6 +22,7 @@ | ||
22 | #include "dmplogger.h" | 22 | #include "dmplogger.h" |
23 | #include "dmptileproviderfactory.h" | 23 | #include "dmptileproviderfactory.h" |
24 | #include "dmpserverrequest.h" | 24 | #include "dmpserverrequest.h" |
25 | +#include "dmpwmtsservice.h" | ||
25 | #include "dmpwmts.h" | 26 | #include "dmpwmts.h" |
26 | #include "dmptilelayer.h" | 27 | #include "dmptilelayer.h" |
27 | 28 | ||
@@ -39,9 +40,9 @@ namespace DmpWmts | @@ -39,9 +40,9 @@ namespace DmpWmts | ||
39 | { | 40 | { |
40 | LOGGER_DEBUG("Destructing WmtsService"); | 41 | LOGGER_DEBUG("Destructing WmtsService"); |
41 | } | 42 | } |
42 | - bool DmpWMTSService::validate() | 43 | + bool DmpWMTSService::validate(std::string &filePath) |
43 | { | 44 | { |
44 | - return false; | 45 | + return true; |
45 | } | 46 | } |
46 | void DmpWMTSService::executeRequest(const DmpServerContext &context) | 47 | void DmpWMTSService::executeRequest(const DmpServerContext &context) |
47 | { | 48 | { |
@@ -79,6 +80,8 @@ namespace DmpWmts | @@ -79,6 +80,8 @@ namespace DmpWmts | ||
79 | } | 80 | } |
80 | else if(boost::iequals(req, "GetThumbnail")) | 81 | else if(boost::iequals(req, "GetThumbnail")) |
81 | { | 82 | { |
83 | + std::shared_ptr<DmpTileProvider> provider = TileProviderFactory::GetProvider(tileLayer); | ||
84 | + provider->GetTileThumbnail(tileLayer, *context.response()); | ||
82 | } | 85 | } |
83 | else if (boost::iequals(req, "GetCapabilities")) | 86 | else if (boost::iequals(req, "GetCapabilities")) |
84 | { | 87 | { |
@@ -24,7 +24,7 @@ namespace DmpWmts | @@ -24,7 +24,7 @@ namespace DmpWmts | ||
24 | std::string name() const override { return std::string("WMTSService"); } | 24 | std::string name() const override { return std::string("WMTSService"); } |
25 | std::string version() const override { return std::string("1.0.0"); } | 25 | std::string version() const override { return std::string("1.0.0"); } |
26 | std::string description() const override { return std::string("WMTS瓦片服务"); } | 26 | std::string description() const override { return std::string("WMTS瓦片服务"); } |
27 | - bool validate() override; | 27 | + bool validate(std::string &filePath) override; |
28 | bool allowMethod(DmpServerRequest::Method method) const override { return method == DmpServerRequest::GET_METHOD;} | 28 | bool allowMethod(DmpServerRequest::Method method) const override { return method == DmpServerRequest::GET_METHOD;} |
29 | void executeRequest(const DmpServerContext &context) override; | 29 | void executeRequest(const DmpServerContext &context) override; |
30 | 30 |
1 | +/************************************************************************** | ||
2 | +* file: dmpwmtsservice.cpp | ||
3 | + | ||
4 | +* Author: wanzhongping | ||
5 | +* Date: 2021-07-28 11:34:16 | ||
6 | +* Email: zhongpingw@chinadci.com | ||
7 | +* copyright: 广州城市信息研究所有限公司 | ||
8 | +***************************************************************************/ | ||
9 | +#include "dmpwmtsservice.h" | ||
10 | + | ||
11 | +// DmpWMTSService::DmpWMTSService() | ||
12 | +// : DmpService() | ||
13 | +// { | ||
14 | +// map_type_ = MapServerType::WMTS_SERVER; | ||
15 | +// //AddProperty("tilePath","/usr/local/dmap4/gdmap/_alllayers"); | ||
16 | +// //AddProperty("tilePath","/mnt/d/Code/tiles/gdmap/_alllayers"); | ||
17 | +// //AddProperty("tileVersion","1"); | ||
18 | +// } | ||
19 | +// DmpWMTSService::~DmpWMTSService() | ||
20 | +// { | ||
21 | +// } | ||
22 | +// bool DmpWMTSService::Read(boost::property_tree::ptree &pt_node) | ||
23 | +// { | ||
24 | +// try { | ||
25 | +// enabled_ = pt_node.get<bool>("enabled"); | ||
26 | +// capabilities_ = pt_node.get<std::string>("capabilities"); | ||
27 | + | ||
28 | +// //读取属性 | ||
29 | +// for (auto property : pt_node.get_child("properties")) | ||
30 | +// { | ||
31 | +// std::string key = property.first; | ||
32 | +// std::string val = property.second.data(); | ||
33 | +// AddProperty(key, val); | ||
34 | +// } | ||
35 | + | ||
36 | +// } | ||
37 | +// catch(std::exception ex) { | ||
38 | +// return false; | ||
39 | +// } | ||
40 | +// return true; | ||
41 | +// } | ||
42 | +// bool DmpWMTSService::Write(boost::property_tree::ptree &pt_node) | ||
43 | +// { | ||
44 | +// pt_node.put("typeName", (int)map_type_); | ||
45 | +// pt_node.put("capabilities", capabilities_); | ||
46 | +// pt_node.put("enabled", enabled_); | ||
47 | + | ||
48 | +// boost::property_tree::ptree pt_subitem; | ||
49 | +// std::map<std::string, std::string>::iterator iter = properties_.begin(); | ||
50 | +// while(iter != properties_.end()) | ||
51 | +// { | ||
52 | +// pt_subitem.put(iter->first, iter->second); | ||
53 | +// ++iter; | ||
54 | +// } | ||
55 | +// pt_node.put_child("properties", pt_subitem); | ||
56 | + | ||
57 | +// return true; | ||
58 | +// } |
1 | +/************************************************************************** | ||
2 | +* file: dmpwmtsservice.h | ||
3 | + | ||
4 | +* Author: wanzhongping | ||
5 | +* Date: 2021-07-28 11:34:06 | ||
6 | +* Email: zhongpingw@chinadci.com | ||
7 | +* copyright: 广州城市信息研究所有限公司 | ||
8 | +***************************************************************************/ | ||
9 | + | ||
10 | +#ifndef __dmpwmtsservice_h__ | ||
11 | +#define __dmpwmtsservice_h__ | ||
12 | +#include "dmpservice.h" | ||
13 | + | ||
14 | + | ||
15 | +// class DmpWMTSService : public DmpService | ||
16 | +// { | ||
17 | +// public: | ||
18 | +// DmpWMTSService(); | ||
19 | +// virtual ~DmpWMTSService(); | ||
20 | +// virtual bool Read(boost::property_tree::ptree &pt_node) override; | ||
21 | +// virtual bool Write(boost::property_tree::ptree &pt_node) override; | ||
22 | + | ||
23 | + | ||
24 | +// protected: | ||
25 | +// std::string capabilities_; | ||
26 | +// bool enabled_; | ||
27 | +// }; | ||
28 | + | ||
29 | +#endif // __dmpwmtsservice_h__ |
请
注册
或
登录
后发表评论