提交 3787f4fa28acb73c34127dd1e7832047990d408d
Merge branch 'master' of http://gitlab.ctune.cn/DMapServer/DMapServer4.1
正在显示
13 个修改的文件
包含
99 行增加
和
198 行删除
@@ -14,6 +14,7 @@ SET (TILESERVER_SRCS | @@ -14,6 +14,7 @@ SET (TILESERVER_SRCS | ||
14 | # dmpwmtsservice.cpp | 14 | # dmpwmtsservice.cpp |
15 | wmts/dmpwmtsutils.cpp | 15 | wmts/dmpwmtsutils.cpp |
16 | tms/dmptms.cpp | 16 | tms/dmptms.cpp |
17 | + tms/dmptmstileprovider.cpp | ||
17 | ) | 18 | ) |
18 | 19 | ||
19 | SET (TILESERVER_HDRS | 20 | SET (TILESERVER_HDRS |
@@ -30,6 +31,7 @@ SET (TILESERVER_HDRS | @@ -30,6 +31,7 @@ SET (TILESERVER_HDRS | ||
30 | # dmpwmtsservice.h | 31 | # dmpwmtsservice.h |
31 | wmts/dmpwmtsutils.h | 32 | wmts/dmpwmtsutils.h |
32 | tms/dmptms.h | 33 | tms/dmptms.h |
34 | + tms/dmptmstileprovider.h | ||
33 | ) | 35 | ) |
34 | ######################################################## | 36 | ######################################################## |
35 | # Build | 37 | # Build |
@@ -6,10 +6,16 @@ | @@ -6,10 +6,16 @@ | ||
6 | * Email: zhongpingw@chinadci.com | 6 | * Email: zhongpingw@chinadci.com |
7 | * copyright: 广州城市信息研究所有限公司 | 7 | * copyright: 广州城市信息研究所有限公司 |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | +#include <map> | ||
9 | #include "dmptms.h" | 10 | #include "dmptms.h" |
10 | #include "dmptilelayer.h" | 11 | #include "dmptilelayer.h" |
12 | +#include "dmpserverrequest.h" | ||
13 | +#include "dmpserverresponse.h" | ||
11 | #include "dmpservercontext.h" | 14 | #include "dmpservercontext.h" |
12 | #include "dmplogger.h" | 15 | #include "dmplogger.h" |
16 | +#include "dmptilelayer.h" | ||
17 | +#include "dmpproject.h" | ||
18 | +#include "dmptmstileprovider.h" | ||
13 | 19 | ||
14 | namespace DmpTms | 20 | namespace DmpTms |
15 | { | 21 | { |
@@ -26,5 +32,54 @@ namespace DmpTms | @@ -26,5 +32,54 @@ namespace DmpTms | ||
26 | 32 | ||
27 | void DmpTMSService::executeRequest(const DmpServerContext &context) | 33 | void DmpTMSService::executeRequest(const DmpServerContext &context) |
28 | { | 34 | { |
35 | + | ||
36 | + if(context.request()->isRestful()) | ||
37 | + { | ||
38 | + std::string path_=context.request()->path(); | ||
39 | + std::vector<std::string> vec_; | ||
40 | + boost::split(vec_,context.request()->path(),boost::is_any_of("/"),boost::token_compress_on); | ||
41 | + int isize_=vec_.size(); | ||
42 | + if(isize_<4) | ||
43 | + { | ||
44 | + context.response()->write("Tms,Operation is null"); | ||
45 | + return; | ||
46 | + } | ||
47 | + std::string::size_type idx0_,idx1_; | ||
48 | + idx0_=vec_[isize_-1].find("png"); | ||
49 | + idx1_=vec_[isize_-1].find("jpg"); | ||
50 | + | ||
51 | + if((idx0_!=std::string::npos)||(idx1_!=std::string::npos)) | ||
52 | + { | ||
53 | + std::vector<std::string> vec0_; | ||
54 | + boost::split(vec0_,vec_[isize_-1],boost::is_any_of("."),boost::token_compress_on); | ||
55 | + int tileCol_=atoi(vec0_[0].c_str()); | ||
56 | + int tileRow_=atoi(vec_[isize_-2].c_str()); | ||
57 | + int tileMatrix_=atoi(vec_[isize_-3].c_str()); | ||
58 | + const DmpProject *project = context.project(); | ||
59 | + DmpTileLayer *tileLayer = static_cast<DmpTileLayer *>(project->getLayer("layer")); | ||
60 | + std::string format_=vec0_[1].c_str(); | ||
61 | + std::string filePath_=tileLayer->getDataSource(); | ||
62 | + if(filePath_.empty()) | ||
63 | + { | ||
64 | + context.response()->write("Tms,Operation is null"); | ||
65 | + } | ||
66 | + else | ||
67 | + { | ||
68 | + DmpTmsTileProvider provider_=DmpTmsTileProvider(filePath_); | ||
69 | + provider_.WriteTile(tileRow_, tileCol_, tileMatrix_, format_, *context.response()); | ||
70 | + } | ||
71 | + } | ||
72 | + else | ||
73 | + { | ||
74 | + context.response()->write("Tms,Operation is null"); | ||
75 | + return; | ||
76 | + } | ||
77 | + } | ||
78 | + else | ||
79 | + { | ||
80 | + context.response()->write("非TMS请求"); | ||
81 | + } | ||
82 | + | ||
29 | } | 83 | } |
84 | + | ||
30 | } // namespace DmpTms | 85 | } // namespace DmpTms |
1 | -/************************************************************************** | ||
2 | -* file: dmpserverparameters.cpp | ||
3 | - | ||
4 | -* Author: lijiahuan | ||
5 | -* Date: 2021-12-09 17:41:00 | ||
6 | -* Email: jiahuanl@chinadci.com | ||
7 | -* copyright: 广州城市信息研究所有限公司 | ||
8 | -***************************************************************************/ | ||
9 | -#include <iostream> | ||
10 | -#include <boost/lexical_cast.hpp> | ||
11 | -#include <boost/algorithm/string.hpp> | ||
12 | -#include "dmplogger.h" | ||
13 | -#include "dmpserverutils.h" | ||
14 | -#include "dmptmsparameters.h" | ||
15 | - | ||
16 | - | ||
17 | -namespace DmpTms | ||
18 | -{ | ||
19 | - DmpTmsParameters::DmpTmsParameters(const DmpServerParameters ¶meters) | ||
20 | - { | ||
21 | - params_ = parameters.Parameters(); | ||
22 | - } | ||
23 | - DmpTmsParameters::DmpTmsParameters() : DmpServerParameters() | ||
24 | - { | ||
25 | - | ||
26 | - } | ||
27 | - int DmpTmsParameters::TileMatrix() const | ||
28 | - { | ||
29 | - std::map<std::string, std::string>::const_iterator iter; | ||
30 | - iter = params_.find("TILEMATRIX"); | ||
31 | - if (iter != params_.end()) | ||
32 | - { | ||
33 | - try | ||
34 | - { | ||
35 | - int num_tile_atrix = boost::lexical_cast<int>(iter->second); | ||
36 | - return num_tile_atrix; | ||
37 | - } | ||
38 | - catch (boost::bad_lexical_cast &e) | ||
39 | - { | ||
40 | - LOGGER_ERROR(e.what()); | ||
41 | - } | ||
42 | - } | ||
43 | - return -1; | ||
44 | - } | ||
45 | - int DmpTmsParameters::TileRow() const | ||
46 | - { | ||
47 | - std::map<std::string, std::string>::const_iterator iter; | ||
48 | - iter = params_.find("TILEROW"); | ||
49 | - if (iter != params_.end()) | ||
50 | - { | ||
51 | - try | ||
52 | - { | ||
53 | - int num_tile_row = boost::lexical_cast<int>(iter->second); | ||
54 | - return num_tile_row; | ||
55 | - } | ||
56 | - catch (boost::bad_lexical_cast &e) | ||
57 | - { | ||
58 | - LOGGER_ERROR(e.what()); | ||
59 | - } | ||
60 | - } | ||
61 | - return -1; | ||
62 | - } | ||
63 | - int DmpTmsParameters::TileCol() const | ||
64 | - { | ||
65 | - std::map<std::string, std::string>::const_iterator iter; | ||
66 | - iter = params_.find("TILECOL"); | ||
67 | - if (iter != params_.end()) | ||
68 | - { | ||
69 | - try | ||
70 | - { | ||
71 | - int num_tile_col = boost::lexical_cast<int>(iter->second); | ||
72 | - return num_tile_col; | ||
73 | - } | ||
74 | - catch (boost::bad_lexical_cast &e) | ||
75 | - { | ||
76 | - LOGGER_ERROR(e.what()); | ||
77 | - } | ||
78 | - } | ||
79 | - return -1; | ||
80 | - } | ||
81 | - | ||
82 | - std::string DmpTmsParameters::TileMatrixSet() const | ||
83 | - { | ||
84 | - std::string tile_matrix_set; | ||
85 | - std::map<std::string, std::string>::const_iterator iter; | ||
86 | - iter = params_.find("TILEMATRIXSET"); | ||
87 | - if (iter != params_.end()) | ||
88 | - { | ||
89 | - tile_matrix_set = iter->second; | ||
90 | - } | ||
91 | - return tile_matrix_set; | ||
92 | - } | ||
93 | - std::string DmpTmsParameters::Layer() const | ||
94 | - { | ||
95 | - std::string layer; | ||
96 | - std::map<std::string, std::string>::const_iterator iter; | ||
97 | - iter = params_.find("LAYER"); | ||
98 | - if (iter != params_.end()) | ||
99 | - { | ||
100 | - layer = iter->second; | ||
101 | - } | ||
102 | - return layer; | ||
103 | - } | ||
104 | - | ||
105 | - DmpTmsParameters::Format DmpTmsParameters::ImageFormat() const | ||
106 | - { | ||
107 | - std::string frm; | ||
108 | - std::map<std::string, std::string>::const_iterator iter; | ||
109 | - iter = params_.find("format"); | ||
110 | - if (iter != params_.end()) | ||
111 | - { | ||
112 | - frm = iter->second; | ||
113 | - if (frm.empty()) { | ||
114 | - return Format::NONE; | ||
115 | - } | ||
116 | - Format f = Format::PNG; | ||
117 | - boost::to_lower(frm); | ||
118 | - if (frm.compare("jpg") == 0 || frm.compare("jpeg") == 0 || frm.compare("image/jpeg") == 0 ) { | ||
119 | - f = Format::JPG; | ||
120 | - } | ||
121 | - return f; | ||
122 | - } | ||
123 | - return Format::NONE; | ||
124 | - } | ||
125 | -} |
1 | -/************************************************************************** | ||
2 | -* file: dmpserverparameters.h | ||
3 | - | ||
4 | -* Author: lijiahuan | ||
5 | -* Date: 2021-12-09 17:41:00 | ||
6 | -* Email: jiahuanl@chinadci.com | ||
7 | -* copyright: 广州城市信息研究所有限公司 | ||
8 | -***************************************************************************/ | ||
9 | -#ifndef __dmptmsparameters_h__ | ||
10 | -#define __dmptmsparameters_h__ | ||
11 | - | ||
12 | -#include "dmpserverparameters.h" | ||
13 | -namespace DmpTms | ||
14 | -{ | ||
15 | - class DmpTmsParameters : public DmpServerParameters | ||
16 | - { | ||
17 | - public: | ||
18 | - enum class Format | ||
19 | - { | ||
20 | - NONE, | ||
21 | - JPG, | ||
22 | - PNG | ||
23 | - }; | ||
24 | - DmpTmsParameters(const DmpServerParameters ¶meters); | ||
25 | - DmpTmsParameters(); | ||
26 | - virtual ~DmpTmsParameters() = default; | ||
27 | - std::string Layer() const; | ||
28 | - Format ImageFormat() const; | ||
29 | - std::string TileMatrixSet() const; | ||
30 | - int TileMatrix() const; | ||
31 | - int TileRow() const; | ||
32 | - int TileCol() const; | ||
33 | - }; | ||
34 | -} | ||
35 | -#endif //__dmptmsparameters_h__ |
@@ -19,8 +19,7 @@ namespace DmpTms | @@ -19,8 +19,7 @@ namespace DmpTms | ||
19 | std::string tile_path = file_rootPath+"/"+std::to_string(level)+"/"+std::to_string(row)+"/"+std::to_string(col)+"."+format; | 19 | std::string tile_path = file_rootPath+"/"+std::to_string(level)+"/"+std::to_string(row)+"/"+std::to_string(col)+"."+format; |
20 | std::ifstream fread(tile_path, std::ifstream::binary); | 20 | std::ifstream fread(tile_path, std::ifstream::binary); |
21 | if(!fread) | 21 | if(!fread) |
22 | - { | ||
23 | - | 22 | + { |
24 | response.sendError(500, "找不到瓦片:("); | 23 | response.sendError(500, "找不到瓦片:("); |
25 | return; | 24 | return; |
26 | } | 25 | } |
@@ -16,11 +16,13 @@ namespace DmpTms | @@ -16,11 +16,13 @@ namespace DmpTms | ||
16 | { | 16 | { |
17 | class DmpTmsTileProvider | 17 | class DmpTmsTileProvider |
18 | { | 18 | { |
19 | - public: | 19 | + public: |
20 | + std::string ImageFormat() const; | ||
20 | DmpTmsTileProvider(const std::string& root_path); | 21 | DmpTmsTileProvider(const std::string& root_path); |
21 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) ; | 22 | void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) ; |
22 | - protected: | 23 | + protected: |
23 | std::string file_rootPath; | 24 | std::string file_rootPath; |
24 | }; | 25 | }; |
25 | } | 26 | } |
27 | + | ||
26 | #endif | 28 | #endif |
@@ -31,7 +31,7 @@ namespace DmpWmts | @@ -31,7 +31,7 @@ namespace DmpWmts | ||
31 | } | 31 | } |
32 | } | 32 | } |
33 | l = "L" + l; | 33 | l = "L" + l; |
34 | - string r = IntToHexStr(rGroup); | 34 | + string r = DmpWmtsUtils::IntToHexStr(rGroup); |
35 | 35 | ||
36 | int rLength = r.length(); | 36 | int rLength = r.length(); |
37 | if (rLength < 4) | 37 | if (rLength < 4) |
@@ -43,7 +43,7 @@ namespace DmpWmts | @@ -43,7 +43,7 @@ namespace DmpWmts | ||
43 | } | 43 | } |
44 | r = "R" + r; | 44 | r = "R" + r; |
45 | 45 | ||
46 | - string c = IntToHexStr(cGroup); | 46 | + string c = DmpWmtsUtils::IntToHexStr(cGroup); |
47 | int cLength = c.length(); | 47 | int cLength = c.length(); |
48 | if (cLength < 4) | 48 | if (cLength < 4) |
49 | { | 49 | { |
@@ -28,7 +28,7 @@ namespace DmpWmts | @@ -28,7 +28,7 @@ namespace DmpWmts | ||
28 | } | 28 | } |
29 | void DmpEsriTileProvider::WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) | 29 | void DmpEsriTileProvider::WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) |
30 | { | 30 | { |
31 | - std::string level_str = "L" + IntToFormatStr(level); | 31 | + std::string level_str = "L" + DmpWmtsUtils::IntToFormatStr(level); |
32 | std::string row_str = "R" + IntToHex8Str(row); | 32 | std::string row_str = "R" + IntToHex8Str(row); |
33 | std::string col_str = "C" + IntToHex8Str(col); | 33 | std::string col_str = "C" + IntToHex8Str(col); |
34 | 34 |
@@ -58,7 +58,27 @@ namespace DmpWmts | @@ -58,7 +58,27 @@ namespace DmpWmts | ||
58 | 58 | ||
59 | return provider; | 59 | return provider; |
60 | } | 60 | } |
61 | - | 61 | + int TileProviderFactory::StringToVector(std::string& strVector) |
62 | + { | ||
63 | + int iVector_=-1; | ||
64 | + if(std::strcmp(strVector.c_str(),"ESRI_V0")==0) | ||
65 | + { | ||
66 | + iVector_=0; | ||
67 | + } | ||
68 | + else if(std::strcmp(strVector.c_str(),"ESRI_V1")==0) | ||
69 | + { | ||
70 | + iVector_=1; | ||
71 | + } | ||
72 | + else if(std::strcmp(strVector.c_str(),"ESRI_V2")==0) | ||
73 | + { | ||
74 | + iVector_=2; | ||
75 | + } | ||
76 | + else | ||
77 | + { | ||
78 | + iVector_=3; | ||
79 | + } | ||
80 | + return iVector_; | ||
81 | + } | ||
62 | // CapabiliTileProviderFactory::CapabiliTileProviderFactory() | 82 | // CapabiliTileProviderFactory::CapabiliTileProviderFactory() |
63 | // { | 83 | // { |
64 | // } | 84 | // } |
@@ -31,7 +31,8 @@ namespace DmpWmts | @@ -31,7 +31,8 @@ namespace DmpWmts | ||
31 | class TileProviderFactory | 31 | class TileProviderFactory |
32 | { | 32 | { |
33 | public: | 33 | public: |
34 | - static std::shared_ptr<DmpTileProvider> GetProvider( DmpTileLayer* dmpTileLayer); | 34 | + static std::shared_ptr<DmpTileProvider> GetProvider( DmpTileLayer* dmpTileLayer); |
35 | + static int StringToVector(std::string& strVector); | ||
35 | private: | 36 | private: |
36 | TileProviderFactory(); | 37 | TileProviderFactory(); |
37 | }; | 38 | }; |
@@ -11,9 +11,8 @@ | @@ -11,9 +11,8 @@ | ||
11 | #include <boost/property_tree/xml_parser.hpp> | 11 | #include <boost/property_tree/xml_parser.hpp> |
12 | #include <string> | 12 | #include <string> |
13 | namespace DmpWmts | 13 | namespace DmpWmts |
14 | -{ | ||
15 | - | ||
16 | - std::string IntToFormatStr(const int num) | 14 | +{ |
15 | + std::string DmpWmtsUtils::IntToFormatStr(const int num) | ||
17 | { | 16 | { |
18 | std::string str = std::to_string(num); | 17 | std::string str = std::to_string(num); |
19 | if(num>=0 && num<10) | 18 | if(num>=0 && num<10) |
@@ -23,7 +22,7 @@ namespace DmpWmts | @@ -23,7 +22,7 @@ namespace DmpWmts | ||
23 | return str; | 22 | return str; |
24 | } | 23 | } |
25 | 24 | ||
26 | - std::string IntToHexStr(const int num) | 25 | + std::string DmpWmtsUtils::IntToHexStr(const int num) |
27 | { | 26 | { |
28 | char* buffer = new char[8]; | 27 | char* buffer = new char[8]; |
29 | sprintf(buffer,"%x",num); | 28 | sprintf(buffer,"%x",num); |
@@ -31,26 +30,5 @@ namespace DmpWmts | @@ -31,26 +30,5 @@ namespace DmpWmts | ||
31 | delete[] buffer; | 30 | delete[] buffer; |
32 | return str; | 31 | return str; |
33 | } | 32 | } |
34 | - int StringToVector(std::string& strVector) | ||
35 | - { | ||
36 | - int iVector_=-1; | ||
37 | - if(std::strcmp(strVector.c_str(),"ESRI_V0")==0) | ||
38 | - { | ||
39 | - iVector_=0; | ||
40 | - } | ||
41 | - else if(std::strcmp(strVector.c_str(),"ESRI_V1")==0) | ||
42 | - { | ||
43 | - iVector_=1; | ||
44 | - } | ||
45 | - else if(std::strcmp(strVector.c_str(),"ESRI_V2")==0) | ||
46 | - { | ||
47 | - iVector_=2; | ||
48 | - } | ||
49 | - else | ||
50 | - { | ||
51 | - iVector_=3; | ||
52 | - } | ||
53 | - return iVector_; | ||
54 | - } | ||
55 | 33 | ||
56 | } | 34 | } |
@@ -15,9 +15,13 @@ | @@ -15,9 +15,13 @@ | ||
15 | 15 | ||
16 | namespace DmpWmts | 16 | namespace DmpWmts |
17 | { | 17 | { |
18 | - std::string IntToFormatStr(const int num); | ||
19 | - std::string IntToHexStr(const int num); | ||
20 | - int StringToVector(std::string& strVector); | 18 | + class DmpWmtsUtils |
19 | + { | ||
20 | + public: | ||
21 | + static std::string IntToFormatStr(const int num); | ||
22 | + static std::string IntToHexStr(const int num); | ||
23 | + | ||
24 | + }; | ||
21 | } | 25 | } |
22 | 26 | ||
23 | #endif //__dmpwmtsutils_h__ | 27 | #endif //__dmpwmtsutils_h__ |
请
注册
或
登录
后发表评论