提交 fad9178405650ec33b91b6c60ddcb8335992bfa0

作者 WZP 万忠平
1 个父辈 8f20520f

wzp

... ... @@ -37,7 +37,6 @@ SET (DMAP_SERVER_SRCS
37 37 dmpserverregistry.cpp
38 38 python/dmppythonutils.cpp
39 39 python/dmpserverwrapper.cpp
40   - dmppgsqlutils.cpp
41 40 dmphttpbase.cpp
42 41 dmphttputils.cpp
43 42 )
... ... @@ -69,7 +68,6 @@ SET (DMAP_SERVER_HDRS
69 68 dmpserverproject.h
70 69 dmpserverregistry.h
71 70 python/dmppythonutils.h
72   - dmppgsqlutils.h
73 71 dmphttpbase.h
74 72 dmphttputils.h
75 73 )
... ...
1   -#include <iostream>
2   -#include <libpq-fe.h>
3   -#include <map>
4   -#include <vector>
5   -#include <boost/property_tree/ptree.hpp>
6   -#include "dmppgsqlutils.h"
7   -
8   -
9   - DmpPgsqlUtils::DmpPgsqlUtils()
10   - {}
11   - DmpPgsqlUtils::DmpPgsqlUtils( const char* strConn,std::string& Msg)
12   - {
13   - //std::string strconn_="hostaddr=172.26.99.160 prot=5432 dbname='DmapServer' user='postgres' password='chinadci'";
14   - conn_=strConn;
15   - basepconn_=PQconnectdb(conn_);
16   - if(PQstatus(basepconn_)!=CONNECTION_OK)
17   - {
18   - Msg= (std::string)PQerrorMessage(basepconn_);
19   - }
20   - }
21   - DmpPgsqlUtils::~DmpPgsqlUtils()
22   - {
23   - if(PQstatus(basepconn_)==CONNECTION_OK)
24   - {
25   - PQfinish(basepconn_);
26   - }
27   - }
28   -
29   - void DmpPgsqlUtils::do_exit(PGconn *conn)
30   - {
31   - PQfinish(conn);
32   - exit(1);
33   - }
34   -
35   - bool DmpPgsqlUtils::GetDMapServices(std::map<int,DMapService> &dmapServices,std::string& Msg)
36   - {
37   - PGresult *res;
38   - const char* strsql="SELECT name, title, state::character, create_time, update_time, description, node::character, overview, type, service_guid, catalog_guid FROM public.dmap_service where type='WMTS'";
39   - //char* conn_="hostaddr=172.26.60.100 port=5432 dbname=dmap_manager_test user=postgres password=chinadci";
40   - //PGconn* pconn_=PQconnectdb(conn_);
41   - if(PQstatus(basepconn_)!=CONNECTION_OK)
42   - {
43   - std::string Msg_= (std::string)PQerrorMessage(basepconn_);
44   - PQfinish(basepconn_);
45   - return false;
46   - }
47   - res = PQexec(basepconn_,strsql);
48   - int tuple_num=PQntuples(res);
49   - int field_num=PQnfields(res);
50   - if(tuple_num>0)
51   - {
52   - for(int i=0;i<tuple_num;i++)
53   - {
54   - std::string name=PQgetvalue(res,i,0);
55   - std::string state=PQgetvalue(res,i,2);
56   - std::string createtime=PQgetvalue(res,i,3);
57   - std::string type=PQgetvalue(res,i,8);
58   - std::string serviceguid=PQgetvalue(res,i,9);
59   - DMapService service{
60   - .name=name,
61   - .state=state,
62   - .create_time=createtime,
63   - .type=type,
64   - .service_guid=serviceguid
65   - };
66   - dmapServices[i]=service;
67   - }
68   -
69   - }
70   - else
71   - {
72   - return false;
73   - }
74   - PQclear(res);
75   - return true;
76   - }
77   - bool DmpPgsqlUtils::GetDMapService(DMapService &dmapService,const std::string& servicename,std::string& Msg)
78   - {
79   - PGresult *res;
80   - std::string strsql="SELECT name, title, state::character, create_time, update_time, description, node::character, overview, type, service_guid, catalog_guid FROM public.dmap_service where name='"+servicename+"'";
81   - const char* csql=strsql.c_str();
82   - if(PQstatus(basepconn_)!=CONNECTION_OK)
83   - {
84   - std::string Msg= (std::string)PQerrorMessage(basepconn_);
85   - PQfinish(basepconn_);
86   - return false;
87   - }
88   - res = PQexec(basepconn_,csql);
89   - int tuple_num=PQntuples(res);
90   - int field_num=PQnfields(res);
91   - if(tuple_num==1)
92   - {
93   - std::string name=PQgetvalue(res,0,0);
94   - std::string state=PQgetvalue(res,0,2);
95   - std::string createtime=PQgetvalue(res,0,3);
96   - std::string type=PQgetvalue(res,0,8);
97   - std::string serviceguid=PQgetvalue(res,0,9);
98   - DMapService service{
99   - .name=name,
100   - .state=state,
101   - .create_time=createtime,
102   - .type=type,
103   - .service_guid=serviceguid
104   - };
105   - dmapService=service;
106   - }
107   - else
108   - {
109   - return false;
110   - }
111   - PQclear(res);
112   - return true;
113   - }
114   -
115   - bool DmpPgsqlUtils::GetDMapwmts(const std::string& serviceGuid,DMapWmtsService& resWmts,std::string& Msg)
116   - {
117   - //char* conn_="hostaddr=172.26.60.100 port=5432 dbname=dmap_manager_test user=postgres password=chinadci";
118   - std::string strsql="SELECT name, wmts_type, vendor, create_time::character, crs, datasource, metadata_url, scheme_guid FROM public.dmap_wmts where guid='"+serviceGuid+"'";
119   - const char* csql=strsql.c_str();
120   -
121   - //PGconn* pconn_=PQconnectdb(conn_);
122   - if(PQstatus(basepconn_)!=CONNECTION_OK)
123   - {
124   - std::string Msg= (std::string)PQerrorMessage(basepconn_);
125   - PQfinish(basepconn_);
126   - return false;
127   - }
128   - PGresult *res;
129   - res = PQexec(basepconn_,csql);
130   - int tuple_num=PQntuples(res);
131   - int field_num=PQnfields(res);
132   -
133   - if(tuple_num>0)
134   - {
135   - resWmts.name=PQgetvalue(res,0,0);
136   - resWmts.type=PQgetvalue(res,0,1);
137   - std::string v=PQgetvalue(res,0,2);
138   - resWmts.vendor=StringToVendor(v);
139   - resWmts.create_time=PQgetvalue(res,0,3);
140   - resWmts.crs=PQgetvalue(res,0,4);
141   - resWmts.datasource=PQgetvalue(res,0,5);
142   - resWmts.metadata_url=PQgetvalue(res,0,6);
143   - resWmts.tile_id= PQgetvalue(res,0,7);
144   - }
145   - else
146   - {
147   - return false;
148   - }
149   - PQclear(res);
150   - return true;
151   - }
152   - bool DmpPgsqlUtils::GetDMapwmtsFromName(const std::string& serviceName, DMapWmtsService& resWmts,std::string& Msg)
153   - {
154   - std::string strsql="SELECT name, wmts_type, vendor, create_time::character, crs, datasource, metadata_url,layer_name, layer_alias, layer_title, layer_style, layer_format, layer_extent, scheme_guid FROM public.dmap_wmts where name='"+serviceName+"'";
155   - const char* csql=strsql.c_str();
156   -
157   - //PGconn* pconn_=PQconnectdb(conn_);
158   - if(PQstatus(basepconn_)!=CONNECTION_OK)
159   - {
160   - std::string Msg= (std::string)PQerrorMessage(basepconn_);
161   - PQfinish(basepconn_);
162   - return false;
163   - }
164   - PGresult *res;
165   - res = PQexec(basepconn_,csql);
166   - int tuple_num=PQntuples(res);
167   - int field_num=PQnfields(res);
168   -
169   - if(tuple_num>0)
170   - {
171   - resWmts.name=PQgetvalue(res,0,0);
172   - resWmts.type=PQgetvalue(res,0,1);
173   - std::string v=PQgetvalue(res,0,2);
174   - resWmts.vendor=StringToVendor(v);
175   - resWmts.create_time=PQgetvalue(res,0,3);
176   - resWmts.crs=PQgetvalue(res,0,4);
177   - resWmts.datasource=PQgetvalue(res,0,5);
178   - resWmts.metadata_url=PQgetvalue(res,0,6);
179   - resWmts.layername=PQgetvalue(res,0,7);
180   - resWmts.layer_alias=PQgetvalue(res,0,8);
181   - resWmts.layer_tile=PQgetvalue(res,0,9);
182   - resWmts.layer_style=PQgetvalue(res,0,10);
183   - resWmts.layer_format=PQgetvalue(res,0,11);
184   - resWmts.layer_extent=PQgetvalue(res,0,12);
185   - resWmts.tile_id= PQgetvalue(res,0,13);
186   - }
187   - else
188   - {
189   - return false;
190   - }
191   - PQclear(res);
192   - return true;
193   - }
194   - bool DmpPgsqlUtils::GetTileScheme(const std::string& guid,TileScheme& tileScheme,std::string& Msg)
195   - {
196   - std::string strsql="SELECT guid, name, alias, description, crs, crs_wkt, extent, top_left, levels, dpi::character, rows::character, cols::character, update_time, parameter FROM public.dmap_tile_scheme where guid='"+guid+"'";
197   - const char* csql=strsql.c_str();
198   -
199   - //PGconn* pconn_=PQconnectdb(conn_);
200   - if(PQstatus(basepconn_)!=CONNECTION_OK)
201   - {
202   - std::string Msg= (std::string)PQerrorMessage(basepconn_);
203   - PQfinish(basepconn_);
204   - return false;
205   - }
206   - PGresult *res;
207   - res = PQexec(basepconn_,csql);
208   - int tuple_num=PQntuples(res);
209   - int field_num=PQnfields(res);
210   -
211   - if(tuple_num>0)
212   - {
213   - tileScheme.guid=PQgetvalue(res,0,0);
214   - tileScheme.name=PQgetvalue(res,0,1);
215   - tileScheme.crs=PQgetvalue(res,0,4);
216   - tileScheme.wkt=PQgetvalue(res,0,5);
217   - tileScheme.layer_extent=PQgetvalue(res,0,6);
218   - tileScheme.top_left=PQgetvalue(res,0,7);
219   - tileScheme.levels=PQgetvalue(res,0,8);
220   - tileScheme.dpi=PQgetvalue(res,0,9);
221   - tileScheme.rows=PQgetvalue(res,0,10);
222   - tileScheme.cols=PQgetvalue(res,0,11);
223   - }
224   - else
225   - {
226   - return false;
227   - }
228   - PQclear(res);
229   - return true;
230   - }
231   - bool DmpPgsqlUtils::CreatServerPTree(const DMapService &dmapServices,const DMapWmtsService& resWmts,boost::property_tree::ptree& pt_root)
232   - {
233   - boost::property_tree::ptree pt_properties;
234   - pt_root.add("serviceName",dmapServices.name);
235   - pt_root.add("mapType",dmapServices.type);
236   - pt_root.add("state",dmapServices.state);
237   - pt_root.add("capabilities",dmapServices.type+"Server");
238   - pt_root.add_child("properties",pt_properties);
239   - pt_properties.add("filePath","postgresql");
240   - pt_properties.add("maxScale","");
241   - pt_properties.add("minScale","");
242   - boost::property_tree::ptree pt_services,pt_service;
243   - //pt_service.add("typeName",atoi(dmpwmtsservices_.type.c_str()));
244   - pt_service.add("typeName",0);
245   - pt_service.add("enabled","true");
246   - pt_service.add("properties.tileVersion",resWmts.vendor);
247   - pt_service.add("properties.tilePath",resWmts.datasource);
248   - pt_service.add("capabilities","");
249   - pt_services.push_back(std::make_pair("", pt_service));
250   - pt_root.put_child("services",pt_services);
251   - return true;
252   - }
253   - bool DmpPgsqlUtils::GetDMapServices(DMapService &dmapService,const std::string serviceName,std::string& Msg)
254   - {
255   - PGresult *res;
256   - const char* strsql="SELECT name, title, state::character, create_time, update_time, description, node::character, overview, type, service_guid, catalog_guid FROM public.dmap_service where type='WMTS'";
257   - //char* conn_="hostaddr=172.26.60.100 port=5432 dbname=dmap_manager_test user=postgres password=chinadci";
258   - //PGconn* pconn_=PQconnectdb(conn_);
259   - if(PQstatus(basepconn_)!=CONNECTION_OK)
260   - {
261   - std::string Msg= (std::string)PQerrorMessage(basepconn_);
262   - PQfinish(basepconn_);
263   - return false;
264   - }
265   - res = PQexec(basepconn_,strsql);
266   - int tuple_num=PQntuples(res);
267   - if(tuple_num>0)
268   - {
269   - dmapService.name=PQgetvalue(res,0,0);
270   - dmapService.state=PQgetvalue(res,0,2);
271   - dmapService.create_time=PQgetvalue(res,0,3);
272   - dmapService.type=PQgetvalue(res,0,8);
273   - dmapService.service_guid=PQgetvalue(res,0,9);
274   - }
275   - else
276   - {
277   - return false;
278   - }
279   - PQclear(res);
280   - return true;
281   - }
282   -
283   - std::string DmpPgsqlUtils::StringToVendor(const std::string str)
284   - {
285   - std::string v="-1";
286   - if(str=="ESRI_V0")
287   - v="0";
288   - else if(str=="ESRI_V1")
289   - v="1";
290   - else if(str=="ESRI_V2")
291   - v="2";
292   - else if(str=="QGIS")
293   - v="3";
294   - else
295   - {}
296   -
297   - return v;
298   - }
299   -
300   -
301   -
302   -
\ No newline at end of file
1   -#ifndef __dmppgsqlutils_h__
2   -#define __dmppgsqlutils_h__
3   -
4   -#include <iostream>
5   -#include <map>
6   -#include <boost/property_tree/ptree.hpp>
7   -#include <libpq-fe.h>
8   -#include <string>
9   -
10   - //typedef std::map<int,std::map<std::string,std::string>> resMap;
11   - struct DMapService
12   - {
13   - std::string name;
14   - std::string alias;
15   - std::string state;
16   - std::string create_time;
17   - std::string update_time;
18   - std::string type;
19   - std::string description;
20   - std::string node;
21   - std::string service_guid;
22   - std::string catalog_guid;
23   - };
24   - struct DMapWmtsService
25   - {
26   - std::string name;
27   - std::string type;
28   - std::string vendor;
29   - std::string crs;
30   - std::string create_time;
31   - std::string datasource;
32   - std::string metadata_url;
33   - std::string description;
34   - std::string layername;
35   - std::string layer_alias;
36   - std::string layer_tile;
37   - std::string layer_style;
38   - std::string layer_format;
39   - std::string layer_extent;
40   - std::string layer_description;
41   - std::string tile_id;
42   - };
43   - struct TileScheme
44   - {
45   - std::string guid;
46   - std::string name;
47   - std::string alias;
48   - std::string crs;
49   - std::string datasource;
50   - std::string top_left;
51   - std::string levels;
52   - std::string update_time;
53   - std::string dpi;
54   - std::string rows;
55   - std::string cols;
56   - std::string wkt ;
57   - std::string layer_extent;
58   - };
59   - class DmpPgsqlUtils
60   - {
61   - private:
62   - const char* conn_;
63   - PGconn* basepconn_;
64   - void FinishConnection(PGconn *conn);
65   - void Reset();
66   - public:
67   - DmpPgsqlUtils(const char* strConn_ ,std::string& Msg_);
68   - DmpPgsqlUtils();
69   - ~DmpPgsqlUtils();
70   -
71   - void do_exit(PGconn *conn);
72   - //bool ExecuteQuery(const std::string& sqlstr,resMap& resMap_,std::string& Msg_);
73   - bool GetDMapServices(std::map<int,DMapService> &dmapServices,std::string& Msg);
74   - bool GetDMapService(DMapService &dmapService,const std::string& servicename,std::string& Msg);
75   - bool GetDMapwmts(const std::string& serviceGuid, DMapWmtsService& resWmts,std::string& Msg);
76   - bool GetDMapwmtsFromName(const std::string& serviceName, DMapWmtsService& resWmts,std::string& Msg);
77   - bool GetTileScheme(const std::string& guid, TileScheme& tileScheme,std::string& Msg);
78   - bool CreatServerPTree(const DMapService &dmapServices,const DMapWmtsService& resWmts,boost::property_tree::ptree& pt_root);
79   - bool GetDMapServices(DMapService &dmapService,const std::string serviceName,std::string& Msg);
80   - std::string StringToVendor(const std::string str);
81   - };
82   -
83   -
84   -
85   -
86   -#endif //__dmpwmtsutils_h__
\ No newline at end of file
注册登录 后发表评论