正在显示
14 个修改的文件
包含
406 行增加
和
62 行删除
| ... | ... | @@ -37,8 +37,13 @@ SET (DMAP_SERVER_SRCS |
| 37 | 37 | dmpserverregistry.cpp |
| 38 | 38 | python/dmppythonutils.cpp |
| 39 | 39 | python/dmpserverwrapper.cpp |
| 40 | +<<<<<<< Updated upstream | |
| 41 | +======= | |
| 42 | + #dmppgsqlutils.cpp | |
| 43 | +>>>>>>> Stashed changes | |
| 40 | 44 | dmphttpbase.cpp |
| 41 | 45 | dmphttputils.cpp |
| 46 | + dmptilethumbnail.cpp | |
| 42 | 47 | ) |
| 43 | 48 | |
| 44 | 49 | SET (DMAP_SERVER_HDRS |
| ... | ... | @@ -70,6 +75,7 @@ SET (DMAP_SERVER_HDRS |
| 70 | 75 | python/dmppythonutils.h |
| 71 | 76 | dmphttpbase.h |
| 72 | 77 | dmphttputils.h |
| 78 | + dmptilethumbnail.h | |
| 73 | 79 | ) |
| 74 | 80 | |
| 75 | 81 | ############################################################# | ... | ... |
| ... | ... | @@ -54,25 +54,25 @@ if (temp_data.find(http_) == 0) { |
| 54 | 54 | int DmpHttp::DmpHttpBase::buildPostRequest(const std::string& server, const std::string& path, |
| 55 | 55 | std::ostream& out_request) { |
| 56 | 56 | // 分割path中的json数据 |
| 57 | - std::string temp_path(path), temp_json; | |
| 58 | - int json_pos_begin = temp_path.find(HTTP_JSON_BEGIN) + 1; | |
| 59 | - int json_pos_end = temp_path.find(HTTP_JSON_END); | |
| 60 | - if (json_pos_begin != std::string::npos) { | |
| 61 | - // 计算json的长度 | |
| 62 | - int temp_json_lenth = std::string::npos; | |
| 63 | - if (json_pos_end != temp_json_lenth) { | |
| 64 | - temp_json_lenth = (json_pos_end - json_pos_begin); | |
| 65 | - } | |
| 66 | - temp_json = temp_path.substr(json_pos_begin, temp_json_lenth); | |
| 67 | - temp_path = temp_path.substr(0, (json_pos_begin - 1)); | |
| 68 | - } | |
| 69 | - out_request << "POST " << temp_path.c_str() << " HTTP/1.0\r\n"; | |
| 70 | - out_request << "Host: " << server.c_str() << "\r\n"; | |
| 71 | - out_request << "Content-Length: " << temp_json.length() << "\r\n"; | |
| 72 | - out_request << "Content-Type: application/x-www-form-urlencoded\r\n"; | |
| 73 | - out_request << "Accept: */*\r\n"; | |
| 74 | - out_request << "Connection: close\r\n\r\n"; | |
| 75 | - out_request << temp_json.c_str(); | |
| 57 | + // std::string temp_path(path), temp_json; | |
| 58 | + // int json_pos_begin = temp_path.find(HTTP_JSON_BEGIN) + 1; | |
| 59 | + // int json_pos_end = temp_path.find(HTTP_JSON_END); | |
| 60 | + // if (json_pos_begin != std::string::npos) { | |
| 61 | + // // 计算json的长度 | |
| 62 | + // int temp_json_lenth = std::string::npos; | |
| 63 | + // if (json_pos_end != temp_json_lenth) { | |
| 64 | + // temp_json_lenth = (json_pos_end - json_pos_begin); | |
| 65 | + // } | |
| 66 | + // temp_json = temp_path.substr(json_pos_begin, temp_json_lenth); | |
| 67 | + // temp_path = temp_path.substr(0, (json_pos_begin - 1)); | |
| 68 | + // } | |
| 69 | + // out_request << "POST " << temp_path.c_str() << " HTTP/1.0\r\n"; | |
| 70 | + // out_request << "Host: " << server.c_str() << "\r\n"; | |
| 71 | + // out_request << "Content-Length: " << temp_json.length() << "\r\n"; | |
| 72 | + // out_request << "Content-Type: application/x-www-form-urlencoded\r\n"; | |
| 73 | + // out_request << "Accept: */*\r\n"; | |
| 74 | + // out_request << "Connection: close\r\n\r\n"; | |
| 75 | + // out_request << temp_json.c_str(); | |
| 76 | 76 | return HTTP_SUCCESS; |
| 77 | 77 | } |
| 78 | 78 | ... | ... |
| ... | ... | @@ -15,15 +15,15 @@ DmpHttp::DmpHttpUtils::~DmpHttpUtils() {} |
| 15 | 15 | |
| 16 | 16 | int DmpHttp::DmpHttpUtils::post(const std::string& url) |
| 17 | 17 | { |
| 18 | - handle_request_resolve(url, DmpHttpBase::buildPostRequest); | |
| 18 | + handleRequestResolve(url, DmpHttpBase::buildPostRequest); | |
| 19 | 19 | return HTTP_SUCCESS; |
| 20 | 20 | } |
| 21 | 21 | int DmpHttp::DmpHttpUtils::get(const std::string& url) |
| 22 | 22 | { |
| 23 | - handle_request_resolve(url, DmpHttpBase::buildGetRequest); | |
| 23 | + handleRequestResolve(url, DmpHttpBase::buildGetRequest); | |
| 24 | 24 | return HTTP_SUCCESS; |
| 25 | 25 | } |
| 26 | -void DmpHttp::DmpHttpUtils::handle_request_resolve(const std::string& url, pBuildRequest func) { | |
| 26 | +void DmpHttp::DmpHttpUtils::handleRequestResolve(const std::string& url, pBuildRequest func) { | |
| 27 | 27 | try { |
| 28 | 28 | responseData_.clear(); |
| 29 | 29 | // 解析URL |
| ... | ... | @@ -37,7 +37,7 @@ void DmpHttp::DmpHttpUtils::handle_request_resolve(const std::string& url, pBuil |
| 37 | 37 | // 解析服务地址\端口 |
| 38 | 38 | boost::asio::ip::tcp::resolver::query query(server, port); |
| 39 | 39 | resolver_.async_resolve(query, |
| 40 | - boost::bind(&DmpHttpUtils::handle_resolve, this, | |
| 40 | + boost::bind(&DmpHttpUtils::handleResolve, this, | |
| 41 | 41 | boost::asio::placeholders::error, |
| 42 | 42 | boost::asio::placeholders::iterator)); |
| 43 | 43 | } |
| ... | ... | @@ -47,7 +47,7 @@ void DmpHttp::DmpHttpUtils::handle_request_resolve(const std::string& url, pBuil |
| 47 | 47 | } |
| 48 | 48 | return; |
| 49 | 49 | } |
| 50 | -void DmpHttp::DmpHttpUtils::handle_resolve(const boost::system::error_code& err, | |
| 50 | +void DmpHttp::DmpHttpUtils::handleResolve(const boost::system::error_code& err, | |
| 51 | 51 | boost::asio::ip::tcp::resolver::iterator endpoint_iterator) { |
| 52 | 52 | if (err) { |
| 53 | 53 | std::cout << "Error: " << err << "\n"; |
| ... | ... | @@ -55,30 +55,30 @@ void DmpHttp::DmpHttpUtils::handle_resolve(const boost::system::error_code& err, |
| 55 | 55 | } |
| 56 | 56 | // 尝试连接 |
| 57 | 57 | boost::asio::async_connect(socket_, endpoint_iterator, |
| 58 | - boost::bind(&DmpHttpUtils::handle_connect, this, | |
| 58 | + boost::bind(&DmpHttpUtils::handleConnect, this, | |
| 59 | 59 | boost::asio::placeholders::error)); |
| 60 | 60 | } |
| 61 | -void DmpHttp::DmpHttpUtils::handle_connect(const boost::system::error_code& err) { | |
| 61 | +void DmpHttp::DmpHttpUtils::handleConnect(const boost::system::error_code& err) { | |
| 62 | 62 | if (err) { |
| 63 | 63 | std::cout << "Error: " << err << "\n"; |
| 64 | 64 | return; |
| 65 | 65 | } |
| 66 | 66 | // 发送request请求 |
| 67 | 67 | boost::asio::async_write(socket_, request_, |
| 68 | - boost::bind(&DmpHttpUtils::handle_write_request, this, | |
| 68 | + boost::bind(&DmpHttpUtils::handleWriteRequest, this, | |
| 69 | 69 | boost::asio::placeholders::error)); |
| 70 | 70 | } |
| 71 | -void DmpHttp::DmpHttpUtils::handle_write_request(const boost::system::error_code& err) { | |
| 71 | +void DmpHttp::DmpHttpUtils::handleWriteRequest(const boost::system::error_code& err) { | |
| 72 | 72 | if (err) { |
| 73 | 73 | std::cout << "Error: " << err << "\n"; |
| 74 | 74 | return; |
| 75 | 75 | } |
| 76 | 76 | // 异步持续读数据到response_,直到接收协议符号 \r\n 为止 |
| 77 | 77 | boost::asio::async_read_until(socket_, response_, "\r\n", |
| 78 | - boost::bind(&DmpHttpUtils::handle_read_status_line, this, | |
| 78 | + boost::bind(&DmpHttpUtils::handleReadStatusLine, this, | |
| 79 | 79 | boost::asio::placeholders::error)); |
| 80 | 80 | } |
| 81 | -void DmpHttp::DmpHttpUtils::handle_read_status_line(const boost::system::error_code& err) { | |
| 81 | +void DmpHttp::DmpHttpUtils::handleReadStatusLine(const boost::system::error_code& err) { | |
| 82 | 82 | if (err) { |
| 83 | 83 | std::cout << "Error: " << err << "\n"; |
| 84 | 84 | return; |
| ... | ... | @@ -102,11 +102,11 @@ void DmpHttp::DmpHttpUtils::handle_read_status_line(const boost::system::error_c |
| 102 | 102 | } |
| 103 | 103 | // 读取响应头,直到接收协议符号 \r\n\r\n 为止 |
| 104 | 104 | boost::asio::async_read_until(socket_, response_, "\r\n\r\n", |
| 105 | - boost::bind(&DmpHttpUtils::handle_read_headers, this, | |
| 105 | + boost::bind(&DmpHttpUtils::handleReadHeaders, this, | |
| 106 | 106 | boost::asio::placeholders::error)); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | -void DmpHttp::DmpHttpUtils::handle_read_headers(const boost::system::error_code& err) { | |
| 109 | +void DmpHttp::DmpHttpUtils::handleReadHeaders(const boost::system::error_code& err) { | |
| 110 | 110 | if (err) { |
| 111 | 111 | std::cout << "Error: " << err << "\n"; |
| 112 | 112 | return; |
| ... | ... | @@ -135,10 +135,10 @@ void DmpHttp::DmpHttpUtils::handle_read_headers(const boost::system::error_code& |
| 135 | 135 | // 开始读取剩余所有内容 |
| 136 | 136 | boost::asio::async_read(socket_, response_, |
| 137 | 137 | boost::asio::transfer_at_least(1), |
| 138 | - boost::bind(&DmpHttpUtils::handle_read_content, this, | |
| 138 | + boost::bind(&DmpHttpUtils::handleReadContent, this, | |
| 139 | 139 | boost::asio::placeholders::error)); |
| 140 | 140 | } |
| 141 | -void DmpHttp::DmpHttpUtils::handle_read_content(const boost::system::error_code& err) { | |
| 141 | +void DmpHttp::DmpHttpUtils::handleReadContent(const boost::system::error_code& err) { | |
| 142 | 142 | if (!err) { |
| 143 | 143 | |
| 144 | 144 | // 输出读到的数据 |
| ... | ... | @@ -152,7 +152,7 @@ void DmpHttp::DmpHttpUtils::handle_read_content(const boost::system::error_code& |
| 152 | 152 | // 继续读取剩余内容,直到读到EOF |
| 153 | 153 | boost::asio::async_read(socket_, response_, |
| 154 | 154 | boost::asio::transfer_at_least(1), |
| 155 | - boost::bind(&DmpHttpUtils::handle_read_content, this, | |
| 155 | + boost::bind(&DmpHttpUtils::handleReadContent, this, | |
| 156 | 156 | boost::asio::placeholders::error)); |
| 157 | 157 | |
| 158 | 158 | } | ... | ... |
| ... | ... | @@ -25,20 +25,20 @@ namespace DmpHttp |
| 25 | 25 | virtual std::string getResponse(void) {return responseData_;} |
| 26 | 26 | private: |
| 27 | 27 | // 建立请求 |
| 28 | - void handle_request_resolve(const std::string& url, pBuildRequest func); | |
| 28 | + void handleRequestResolve(const std::string& url, pBuildRequest func); | |
| 29 | 29 | // 解析后 |
| 30 | - void handle_resolve(const boost::system::error_code& err, | |
| 30 | + void handleResolve(const boost::system::error_code& err, | |
| 31 | 31 | boost::asio::ip::tcp::resolver::iterator endpoint_iterator); |
| 32 | 32 | // 连接后 |
| 33 | - void handle_connect(const boost::system::error_code& err); | |
| 33 | + void handleConnect(const boost::system::error_code& err); | |
| 34 | 34 | // 发送请求后 |
| 35 | - void handle_write_request(const boost::system::error_code& err); | |
| 35 | + void handleWriteRequest(const boost::system::error_code& err); | |
| 36 | 36 | // 读取响应后 |
| 37 | - void handle_read_status_line(const boost::system::error_code& err); | |
| 37 | + void handleReadStatusLine(const boost::system::error_code& err); | |
| 38 | 38 | // 读取响应头后 |
| 39 | - void handle_read_headers(const boost::system::error_code& err); | |
| 39 | + void handleReadHeaders(const boost::system::error_code& err); | |
| 40 | 40 | // 读取正文数据后 |
| 41 | - void handle_read_content(const boost::system::error_code& err); | |
| 41 | + void handleReadContent(const boost::system::error_code& err); | |
| 42 | 42 | private: |
| 43 | 43 | // 解析器 |
| 44 | 44 | boost::asio::ip::tcp::resolver resolver_; | ... | ... |
| ... | ... | @@ -16,9 +16,22 @@ |
| 16 | 16 | #include <boost/property_tree/xml_parser.hpp> |
| 17 | 17 | #include <sstream> |
| 18 | 18 | #include <fstream> |
| 19 | +#include <math.h> | |
| 20 | +#include "dmptilethumbnail.h" | |
| 21 | +#include "dmptilelayer.h" | |
| 22 | + | |
| 23 | +<<<<<<< Updated upstream | |
| 24 | + | |
| 19 | 25 | #include <iostream> |
| 20 | 26 | #include "dmplogger.h" |
| 21 | 27 | |
| 28 | +#include <math.h> | |
| 29 | +#include "dmptilethumbnail.h" | |
| 30 | +#include "dmptilelayer.h" | |
| 31 | +======= | |
| 32 | +>>>>>>> Stashed changes | |
| 33 | + | |
| 34 | + | |
| 22 | 35 | |
| 23 | 36 | DmpServerManager::DmpServerManager() |
| 24 | 37 | { |
| ... | ... | @@ -49,12 +62,13 @@ DmpServerManager::~DmpServerManager() |
| 49 | 62 | void DmpServerManager::init(const boost::filesystem::path &modulePath) |
| 50 | 63 | { |
| 51 | 64 | serverRegistry_->init(modulePath); |
| 52 | - | |
| 53 | - if(!LoadServices()) | |
| 65 | +<<<<<<< Updated upstream | |
| 66 | + if(!loadServices()) | |
| 54 | 67 | { |
| 55 | 68 | std::cout << "加载服务失败!" << std::endl; |
| 56 | 69 | LOGGER_ERROR("加载服务失败!"); |
| 57 | 70 | } |
| 71 | + //LoadDmpServices(); | |
| 58 | 72 | } |
| 59 | 73 | |
| 60 | 74 | std::string DmpServerManager::getCapabilities() |
| ... | ... | @@ -125,6 +139,13 @@ bool DmpServerManager::publish(const std::string& serverName, const std::string& |
| 125 | 139 | return false; |
| 126 | 140 | } |
| 127 | 141 | projects_[serviceName] = project; |
| 142 | + //增加缩略图处理 | |
| 143 | + if(serverName=="tileserver") | |
| 144 | + { | |
| 145 | + DmpTileLayer *tileLayer = static_cast<DmpTileLayer *>(project->getLayer()); | |
| 146 | + DmpTileThumbnail::ctreatWmtsThumbnail(tileLayer); | |
| 147 | + } | |
| 148 | + | |
| 128 | 149 | return true; |
| 129 | 150 | } |
| 130 | 151 | |
| ... | ... | @@ -149,7 +170,7 @@ bool DmpServerManager::stopService(const std::string &serverName, const std::str |
| 149 | 170 | { |
| 150 | 171 | return serverRegistry_->getServer(serverName)->stop(serviceName); |
| 151 | 172 | } |
| 152 | -bool DmpServerManager::LoadServices() | |
| 173 | +bool DmpServerManager::loadServices() | |
| 153 | 174 | { |
| 154 | 175 | boost::property_tree::ptree pt,ptList; |
| 155 | 176 | std::string conn = DmpServerConfig::Instance()->getMetaUrl(); |
| ... | ... | @@ -159,15 +180,6 @@ bool DmpServerManager::LoadServices() |
| 159 | 180 | { |
| 160 | 181 | return false; |
| 161 | 182 | } |
| 162 | - | |
| 163 | - ////测试响应内容写入文本 | |
| 164 | - // std::ofstream examplefile ("/mnt/d/example.txt"); | |
| 165 | - // if (examplefile.is_open()) { | |
| 166 | - // examplefile << DmpHttp::get(url_); | |
| 167 | - // examplefile.close(); | |
| 168 | - // } | |
| 169 | - //boost::property_tree::read_json("./example.txt", pt_); | |
| 170 | - | |
| 171 | 183 | std::stringstream ssData; |
| 172 | 184 | ssData<<strContent.c_str(); |
| 173 | 185 | boost::property_tree::read_json(ssData, pt); |
| ... | ... | @@ -182,8 +194,31 @@ bool DmpServerManager::LoadServices() |
| 182 | 194 | std::string type = e.second.get<std::string>("type"); |
| 183 | 195 | int capabilities =e.second.get<int>("capabilities"); |
| 184 | 196 | std::string project = e.second.get<std::string>("project"); |
| 185 | - this->publish(type,name,title,capabilities,project); | |
| 197 | + this->initServices(type,name,title,capabilities,project); | |
| 186 | 198 | } |
| 187 | 199 | } |
| 188 | 200 | return true; |
| 201 | +} | |
| 202 | +bool DmpServerManager::initServices(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData) | |
| 203 | +{ | |
| 204 | + //project | |
| 205 | + std::string projData; | |
| 206 | + if (!DmpServerUtils::Base64Decode(projectData, &projData)) | |
| 207 | + { | |
| 208 | + return false; | |
| 209 | + } | |
| 210 | + DmpProject *project = new DmpProject(); | |
| 211 | + if (!project->Read(projData)) | |
| 212 | + { | |
| 213 | + delete project; | |
| 214 | + return false; | |
| 215 | + } | |
| 216 | + | |
| 217 | + if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project)) | |
| 218 | + { | |
| 219 | + delete project; | |
| 220 | + return false; | |
| 221 | + } | |
| 222 | + projects_[serviceName] = project; | |
| 223 | + return true; | |
| 189 | 224 | } |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -19,6 +19,7 @@ |
| 19 | 19 | #include "dmpserverrequest.h" |
| 20 | 20 | #include "dmpserverregistry.h" |
| 21 | 21 | |
| 22 | + | |
| 22 | 23 | #define URI_RELOAD ("/API/Service/TileService/Reload") //加载已注册服务接口 |
| 23 | 24 | class SERVER_EXPORT DmpServerManager |
| 24 | 25 | { |
| ... | ... | @@ -37,7 +38,12 @@ public: |
| 37 | 38 | DmpProject* getProject(const std::string& serviceName); |
| 38 | 39 | bool removeProject(const std::string& serviceName); |
| 39 | 40 | std::string getCapabilities(); |
| 40 | - bool LoadServices(); | |
| 41 | + bool loadServices(); | |
| 42 | + //初始化加载服务 | |
| 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); | |
| 41 | 47 | |
| 42 | 48 | private: |
| 43 | 49 | typedef std::map<std::string, DmpProject*, ci_less> ProjectMap; |
| ... | ... | @@ -54,4 +60,5 @@ struct ServicesData |
| 54 | 60 | std::string project; |
| 55 | 61 | }; |
| 56 | 62 | |
| 63 | + | |
| 57 | 64 | #endif // __dmpservermanager_h__ | ... | ... |
src/server/dmptilethumbnail.cpp
0 → 100644
| 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
0 → 100644
| 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__ | ... | ... |
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | |
| 4 | 4 | SET (TILESERVER_SRCS |
| 5 | 5 | dmptileserver.cpp |
| 6 | + #dmptilethumbnail.cpp | |
| 6 | 7 | wmts/dmpwmts.cpp |
| 7 | 8 | wmts/dmpwmtsparameters.cpp |
| 8 | 9 | wmts/dmptileproviderfactory.cpp |
| ... | ... | @@ -19,6 +20,7 @@ SET (TILESERVER_SRCS |
| 19 | 20 | |
| 20 | 21 | SET (TILESERVER_HDRS |
| 21 | 22 | dmptileserver.h |
| 23 | + #dmptilethumbnail.h | |
| 22 | 24 | wmts/dmpwmtsparameters.h |
| 23 | 25 | wmts/dmptileprovider.h |
| 24 | 26 | wmts/dmptileproviderfactory.h | ... | ... |
| ... | ... | @@ -52,15 +52,21 @@ namespace DmpWmts |
| 52 | 52 | return; |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | - void DmpCapabiliTilesOperation::WriteCapabilities(boost::property_tree::ptree& pt,const std::string& host,const std::string& servicename,DmpServerResponse& response) | |
| 55 | + void DmpCapabiliTilesOperation::WriteCapabilities(boost::property_tree::ptree& pt,const std::string& host,const std::string& servicename,const std::string& title,DmpServerResponse& response) | |
| 56 | 56 | { |
| 57 | 57 | //构建能力文档 |
| 58 | 58 | boost::property_tree::ptree pt_root,pt_TileMatrix; |
| 59 | - CreateGetCapabilitiesDocument(host,servicename,pt_root); | |
| 59 | + //CreateGetCapabilitiesDocument(host,servicename,pt_root); | |
| 60 | + CreateGetCapabilitiesDocument(host,title,pt_root); | |
| 60 | 61 | pt_root.add("Capabilities.Contents.Layer.ows:Title",pt.get<std::string>("Layer.ows:Title")); |
| 61 | 62 | pt_root.add("Capabilities.Contents.Layer.ows:Abstract",pt.get<std::string>("Layer.ows:Abstract")); |
| 62 | 63 | pt_root.add("Capabilities.Contents.Layer.ows:Identifier",pt.get<std::string>("Layer.ows:Identifier")); |
| 63 | 64 | //pt_root_.add("Capabilities.Contents.Layer.Style.<xmlattr>.isDefault",pt_.get<std::string>("Layer.Style.<xmlattr>.isDefault")); |
| 65 | + | |
| 66 | + | |
| 67 | + pt_root.add("Capabilities.Contents.Layer.ows:BoundingBox.ows:LowerCorner",pt.get<std::string>("Layer.ows:BoundingBox.ows:LowerCorner")); | |
| 68 | + pt_root.add("Capabilities.Contents.Layer.ows:BoundingBox.ows:UpperCorner",pt.get<std::string>("Layer.ows:BoundingBox.ows:UpperCorner")); | |
| 69 | + | |
| 64 | 70 | pt_root.add("Capabilities.Contents.Layer.Style",pt.get<std::string>("Layer.Style")); |
| 65 | 71 | pt_root.add("Capabilities.Contents.Layer.Format",pt.get<std::string>("Layer.Format")); |
| 66 | 72 | pt_root.add("Capabilities.Contents.Layer.TileMatrixSetLink.TileMatrixSet",pt.get<std::string>("Layer.TileMatrixSetLink.TileMatrixSet")); | ... | ... |
| ... | ... | @@ -35,7 +35,7 @@ namespace DmpWmts |
| 35 | 35 | public: |
| 36 | 36 | DmpCapabiliTilesOperation(); |
| 37 | 37 | void WriteCapabilities(DmpServerResponse& response); |
| 38 | - void WriteCapabilities(boost::property_tree::ptree& pt ,const std::string& host ,const std::string& servicename,DmpServerResponse& response); | |
| 38 | + void WriteCapabilities(boost::property_tree::ptree& pt ,const std::string& host ,const std::string& servicename,const std::string& title,DmpServerResponse& response); | |
| 39 | 39 | void GetCapabilitiesDocument(DmpServerResponse& response); |
| 40 | 40 | void CreateGetCapabilitiesDocument(const std::string& host,const std::string& servicename,boost::property_tree::ptree& pt); |
| 41 | 41 | void GetServiceIdentificationElement(const std::string& servicename,boost::property_tree::ptree& pt); | ... | ... |
| ... | ... | @@ -67,7 +67,7 @@ namespace DmpWmts |
| 67 | 67 | const DmpServerProject *serverProject = context.serverProject(); |
| 68 | 68 | const DmpProject *project = serverProject->project(); |
| 69 | 69 | DmpTileLayer *tileLayer = static_cast<DmpTileLayer *>(project->getLayer(layerName)); |
| 70 | - | |
| 70 | + | |
| 71 | 71 | if (req.empty()) |
| 72 | 72 | { |
| 73 | 73 | context.response()->writeHtml("wmts,Operation is null"); |
| ... | ... | @@ -80,11 +80,11 @@ namespace DmpWmts |
| 80 | 80 | } |
| 81 | 81 | else if(boost::iequals(req, "GetThumbnail")) |
| 82 | 82 | { |
| 83 | - | |
| 84 | 83 | } |
| 85 | 84 | else if (boost::iequals(req, "GetCapabilities")) |
| 86 | 85 | { |
| 87 | 86 | const std::string host=context.request()->domain()+":"+context.request()->port();; |
| 87 | + const std::string title=serverProject->title(); | |
| 88 | 88 | const std::string servicename=serverProject->name(); |
| 89 | 89 | |
| 90 | 90 | boost::property_tree::ptree pt; |
| ... | ... | @@ -93,6 +93,11 @@ namespace DmpWmts |
| 93 | 93 | pt.add("Layer.ows:Identifier",""); |
| 94 | 94 | pt.add("Layer.Style",tileLayer->getStyle()); |
| 95 | 95 | pt.add("Layer.Format",tileLayer->getFormat()); |
| 96 | + DmpRectangle rectangle=tileLayer->extent(); | |
| 97 | + std::string lowerPoint=std::to_string(rectangle.xmin())+" "+std::to_string(rectangle.ymin()); | |
| 98 | + std::string upperPoint=std::to_string(rectangle.xmax())+" "+std::to_string(rectangle.ymax()); | |
| 99 | + pt.add("Layer.ows:BoundingBox.ows:LowerCorner",lowerPoint); | |
| 100 | + pt.add("Layer.ows:BoundingBox.ows:UpperCorner",upperPoint); | |
| 96 | 101 | |
| 97 | 102 | std::vector<DmpTileMatrixSet*> tileMatrixSets; |
| 98 | 103 | tileLayer->getTileMatrixSets(tileMatrixSets); |
| ... | ... | @@ -120,11 +125,12 @@ namespace DmpWmts |
| 120 | 125 | pt.add("TileMatrixSet.TileHeight",(*iter)->tileRows()); |
| 121 | 126 | pt.add("TileMatrixSet.TopLeftCorner",std::to_string((*iter)->tileOrigin()->x())+","+std::to_string((*iter)->tileOrigin()->y())); |
| 122 | 127 | pt.add("TileMatrixSet.DPI",(*iter)->dpi()); |
| 128 | + | |
| 123 | 129 | } |
| 124 | 130 | //boost::property_tree::write_json("/mnt/d/json.txt",pt); |
| 125 | 131 | |
| 126 | 132 | DmpCapabiliTilesOperation capOper; |
| 127 | - capOper.WriteCapabilities(pt,host,servicename,*context.response()); | |
| 133 | + capOper.WriteCapabilities(pt,host,servicename,title,*context.response()); | |
| 128 | 134 | |
| 129 | 135 | } |
| 130 | 136 | } | ... | ... |
请
注册
或
登录
后发表评论