|
1
|
+/**************************************************************************
|
|
2
|
+* file: dmpwfsgetcapabilities.cpp
|
|
3
|
+
|
|
4
|
+* Author: qingxiongf
|
|
5
|
+* Date: 2021-12-22 14:04:56
|
|
6
|
+* Email: qingxiongf@chinadci.com
|
|
7
|
+* copyright: 广州城市信息研究所有限公司
|
|
8
|
+***************************************************************************/
|
|
9
|
+#include "dmpwfsgetcapabilities.h"
|
|
10
|
+#include "dmpserverresponse.h"
|
|
11
|
+#include "dmpserverrequest.h"
|
|
12
|
+#include "dmpserverproject.h"
|
|
13
|
+#include "dmpvectorlayer.h"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+namespace DmpWfs
|
|
17
|
+{
|
|
18
|
+ void writeGetCapabilities( const DmpServerContext &context, const DmpWfsParameters& params,
|
|
19
|
+ const DmpProject* project, bool projectSettings)
|
|
20
|
+ {
|
|
21
|
+ std::string serviceName = context.serverProject()->name();
|
|
22
|
+ std::string serviceTitle = context.serverProject()->title();
|
|
23
|
+ if(serviceTitle.empty()) serviceTitle = serviceName;
|
|
24
|
+
|
|
25
|
+ std::string version = params.Version();
|
|
26
|
+ std::string hrefUrl;
|
|
27
|
+ char char_hrefUrl[1024] = {0};
|
|
28
|
+ std::string domain = context.request()->domain();
|
|
29
|
+ std::string port = context.request()->port();
|
|
30
|
+ if(port == "80" || port =="")
|
|
31
|
+ {
|
|
32
|
+ sprintf(char_hrefUrl, "http://%s%s", domain.c_str(), context.request()->path().c_str());
|
|
33
|
+ }
|
|
34
|
+ else
|
|
35
|
+ {
|
|
36
|
+ sprintf(char_hrefUrl, "http://%s:%s%s", domain.c_str(),port.c_str(), context.request()->path().c_str());
|
|
37
|
+ }
|
|
38
|
+ hrefUrl = char_hrefUrl;
|
|
39
|
+ // hrefUrl = "http://172.26.40.51:8821/?mapService=test";
|
|
40
|
+ std::shared_ptr<boost::property_tree::ptree> doc = getCapabilities(project, version,hrefUrl,serviceName,serviceTitle,projectSettings);
|
|
41
|
+
|
|
42
|
+ std::stringstream stream;
|
|
43
|
+ write_xml(stream, *doc.get());
|
|
44
|
+ std::string xml;
|
|
45
|
+ xml = stream.str();
|
|
46
|
+
|
|
47
|
+ // DmpServerResponse* response = context.response();
|
|
48
|
+ context.response()->removeHeader("Content-Type");
|
|
49
|
+ context.response()->setHeader("Content-Type", "text/xml;charset=utf-8");
|
|
50
|
+ context.response()->write(xml);
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+ std::shared_ptr<boost::property_tree::ptree> getCapabilities( const DmpProject* project,
|
|
55
|
+ const std::string &serviceName, const std::string &serviceTitle,
|
|
56
|
+ const std::string &version, const std::string &hrefUrl,
|
|
57
|
+ bool projectSettings )
|
|
58
|
+ {
|
|
59
|
+ std::shared_ptr<boost::property_tree::ptree> xmlRootDoc(new boost::property_tree::ptree());
|
|
60
|
+ boost::property_tree::ptree xmlRoot;
|
|
61
|
+ std::string rootname;
|
|
62
|
+
|
|
63
|
+ rootname = "WFS_Capabilities";
|
|
64
|
+ xmlRoot.add("<xmlattr>.xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
|
|
65
|
+ xmlRoot.add("<xmlattr>.xmlns","http://www.opengis.net/wfs");
|
|
66
|
+ xmlRoot.add("<xmlattr>.xmlns:sld","http://www.opengis.net/sld");
|
|
67
|
+ xmlRoot.add("<xmlattr>.xsi:schemaLocation","http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd");
|
|
68
|
+ xmlRoot.add("<xmlattr>.version", version);
|
|
69
|
+ xmlRoot.add("<xmlattr>.updateSequence", "0");
|
|
70
|
+
|
|
71
|
+ boost::property_tree::ptree ptService;
|
|
72
|
+ ptService.add("Name", serviceName);
|
|
73
|
+ ptService.add("Title", serviceTitle);
|
|
74
|
+ ptService.add("Abstract", "dmap wfs service");
|
|
75
|
+ ptService.add("Keywords", "WFS,DMAP,"+ serviceName );
|
|
76
|
+ ptService.add("OnlineResource", hrefUrl);
|
|
77
|
+ ptService.add("Fees","none");
|
|
78
|
+ ptService.add("AccessConstraints","none");
|
|
79
|
+ xmlRoot.add_child("Service",ptService);
|
|
80
|
+
|
|
81
|
+ boost::property_tree::ptree ptCapability;
|
|
82
|
+ addCapabilitiesRequest(ptCapability,hrefUrl);
|
|
83
|
+ xmlRoot.add_child("Capability",ptCapability);
|
|
84
|
+
|
|
85
|
+ boost::property_tree::ptree ptFeatureTypeList;
|
|
86
|
+ addFeatureTypeList(ptFeatureTypeList,project);
|
|
87
|
+ xmlRoot.add_child("FeatureTypeList",ptFeatureTypeList);
|
|
88
|
+
|
|
89
|
+ boost::property_tree::ptree ptFilter;
|
|
90
|
+ addFilterCapabilities(ptFilter,hrefUrl);
|
|
91
|
+ xmlRoot.add_child("ogc:Filter_Capabilities",ptFilter);
|
|
92
|
+
|
|
93
|
+ xmlRootDoc->add_child(rootname,xmlRoot);
|
|
94
|
+ return xmlRootDoc;
|
|
95
|
+
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ void addCapabilitiesRequest(boost::property_tree::ptree &pt, const std::string &hrefUrl)
|
|
99
|
+ {
|
|
100
|
+ boost::property_tree::ptree ptRequest;
|
|
101
|
+
|
|
102
|
+ boost::property_tree::ptree ptGetCapabilities;
|
|
103
|
+ addCapabilitiesRequest_DCPType(ptGetCapabilities, hrefUrl, "Get");
|
|
104
|
+ addCapabilitiesRequest_DCPType(ptGetCapabilities, hrefUrl, "Post");
|
|
105
|
+ ptRequest.add_child("GetCapabilities", ptGetCapabilities);
|
|
106
|
+
|
|
107
|
+ boost::property_tree::ptree ptDescribeFeatureType;
|
|
108
|
+ boost::property_tree::ptree ptSchemaDescriptionLanguage;
|
|
109
|
+ ptSchemaDescriptionLanguage.add("XMLSCHEMA","");
|
|
110
|
+ ptDescribeFeatureType.add_child("SchemaDescriptionLanguage",ptSchemaDescriptionLanguage);
|
|
111
|
+ addCapabilitiesRequest_DCPType(ptDescribeFeatureType, hrefUrl, "Get");
|
|
112
|
+ addCapabilitiesRequest_DCPType(ptDescribeFeatureType, hrefUrl, "Post");
|
|
113
|
+ ptRequest.add_child("DescribeFeatureType", ptDescribeFeatureType);
|
|
114
|
+
|
|
115
|
+ boost::property_tree::ptree ptGetFeature;
|
|
116
|
+ boost::property_tree::ptree ptResultFormat;
|
|
117
|
+ ptResultFormat.add("GML2","");
|
|
118
|
+ ptResultFormat.add("GML3","");
|
|
119
|
+ ptResultFormat.add("GeoJSON","");
|
|
120
|
+ ptGetFeature.add_child("ResultFormat",ptResultFormat);
|
|
121
|
+ addCapabilitiesRequest_DCPType(ptGetFeature, hrefUrl, "Get");
|
|
122
|
+ addCapabilitiesRequest_DCPType(ptGetFeature, hrefUrl, "Post");
|
|
123
|
+ ptRequest.add_child("GetFeature", ptGetFeature);
|
|
124
|
+
|
|
125
|
+ boost::property_tree::ptree ptTransaction;
|
|
126
|
+ addCapabilitiesRequest_DCPType(ptTransaction, hrefUrl, "Post");
|
|
127
|
+ ptRequest.add_child("Transaction", ptTransaction);
|
|
128
|
+
|
|
129
|
+ pt.add_child("Request", ptRequest);
|
|
130
|
+ return;
|
|
131
|
+ }
|
|
132
|
+
|
|
133
|
+ void addCapabilitiesRequest_DCPType(boost::property_tree::ptree &pt, const std::string &hrefUrl, std::string method)
|
|
134
|
+ {
|
|
135
|
+ boost::property_tree::ptree pt_dcpType;
|
|
136
|
+ boost::property_tree::ptree pt_http;
|
|
137
|
+ boost::property_tree::ptree pt_method;
|
|
138
|
+
|
|
139
|
+ pt_method.add("<xmlattr>.onlineResource", hrefUrl);
|
|
140
|
+
|
|
141
|
+ pt_http.add_child(method, pt_method);
|
|
142
|
+ pt_dcpType.add_child("HTTP", pt_http);
|
|
143
|
+ pt.add_child("DCPType", pt_dcpType);
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ void addFeatureTypeList(boost::property_tree::ptree &pt,const DmpProject *project)
|
|
147
|
+ {
|
|
148
|
+ boost::property_tree::ptree ptOperations;
|
|
149
|
+ ptOperations.add("Query","");
|
|
150
|
+ pt.add_child("Operations", ptOperations);
|
|
151
|
+
|
|
152
|
+ int i = 0;
|
|
153
|
+ std::map<std::string, DmpMapLayer *> mapLayers = project->mapLayers();
|
|
154
|
+ for (std::map<std::string, DmpMapLayer *>::iterator iter = mapLayers.begin(); iter != mapLayers.end(); iter++, i++)
|
|
155
|
+ {
|
|
156
|
+ DmpVectorLayer *layer = (DmpVectorLayer *)iter->second;
|
|
157
|
+ std::string source = layer->source();
|
|
158
|
+ shared_ptr<DmpPgsql> pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source());
|
|
159
|
+ if (pPgsqlConn != nullptr)
|
|
160
|
+ {
|
|
161
|
+ boost::property_tree::ptree ptFeatureType;
|
|
162
|
+ std::string srs = "EPSG:" + std::__cxx11::to_string(project->crs().srid());
|
|
163
|
+ ptFeatureType.add("<xmlattr>.id", i);
|
|
164
|
+ ptFeatureType.add("Name", layer->name());
|
|
165
|
+ ptFeatureType.add("Title", layer->title());
|
|
166
|
+ ptFeatureType.add("DisplayColumn", "");
|
|
167
|
+ ptFeatureType.add("Geometry", "点");
|
|
168
|
+ ptFeatureType.add("GeometryColumn", layer->geom());
|
|
169
|
+ ptFeatureType.add("SRS", srs);
|
|
170
|
+
|
|
171
|
+ boost::property_tree::ptree ptBoundingbox;
|
|
172
|
+ ptBoundingbox.add("<xmlattr>.CRS", srs);
|
|
173
|
+ if (boost::iequals(srs, "CRS:84") || boost::iequals(srs, "EPSG:4326"))
|
|
174
|
+ {
|
|
175
|
+ ptBoundingbox.add("<xmlattr>.miny", layer->extent().xmin());
|
|
176
|
+ ptBoundingbox.add("<xmlattr>.maxy", layer->extent().xmax());
|
|
177
|
+ ptBoundingbox.add("<xmlattr>.minx", layer->extent().ymin());
|
|
178
|
+ ptBoundingbox.add("<xmlattr>.maxx", layer->extent().ymax());
|
|
179
|
+ }
|
|
180
|
+ else
|
|
181
|
+ {
|
|
182
|
+ ptBoundingbox.add("<xmlattr>.minx", layer->extent().xmin());
|
|
183
|
+ ptBoundingbox.add("<xmlattr>.maxx", layer->extent().xmax());
|
|
184
|
+ ptBoundingbox.add("<xmlattr>.miny", layer->extent().ymin());
|
|
185
|
+ ptBoundingbox.add("<xmlattr>.maxy", layer->extent().ymax());
|
|
186
|
+ }
|
|
187
|
+ ptFeatureType.add_child("LatLongBoundingBox", ptBoundingbox);
|
|
188
|
+
|
|
189
|
+ boost::property_tree::ptree ptFields;
|
|
190
|
+ for (; pPgsqlConn->next();)
|
|
191
|
+ {
|
|
192
|
+ std::string fieldname = pPgsqlConn->getString(0);
|
|
193
|
+ std::string typeString = pPgsqlConn->getString(1);
|
|
194
|
+ std::string aliasName = "";
|
|
195
|
+ std::string type = "";
|
|
196
|
+ int typeInt = PGFieldType::VarCharFieldType;
|
|
197
|
+ if (layer->geom() == fieldname)
|
|
198
|
+ {
|
|
199
|
+ typeString = "geometry";
|
|
200
|
+ typeInt = PGFieldType::ShapeFieldType;
|
|
201
|
+ }
|
|
202
|
+ else if (typeString == "integer")
|
|
203
|
+ {
|
|
204
|
+ typeInt = PGFieldType::IntFieldType;
|
|
205
|
+ }
|
|
206
|
+ else if (typeString == "bigint")
|
|
207
|
+ {
|
|
208
|
+ typeInt = PGFieldType::BigIntFieldType;
|
|
209
|
+ }
|
|
210
|
+ else if (typeString == "double precision" || typeString == "real" || typeString == "numeric")
|
|
211
|
+ {
|
|
212
|
+ typeInt = PGFieldType::DoubleFieldType;
|
|
213
|
+ }
|
|
214
|
+ else if (typeString == "character varying" || typeString == "text")
|
|
215
|
+ {
|
|
216
|
+ typeInt = PGFieldType::VarCharFieldType;
|
|
217
|
+ }
|
|
218
|
+ else if (typeString == "geometry")
|
|
219
|
+ {
|
|
220
|
+ typeInt = PGFieldType::ShapeFieldType;
|
|
221
|
+ }
|
|
222
|
+ else if (typeString == "bytea")
|
|
223
|
+ {
|
|
224
|
+ typeInt = PGFieldType::ByteaFieldType;
|
|
225
|
+ }
|
|
226
|
+ else if (typeString == "timestamp without time zone")
|
|
227
|
+ {
|
|
228
|
+ typeInt = PGFieldType::TimestampWithoutTimeZone;
|
|
229
|
+ }
|
|
230
|
+
|
|
231
|
+ switch (typeInt)
|
|
232
|
+ {
|
|
233
|
+ case PGFieldType::IntFieldType:
|
|
234
|
+ typeString = "integer";
|
|
235
|
+ break;
|
|
236
|
+ case PGFieldType::BigIntFieldType:
|
|
237
|
+ case PGFieldType::DoubleFieldType:
|
|
238
|
+ typeString = "double";
|
|
239
|
+ break;
|
|
240
|
+ case PGFieldType::VarCharFieldType:
|
|
241
|
+ typeString = "string";
|
|
242
|
+ break;
|
|
243
|
+ default:
|
|
244
|
+ break;
|
|
245
|
+ }
|
|
246
|
+ boost::property_tree::ptree ptField;
|
|
247
|
+ ptField.add("<xmlattr>.name", fieldname);
|
|
248
|
+ ptField.add("<xmlattr>.aliasName", aliasName);
|
|
249
|
+ ptField.add("<xmlattr>.type", "xsd:" + typeString);
|
|
250
|
+ ptField.add("<xmlattr>.minOccurs", "0");
|
|
251
|
+ ptField.add("<xmlattr>.maxOccurs", "1");
|
|
252
|
+ ptFields.add_child("Field", ptField);
|
|
253
|
+ }
|
|
254
|
+ ptFeatureType.add_child("Fields", ptFields);
|
|
255
|
+ pt.add_child("FeatureType", ptFeatureType);
|
|
256
|
+ }
|
|
257
|
+
|
|
258
|
+ }
|
|
259
|
+ }
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+ void addFilterCapabilities(boost::property_tree::ptree &pt,const std::string &hrefUrl)
|
|
263
|
+ {
|
|
264
|
+ boost::property_tree::ptree ptFilterCapabilities;
|
|
265
|
+
|
|
266
|
+ boost::property_tree::ptree ptSpatialCapabilities;
|
|
267
|
+ boost::property_tree::ptree ptSpatialOperators;
|
|
268
|
+ ptSpatialOperators.add("ogc:BBOX","");
|
|
269
|
+ ptSpatialCapabilities.add_child("ogc:Spatial_Operators",ptSpatialOperators);
|
|
270
|
+ ptFilterCapabilities.add_child("ogc:Spatial_Capabilities", ptSpatialCapabilities);
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+ boost::property_tree::ptree ptScalarCapabilities;
|
|
274
|
+ boost::property_tree::ptree ptComparisonOperators;
|
|
275
|
+ ptComparisonOperators.add("ogc:Simple_Comparisons","");
|
|
276
|
+ ptScalarCapabilities.add_child("ogc:Comparison_Operators",ptComparisonOperators);
|
|
277
|
+ ptFilterCapabilities.add_child("ogc:Filter_Capabilities", ptScalarCapabilities);
|
|
278
|
+
|
|
279
|
+ pt.add_child("ogc:Filter_Capabilities", ptFilterCapabilities);
|
|
280
|
+ }
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+} |
|
|
\ No newline at end of file |
...
|
...
|
|