...
|
...
|
@@ -32,4 +32,1585 @@ namespace DmpWfs |
32
|
32
|
return false;
|
33
|
33
|
}
|
34
|
34
|
|
|
35
|
+ std::string DmpWfsFilter::GetFieldName(const std::string& name)
|
|
36
|
+ {
|
|
37
|
+ int len = name.size();
|
|
38
|
+ char p[100];
|
|
39
|
+ strcpy(p, name.c_str());
|
|
40
|
+ for (int i = 0; i < len; i++)
|
|
41
|
+ {
|
|
42
|
+ if (name[i] == ':')
|
|
43
|
+ {
|
|
44
|
+ strcpy(p, &name[i + 1]);
|
|
45
|
+ len = strlen(p);
|
|
46
|
+ break;
|
|
47
|
+ }
|
|
48
|
+ }
|
|
49
|
+ std::string str = p;
|
|
50
|
+ return str;
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ int DmpWfsFilter::_All(const std::string &ptname,boost::property_tree::ptree& ptree)
|
|
54
|
+ {
|
|
55
|
+
|
|
56
|
+ std::string name = GetFieldName(ptname);
|
|
57
|
+ const char *p = name.c_str();
|
|
58
|
+
|
|
59
|
+ switch (name.length())
|
|
60
|
+ {
|
|
61
|
+ case 2:
|
|
62
|
+ if (0 == strcmp(p, "Or"))
|
|
63
|
+ return _Or(ptree);
|
|
64
|
+ break;
|
|
65
|
+ case 3:
|
|
66
|
+ if (0 == strcmp(p, "Not"))
|
|
67
|
+ return _Not(ptree);
|
|
68
|
+ if (0 == strcmp(p, "And"))
|
|
69
|
+ return _And(ptree);
|
|
70
|
+ break;
|
|
71
|
+ case 4:
|
|
72
|
+ if (0 == strcmp(p, "BBOX"))
|
|
73
|
+ return _BBOX(ptree);
|
|
74
|
+ break;
|
|
75
|
+ case 6:
|
|
76
|
+ if (0 == strcmp(p, "Equals"))
|
|
77
|
+ return _Equals(ptree);
|
|
78
|
+ if (0 == strcmp(p, "Beyond"))
|
|
79
|
+ return _Beyond(ptree);
|
|
80
|
+ if (0 == strcmp(p, "Within"))
|
|
81
|
+ return _Within(ptree);
|
|
82
|
+ break;
|
|
83
|
+ case 7:
|
|
84
|
+ if (0 == strcmp(p, "Crosses"))
|
|
85
|
+ return _Crosses(ptree);
|
|
86
|
+ if (0 == strcmp(p, "Touches"))
|
|
87
|
+ return _Touches(ptree);
|
|
88
|
+ if (0 == strcmp(p, "DWithin"))
|
|
89
|
+ return _DWithin(ptree);
|
|
90
|
+ break;
|
|
91
|
+ case 8:
|
|
92
|
+ if (0 == strcmp(p, "Contains"))
|
|
93
|
+ return _Contains(ptree);
|
|
94
|
+ if (0 == strcmp(p, "Overlaps"))
|
|
95
|
+ return _Overlaps(ptree);
|
|
96
|
+ if (0 == strcmp(p, "Disjoint"))
|
|
97
|
+ return _Disjoint(ptree);
|
|
98
|
+ break;
|
|
99
|
+ case 9:
|
|
100
|
+ if (0 == strcmp(p, "FeatureId"))
|
|
101
|
+ return _FeatureId(ptree);
|
|
102
|
+ break;
|
|
103
|
+ case 10:
|
|
104
|
+ if (0 == strcmp(p, "Intersects"))
|
|
105
|
+ return _Intersects(ptree);
|
|
106
|
+ if (0 == strcmp(p, "ResourceId"))
|
|
107
|
+ return _FeatureId(ptree);
|
|
108
|
+ break;
|
|
109
|
+ case 11:
|
|
110
|
+ if (0 == strcmp(p, "GmlObjectId"))
|
|
111
|
+ return _GmlObjectId(ptree);
|
|
112
|
+ if (0 == strcmp(p, "DIntersects"))
|
|
113
|
+ return _DIntersects(ptree);
|
|
114
|
+ break;
|
|
115
|
+ case 14:
|
|
116
|
+ if (0 == strcmp(p, "PropertyIsLike"))
|
|
117
|
+ return _PropertyIsLike(ptree);
|
|
118
|
+ if (0 == strcmp(p, "PropertyIsNull"))
|
|
119
|
+ return _PropertyIsNull(ptree);
|
|
120
|
+ if (0 == strcmp(p, "fes:ResourceId") || 0 == strcmp(p, "ogc:ResourceId"))
|
|
121
|
+ return _FeatureId(ptree);
|
|
122
|
+ break;
|
|
123
|
+ case 17:
|
|
124
|
+ if (0 == strcmp(p, "PropertyIsBetween"))
|
|
125
|
+ return _PropertyIsBetween(ptree);
|
|
126
|
+ if (0 == strcmp(p, "PropertyIsEqualTo"))
|
|
127
|
+ return _PropertyIsEqualTo(ptree);
|
|
128
|
+ break;
|
|
129
|
+ case 18:
|
|
130
|
+ if (0 == strcmp(p, "PropertyIsLessThan"))
|
|
131
|
+ return _PropertyIsLessThan(ptree);
|
|
132
|
+ break;
|
|
133
|
+ case 20:
|
|
134
|
+ if (0 == strcmp(p, "PropertyIsNotEqualTo"))
|
|
135
|
+ return _PropertyIsNotEqualTo(ptree);
|
|
136
|
+ break;
|
|
137
|
+ case 21:
|
|
138
|
+ if (0 == strcmp(p, "PropertyIsGreaterThan"))
|
|
139
|
+ return _PropertyIsGreaterThan(ptree);
|
|
140
|
+ break;
|
|
141
|
+ case 27:
|
|
142
|
+ if (0 == strcmp(p, "PropertyIsLessThanOrEqualTo"))
|
|
143
|
+ return _PropertyIsLessThanOrEqualTo(ptree);
|
|
144
|
+ break;
|
|
145
|
+ case 30:
|
|
146
|
+ if (0 == strcmp(p, "PropertyIsGreaterThanOrEqualTo"))
|
|
147
|
+ return _PropertyIsGreaterThanOrEqualTo(ptree);
|
|
148
|
+ break;
|
|
149
|
+ default:
|
|
150
|
+ break;
|
|
151
|
+ }
|
|
152
|
+ sql_ += "1=1";
|
|
153
|
+ error_ = "Filter type error: ";
|
|
154
|
+ error_ += p;
|
|
155
|
+ return -17;
|
|
156
|
+ }
|
|
157
|
+
|
|
158
|
+ int DmpWfsFilter::_Or(boost::property_tree::ptree& ptree)
|
|
159
|
+ {
|
|
160
|
+ int nc = 0;
|
|
161
|
+ sql_ += "(";
|
|
162
|
+ for (auto ptchild =ptree.begin(); ptchild != ptree.end(); ++ptchild)
|
|
163
|
+ {
|
|
164
|
+ if (nc)
|
|
165
|
+ {
|
|
166
|
+ sql_ += " or ";
|
|
167
|
+ }
|
|
168
|
+ sql_ += "(";
|
|
169
|
+ int k = _All(ptchild->first, ptchild->second);
|
|
170
|
+ sql_ += ")";
|
|
171
|
+ nc++;
|
|
172
|
+ }
|
|
173
|
+ sql_ += ")";
|
|
174
|
+ return 0;
|
|
175
|
+ }
|
|
176
|
+ int DmpWfsFilter::_Not(boost::property_tree::ptree& ptree)
|
|
177
|
+ {
|
|
178
|
+ sql_ += "not (";
|
|
179
|
+ auto ptchild = ptree.begin();
|
|
180
|
+ // xml_node<char> *node = n->first_node();
|
|
181
|
+ _All(ptchild->first, ptchild->second);
|
|
182
|
+ sql_ += ")";
|
|
183
|
+ return 0;
|
|
184
|
+ }
|
|
185
|
+ int DmpWfsFilter::_And(boost::property_tree::ptree& ptree)
|
|
186
|
+ {
|
|
187
|
+ int nc = 0;
|
|
188
|
+ sql_ += "(";
|
|
189
|
+ for (auto ptchild =ptree.begin(); ptchild != ptree.end(); ++ptchild)
|
|
190
|
+ {
|
|
191
|
+ if (nc)
|
|
192
|
+ {
|
|
193
|
+ sql_ += " and ";
|
|
194
|
+ }
|
|
195
|
+ sql_ += "(";
|
|
196
|
+ int k = _All(ptchild->first, ptchild->second);
|
|
197
|
+ sql_ += ")";
|
|
198
|
+ nc++;
|
|
199
|
+ }
|
|
200
|
+ sql_ += ")";
|
|
201
|
+ return 0;
|
|
202
|
+ }
|
|
203
|
+ int DmpWfsFilter::_BBOX(boost::property_tree::ptree& ptree)
|
|
204
|
+ {
|
|
205
|
+ {
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+ // xml_node<char> *node = n->first_node("PropertyName");
|
|
209
|
+ // if (node == 0)
|
|
210
|
+ // return -1;
|
|
211
|
+ // GetQueryField(propertyName.c_str());
|
|
212
|
+ }
|
|
213
|
+ std::string propertyName = ptree.get<std::string>("PropertyName");
|
|
214
|
+ const char *v = propertyName.c_str();
|
|
215
|
+
|
|
216
|
+ //从FILTER中得到了两个坐标点,构造一个POLYGON?
|
|
217
|
+ double x1, y1, x2, y2;
|
|
218
|
+ int re;
|
|
219
|
+
|
|
220
|
+ boost::property_tree::ptree ptEnvelope = ptree.get_child("Envelope");
|
|
221
|
+ // xml_node<char> *e = n->first_node("Envelope");
|
|
222
|
+ // if (e == 0)
|
|
223
|
+ // e = n->first_node("Box");
|
|
224
|
+ // if (ptEnvelope)
|
|
225
|
+ {
|
|
226
|
+ re = pEnvelope(ptEnvelope, &x1, &y1, &x2, &y2);
|
|
227
|
+ }
|
|
228
|
+ // else
|
|
229
|
+ {
|
|
230
|
+ // re = pEnvelope(n, &x1, &y1, &x2, &y2);
|
|
231
|
+ }
|
|
232
|
+ if (re)
|
|
233
|
+ return -1;
|
|
234
|
+
|
|
235
|
+ // the_geom && 'BOX3D(90900 190900, 100100 200100)'::box3d
|
|
236
|
+ char s[1000];
|
|
237
|
+ std::string ss;
|
|
238
|
+ // ConnClassAll::GetBBox(x1, y1, x2, y2, fieldTemp, (char *)srs.c_str(), this->DatabaseType, ss);
|
|
239
|
+ sql_ += ss;
|
|
240
|
+ return 0;
|
|
241
|
+ }
|
|
242
|
+ int DmpWfsFilter::_Equals(boost::property_tree::ptree& ptree)
|
|
243
|
+ {
|
|
244
|
+ return pGeometrySql("st_equals", "EQUAL", 0, ptree, false); //得到了一条SQL语句
|
|
245
|
+ }
|
|
246
|
+ int DmpWfsFilter::_Beyond(boost::property_tree::ptree& ptree)
|
|
247
|
+ {
|
|
248
|
+ return pGeometrySql("st_disjoint", "DISJOINT", 1, ptree, true);
|
|
249
|
+ }
|
|
250
|
+ int DmpWfsFilter::_Within(boost::property_tree::ptree& ptree)
|
|
251
|
+ {
|
|
252
|
+ return pGeometrySql("st_within", "INSIDE", 0, ptree, false);
|
|
253
|
+ }
|
|
254
|
+ int DmpWfsFilter::_Crosses(boost::property_tree::ptree& ptree)
|
|
255
|
+ {
|
|
256
|
+ return pGeometrySql("st_crosses", "ANYINTERACT", 0, ptree, false);
|
|
257
|
+ }
|
|
258
|
+ int DmpWfsFilter::_Touches(boost::property_tree::ptree& ptree)
|
|
259
|
+ {
|
|
260
|
+ return pGeometrySql("st_touches", "TOUCH", 0, ptree, false);
|
|
261
|
+ }
|
|
262
|
+ int DmpWfsFilter::_DWithin(boost::property_tree::ptree& ptree)
|
|
263
|
+ {
|
|
264
|
+ return pGeometrySql("ST_DWithin", "INSIDE", 0, ptree, true);
|
|
265
|
+ }
|
|
266
|
+ int DmpWfsFilter::_Contains(boost::property_tree::ptree& ptree)
|
|
267
|
+ {
|
|
268
|
+ return pGeometrySql("st_contains", "CONTAINS", 0, ptree, false);
|
|
269
|
+ }
|
|
270
|
+ int DmpWfsFilter::_Overlaps(boost::property_tree::ptree& ptree)
|
|
271
|
+ {
|
|
272
|
+ return pGeometrySql("st_overlaps", "OVERLAPBDYDISJOINT+OVERLAPBDYINTERSECT", 0, ptree, false);
|
|
273
|
+ }
|
|
274
|
+ int DmpWfsFilter::_Disjoint(boost::property_tree::ptree& ptree)
|
|
275
|
+ {
|
|
276
|
+ return pGeometrySql("st_disjoint", "DISJOINT", 1, ptree, false);
|
|
277
|
+ }
|
|
278
|
+ int DmpWfsFilter::_FeatureId(boost::property_tree::ptree& ptree)
|
|
279
|
+ {
|
|
280
|
+ std::string str = ptree.get<std::string>("<xmlattr>.fid");
|
|
281
|
+ /* xml_attribute<char> *a = n->first_attribute("fid");
|
|
282
|
+ if (a == 0)
|
|
283
|
+ {
|
|
284
|
+ a = n->first_attribute("rid");
|
|
285
|
+ }
|
|
286
|
+ if (a)
|
|
287
|
+ {
|
|
288
|
+ std::string s = a->value();
|
|
289
|
+ int at = s.find(".");
|
|
290
|
+ if (at != string::npos)
|
|
291
|
+ s = s.substr(at + 1);
|
|
292
|
+ sql = sql + initConfig.GetGID(DatabaseType) + "='" + s + "'";
|
|
293
|
+ }*///
|
|
294
|
+ //<FeatureId fid=\"TREESA_1M.9012\"/> \
|
|
295
|
+
|
|
296
|
+ return 0;
|
|
297
|
+ }
|
|
298
|
+ int DmpWfsFilter::_Intersects(boost::property_tree::ptree& ptree)
|
|
299
|
+ {
|
|
300
|
+ //return pGeometrySql("st_intersection","ANYINTERACT",0,n,false);
|
|
301
|
+ return pGeometrySql("ST_Intersects", "ANYINTERACT", 0, ptree, false);
|
|
302
|
+ }
|
|
303
|
+
|
|
304
|
+ int DmpWfsFilter::_DIntersects(boost::property_tree::ptree& ptree)
|
|
305
|
+ {
|
|
306
|
+ //return pGeometrySql("st_intersection","ANYINTERACT",0,n,true);
|
|
307
|
+ return pGeometrySql("ST_Intersects", "ANYINTERACT", 0, ptree, true);
|
|
308
|
+ }
|
|
309
|
+
|
|
310
|
+ int DmpWfsFilter::_GmlObjectId(boost::property_tree::ptree& ptree)
|
|
311
|
+ {
|
|
312
|
+ return 0;
|
|
313
|
+ }
|
|
314
|
+ int DmpWfsFilter::_PropertyIsLike(boost::property_tree::ptree& ptree)
|
|
315
|
+ {
|
|
316
|
+ char wildCard = '*';
|
|
317
|
+ char singleCard = '.';
|
|
318
|
+ char escapeCard = '!';
|
|
319
|
+ //首先取得用户指定的通配符,并进行适当的转换
|
|
320
|
+ /* xml_attribute<char> *attrWildCard = n->first_attribute("wildCard");
|
|
321
|
+ xml_attribute<char> *attrSingleCard = n->first_attribute("singleChar");
|
|
322
|
+ xml_attribute<char> *attrEscapeCard = n->first_attribute("escape");
|
|
323
|
+ if (attrWildCard)
|
|
324
|
+ wildCard = ((char *)attrWildCard->value())[0];
|
|
325
|
+ if (attrSingleCard)
|
|
326
|
+ singleCard = ((char *)attrSingleCard->value())[0];
|
|
327
|
+ if (attrEscapeCard)
|
|
328
|
+ escapeCard = ((char *)attrEscapeCard->value())[0];
|
|
329
|
+
|
|
330
|
+ xml_node<char> *node = n->first_node2("ValueReference", "PropertyName");
|
|
331
|
+ if (node == 0)
|
|
332
|
+ return Error(-15, "no enough expression");
|
|
333
|
+ _AppendProperty(sql, node->value());
|
|
334
|
+ if (DatabaseTypePostgreSQL == this->DatabaseType)
|
|
335
|
+ {
|
|
336
|
+ sql = sql + "::varchar";
|
|
337
|
+ }
|
|
338
|
+ sql_ += " LIKE ";
|
|
339
|
+ node = n->first_node("Literal");
|
|
340
|
+ if (node == 0)
|
|
341
|
+ return Error(-15, "no Literal expression");
|
|
342
|
+ char *valueTem = node->value();
|
|
343
|
+ DmapDll::StringHelp::ReplaceWildCards(valueTem, wildCard, singleCard, escapeCard);
|
|
344
|
+ sql_ += "'";
|
|
345
|
+ sql_ += valueTem;
|
|
346
|
+ sql_ += "'";
|
|
347
|
+ if (escapeCard != '!')
|
|
348
|
+ {
|
|
349
|
+ sql_ += " ESCAPE ";
|
|
350
|
+ sql_ += "'";
|
|
351
|
+ sql_ += escapeCard;
|
|
352
|
+ sql_ += "'";
|
|
353
|
+ }*///
|
|
354
|
+
|
|
355
|
+ return 0;
|
|
356
|
+ //return _PropertyOneEqual(n," like",1);
|
|
357
|
+ }
|
|
358
|
+ int DmpWfsFilter::_PropertyIsNull(boost::property_tree::ptree& ptree)
|
|
359
|
+ {
|
|
360
|
+ int isExpression;
|
|
361
|
+ for (auto ptchild =ptree.begin(); ptchild != ptree.end(); ++ptchild)
|
|
362
|
+ {
|
|
363
|
+ int r = _PropertyParse(node, isExpression);
|
|
364
|
+ if (r)
|
|
365
|
+ return r;
|
|
366
|
+ if (isExpression)
|
|
367
|
+ {
|
|
368
|
+ sql_ += " is null";
|
|
369
|
+ }
|
|
370
|
+ return 0;
|
|
371
|
+ }
|
|
372
|
+ return Error(-24, "_PropertyIsNull node missing");
|
|
373
|
+ }
|
|
374
|
+
|
|
375
|
+ int DmpWfsFilter::_PropertyIsBetween(boost::property_tree::ptree& ptree)
|
|
376
|
+ {
|
|
377
|
+ int isExpression, nc = 0;
|
|
378
|
+ //sql+="(";
|
|
379
|
+ for (auto ptchild =ptree.begin(); ptchild != ptree.end(); ++ptchild)
|
|
380
|
+ {
|
|
381
|
+ int r = _PropertyParse(node, isExpression);
|
|
382
|
+ if (r)
|
|
383
|
+ return r;
|
|
384
|
+ if (isExpression)
|
|
385
|
+ {
|
|
386
|
+ nc++;
|
|
387
|
+ break;
|
|
388
|
+ }
|
|
389
|
+ }
|
|
390
|
+ if (nc == 0)
|
|
391
|
+ return Error(-23, "no Property node");
|
|
392
|
+
|
|
393
|
+ sql_ += " between ";
|
|
394
|
+ {
|
|
395
|
+ xml_node<char> *node = n->first_node("LowerBoundary");
|
|
396
|
+ if (node == 0 || node->first_node() == 0)
|
|
397
|
+ return Error(-22, "no LowerBoundary node");
|
|
398
|
+ _PropertyParse(node->first_node(), isExpression);
|
|
399
|
+ }
|
|
400
|
+ sql_ += " and ";
|
|
401
|
+ {
|
|
402
|
+ xml_node<char> *node = n->first_node("UpperBoundary");
|
|
403
|
+ if (node == 0 || node->first_node() == 0)
|
|
404
|
+ return Error(-24, "no UpperBoundary node");
|
|
405
|
+ int isExpression;
|
|
406
|
+ _PropertyParse(node->first_node(), isExpression);
|
|
407
|
+ }
|
|
408
|
+ //sql+=")";
|
|
409
|
+ return 0;
|
|
410
|
+ }
|
|
411
|
+ int DmpWfsFilter::_PropertyOneEqual(boost::property_tree::ptree& ptree, char *type, int isLike)
|
|
412
|
+ {
|
|
413
|
+ int nc = 0, isExpression;
|
|
414
|
+ for (auto ptchild =ptree.begin(); ptchild != ptree.end(); ++ptchild)
|
|
415
|
+ {
|
|
416
|
+ int r = _PropertyParse(ptchild->first,ptchild->second, isExpression, isLike); //这里IsLike设定的值是1
|
|
417
|
+ if (r)
|
|
418
|
+ return r;
|
|
419
|
+ if (isExpression)
|
|
420
|
+ {
|
|
421
|
+ if (nc == 0)
|
|
422
|
+ {
|
|
423
|
+ sql_ += type;
|
|
424
|
+ }
|
|
425
|
+ nc++;
|
|
426
|
+ if (nc == 2)
|
|
427
|
+ return 0;
|
|
428
|
+ }
|
|
429
|
+ }
|
|
430
|
+ if (nc < 2)
|
|
431
|
+ return Error(-19, "no enough expression");
|
|
432
|
+ return 0;
|
|
433
|
+ }
|
|
434
|
+ int DmpWfsFilter::_PropertyIsEqualTo(boost::property_tree::ptree& ptree)
|
|
435
|
+ {
|
|
436
|
+ return _PropertyOneEqual(ptree, "=");
|
|
437
|
+ }
|
|
438
|
+ int DmpWfsFilter::_PropertyParse4(boost::property_tree::ptree& ptree, char *f)
|
|
439
|
+ {
|
|
440
|
+ int nc = 0, isExpression;
|
|
441
|
+ sql_ += "(";
|
|
442
|
+ for (auto ptchild =ptree.begin(); ptchild != ptree.end(); ++ptchild)
|
|
443
|
+ {
|
|
444
|
+ int r = _PropertyParse(ptchild->first, ptchild->second, isExpression);
|
|
445
|
+ if (r)
|
|
446
|
+ return r;
|
|
447
|
+ if (isExpression)
|
|
448
|
+ {
|
|
449
|
+ if (nc == 0)
|
|
450
|
+ {
|
|
451
|
+ sql_ += f;
|
|
452
|
+ }
|
|
453
|
+ nc++;
|
|
454
|
+ if (nc == 2)
|
|
455
|
+ {
|
|
456
|
+ sql_ += ")";
|
|
457
|
+ return 0;
|
|
458
|
+ }
|
|
459
|
+ }
|
|
460
|
+ }
|
|
461
|
+ if (nc < 2)
|
|
462
|
+ return Error(-19, "no enough expression");
|
|
463
|
+
|
|
464
|
+ return 0;
|
|
465
|
+ }
|
|
466
|
+ int DmpWfsFilter::_PropertyParseFunction(boost::property_tree::ptree& ptree)
|
|
467
|
+ {
|
|
468
|
+ {
|
|
469
|
+ xml_attribute<char> *nameNode = n->first_attribute("name");
|
|
470
|
+ if (nameNode == 0)
|
|
471
|
+ return Error(-20, "no function name node");
|
|
472
|
+ char *a = nameNode->value();
|
|
473
|
+ if (a == 0)
|
|
474
|
+ return Error(-21, "no function name");
|
|
475
|
+ sql_ += a;
|
|
476
|
+ }
|
|
477
|
+
|
|
478
|
+ int isExpression;
|
|
479
|
+ sql_ += "(";
|
|
480
|
+ for (auto ptchild =ptree.begin(); ptchild != ptree.end(); ++ptchild)
|
|
481
|
+ {
|
|
482
|
+ int r = _PropertyParse(ptchild->first, ptchild->second, isExpression);
|
|
483
|
+ if (r)
|
|
484
|
+ return r;
|
|
485
|
+ if (isExpression)
|
|
486
|
+ {
|
|
487
|
+ sql_ += ",";
|
|
488
|
+ }
|
|
489
|
+ }
|
|
490
|
+
|
|
491
|
+ sql[sql.size() - 1] = ')';
|
|
492
|
+ //sql+=")";
|
|
493
|
+ return 0;
|
|
494
|
+ }
|
|
495
|
+ void DmpWfsFilter::_AppendProperty(std::string &sql, const char *str)
|
|
496
|
+ {
|
|
497
|
+ //sql_ += "\"";
|
|
498
|
+ sql_ += str;
|
|
499
|
+ //sql_ += "\"";
|
|
500
|
+ }
|
|
501
|
+
|
|
502
|
+ //<fes:Filter
|
|
503
|
+ //xmlns:fes="http://www.opengis.net/fes/2.0"
|
|
504
|
+ //xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
505
|
+ //xsi:schemaLocation="http://www.opengis.net/fes/2.0
|
|
506
|
+ //http://schemas.opengis.net/filter/2.0.0/filterAll.xsd">
|
|
507
|
+ //<fes:PropertyIsLike wildCard="*" singleChar="#" escapeChar="!">
|
|
508
|
+ //<fes:ValueReference>LAST_NAME</fes:ValueReference>
|
|
509
|
+ //<fes:Literal>JOHN*</fes:Literal>
|
|
510
|
+ //</fes:PropertyIsLike>
|
|
511
|
+ //</fes:Filter>
|
|
512
|
+
|
|
513
|
+ //我感觉这里应该有一个通配符的转换
|
|
514
|
+ int DmpWfsFilter::_PropertyParse(const std::string& ptreeName, boost::property_tree::ptree& ptree, int &isExpression, int isLike)
|
|
515
|
+ {
|
|
516
|
+
|
|
517
|
+ isExpression = 0;
|
|
518
|
+ string name = this->GetFieldName(ptreeName);
|
|
519
|
+ const char *p = name.c_str();
|
|
520
|
+ if (p == 0 || p[0] == 0)
|
|
521
|
+ {
|
|
522
|
+ sql_ += "('";
|
|
523
|
+ sql_ += n->value();
|
|
524
|
+ sql_ += "')";
|
|
525
|
+ return 0;
|
|
526
|
+ }
|
|
527
|
+ if (0 == strcmp(p, "Literal"))
|
|
528
|
+ {
|
|
529
|
+ isExpression = 1;
|
|
530
|
+ if (isLike)
|
|
531
|
+ {
|
|
532
|
+ sql_ += "('%";
|
|
533
|
+ sql_ += n->value();
|
|
534
|
+ sql_ += "%')";
|
|
535
|
+ }
|
|
536
|
+ else
|
|
537
|
+ {
|
|
538
|
+ sql_ += "('";
|
|
539
|
+ sql_ += n->value();
|
|
540
|
+ sql_ += "')";
|
|
541
|
+ }
|
|
542
|
+ return 0;
|
|
543
|
+ }
|
|
544
|
+ if (0 == strcmp(p, "PropertyName") || 0 == strcmp(p, "ValueReference"))
|
|
545
|
+ {
|
|
546
|
+ isExpression = 1;
|
|
547
|
+ //std::string s=n->value();
|
|
548
|
+ //s=this->td->GetFieldQuery(s);
|
|
549
|
+ _AppendProperty(sql, n->value()); //添加了一个字段?
|
|
550
|
+
|
|
551
|
+ sql = sql + "::varchar";
|
|
552
|
+ //sql+=n->value();
|
|
553
|
+ return 0;
|
|
554
|
+ }
|
|
555
|
+ if (0 == strcmp(p, "Add"))
|
|
556
|
+ {
|
|
557
|
+ isExpression = 1;
|
|
558
|
+ return _PropertyParse4(ptree, "+");
|
|
559
|
+ }
|
|
560
|
+ if (0 == strcmp(p, "Sub"))
|
|
561
|
+ {
|
|
562
|
+ isExpression = 1;
|
|
563
|
+ return _PropertyParse4(ptree, "-");
|
|
564
|
+ }
|
|
565
|
+ if (0 == strcmp(p, "Mul"))
|
|
566
|
+ {
|
|
567
|
+ isExpression = 1;
|
|
568
|
+ return _PropertyParse4(ptree, "*");
|
|
569
|
+ }
|
|
570
|
+ if (0 == strcmp(p, "Div"))
|
|
571
|
+ {
|
|
572
|
+ isExpression = 1;
|
|
573
|
+ return _PropertyParse4(ptree, "/");
|
|
574
|
+ }
|
|
575
|
+ if (0 == strcmp(p, "Function"))
|
|
576
|
+ {
|
|
577
|
+ isExpression = 1;
|
|
578
|
+ return _PropertyParseFunction(ptree);
|
|
579
|
+ }
|
|
580
|
+ return 0;
|
|
581
|
+ }
|
|
582
|
+ int DmpWfsFilter::_PropertyIsLessThan(boost::property_tree::ptree& ptree)
|
|
583
|
+ {
|
|
584
|
+ return _PropertyOneEqual(ptree, "<");
|
|
585
|
+ }
|
|
586
|
+ int DmpWfsFilter::_PropertyIsNotEqualTo(boost::property_tree::ptree& ptree)
|
|
587
|
+ {
|
|
588
|
+ return _PropertyOneEqual(ptree, "<>");
|
|
589
|
+ }
|
|
590
|
+ int DmpWfsFilter::_PropertyIsGreaterThan(boost::property_tree::ptree& ptree)
|
|
591
|
+ {
|
|
592
|
+ return _PropertyOneEqual(ptree, ">");
|
|
593
|
+ }
|
|
594
|
+ int DmpWfsFilter::_PropertyIsLessThanOrEqualTo(boost::property_tree::ptree& ptree)
|
|
595
|
+ {
|
|
596
|
+ return _PropertyOneEqual(ptree, "<=");
|
|
597
|
+ }
|
|
598
|
+ int DmpWfsFilter::_PropertyIsGreaterThanOrEqualTo(boost::property_tree::ptree& ptree)
|
|
599
|
+ {
|
|
600
|
+ return _PropertyOneEqual(ptree, ">=");
|
|
601
|
+ }
|
|
602
|
+
|
|
603
|
+ void DmpWfsFilter::pParsesrsName(boost::property_tree::ptree& ptree)
|
|
604
|
+ {
|
|
605
|
+ xml_attribute<char> *sr = n->first_attribute("srsName");
|
|
606
|
+ if (sr)
|
|
607
|
+ {
|
|
608
|
+ char *s = _strdup(sr->value());
|
|
609
|
+ clsMalloc m(s);
|
|
610
|
+ if (s == 0 || s[0] == 0)
|
|
611
|
+ return;
|
|
612
|
+ char *ss[10];
|
|
613
|
+ int n = DmapDll::StringHelp::ParseStringTok(s, '#', ss, 10);
|
|
614
|
+ char *sa = ss[n - 1];
|
|
615
|
+ int len = strlen(sa);
|
|
616
|
+ for (int i = 0; i < len; i++)
|
|
617
|
+ {
|
|
618
|
+ if (sa[i] == '_')
|
|
619
|
+ sa[i] = ':';
|
|
620
|
+ }
|
|
621
|
+ n = DmapDll::StringHelp::ParseStringTok(sa, ':', ss, 10);
|
|
622
|
+ //parse epsg:5432
|
|
623
|
+ sa = ss[n - 1];
|
|
624
|
+ strcpy_s((char *)srs.c_str(), sa);
|
|
625
|
+ }
|
|
626
|
+ }
|
|
627
|
+ int DmpWfsFilter::pEnvelope(boost::property_tree::ptree& ptree, double *x1, double *y1, double *x2, double *y2)
|
|
628
|
+ {
|
|
629
|
+ xml_node<char> *node = n->first_node("lowerCorner"); //,"ogc:PropertyName");
|
|
630
|
+ if (node)
|
|
631
|
+ {
|
|
632
|
+ xml_node<char> *node1 = n->first_node("upperCorner"); //,"ogc:PropertyName");
|
|
633
|
+ if (!node1)
|
|
634
|
+ return this->Error(-2, "upperCorner missing");
|
|
635
|
+ sscanf(node->value(), "%lf %lf", x1, y1);
|
|
636
|
+ sscanf(node1->value(), "%lf %lf", x2, y2);
|
|
637
|
+ return 0;
|
|
638
|
+ }
|
|
639
|
+ else
|
|
640
|
+ {
|
|
641
|
+ std::vector<double> v;
|
|
642
|
+ int rt = pGeometryPointArray(n, v);
|
|
643
|
+ if (rt)
|
|
644
|
+ return rt;
|
|
645
|
+ if (v.size() < 4)
|
|
646
|
+ return Error(-16231, "point array too small");
|
|
647
|
+
|
|
648
|
+ //这里不太好吧,只要有个不合法的请求就会死掉
|
|
649
|
+ *x1 = v[0];
|
|
650
|
+ *y1 = v[1];
|
|
651
|
+ *x2 = v[2];
|
|
652
|
+ *y2 = v[3];
|
|
653
|
+ return 0;
|
|
654
|
+ }
|
|
655
|
+ //==0)return -1;
|
|
656
|
+ //char *v=node->value();
|
|
657
|
+
|
|
658
|
+ return Error(-4214, "envope parse error");
|
|
659
|
+ }
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+ //这个函数是对数字进行解析(前到空格去掉,后面的空格可以作为结束标志。。。)
|
|
664
|
+ int DmpWfsFilter::pGeometryDouble(char *d, bool space_before, bool space_after, double &dbl)
|
|
665
|
+ {
|
|
666
|
+ char *p;
|
|
667
|
+ int st;
|
|
668
|
+ enum states //用来维护状态
|
|
669
|
+ {
|
|
670
|
+ INIT = 0,
|
|
671
|
+ NEED_DIG = 1,
|
|
672
|
+ DIG = 2,
|
|
673
|
+ NEED_DIG_DEC = 3,
|
|
674
|
+ DIG_DEC = 4,
|
|
675
|
+ EXP = 5,
|
|
676
|
+ NEED_DIG_EXP = 6,
|
|
677
|
+ DIG_EXP = 7,
|
|
678
|
+ END = 8
|
|
679
|
+ };
|
|
680
|
+
|
|
681
|
+ //下面这段代码主要是进行了所传数字有效性的验证吧?
|
|
682
|
+ if (space_before)
|
|
683
|
+ while (isspace(*d))
|
|
684
|
+ d++; //再次的消除空格
|
|
685
|
+ for (st = INIT, p = d; *p; p++)
|
|
686
|
+ {
|
|
687
|
+
|
|
688
|
+ if (isdigit(*p))
|
|
689
|
+ {
|
|
690
|
+ if (st == INIT || st == NEED_DIG)
|
|
691
|
+ st = DIG; //刚开始或者是期望是数字,转换为是数字
|
|
692
|
+ else if (st == NEED_DIG_DEC)
|
|
693
|
+ st = DIG_DEC; //期望是小数,转化为时小数
|
|
694
|
+ else if (st == NEED_DIG_EXP || st == EXP)
|
|
695
|
+ st = DIG_EXP; //已经是一个科学计数法,或者期望是一个科学计数法
|
|
696
|
+ else if (st == DIG || st == DIG_DEC || st == DIG_EXP)
|
|
697
|
+ ; //已经是数字,小数,科学计数法,则不做转换
|
|
698
|
+ else
|
|
699
|
+ return Error(-4, "invalid digital");
|
|
700
|
+ }
|
|
701
|
+ else if (*p == '.')
|
|
702
|
+ {
|
|
703
|
+ if (st == DIG)
|
|
704
|
+ st = NEED_DIG_DEC; //从数字转换到期望是小数的状态(否则出错)
|
|
705
|
+ else
|
|
706
|
+ return Error(-4, "invalid digital");
|
|
707
|
+ }
|
|
708
|
+ else if (*p == '-' || *p == '+')
|
|
709
|
+ {
|
|
710
|
+ if (st == INIT)
|
|
711
|
+ st = NEED_DIG;
|
|
712
|
+ else if (st == EXP)
|
|
713
|
+ st = NEED_DIG_EXP;
|
|
714
|
+ else
|
|
715
|
+ return Error(-4, "invalid digital");
|
|
716
|
+ }
|
|
717
|
+ else if (*p == 'e' || *p == 'E') //科学计数法
|
|
718
|
+ {
|
|
719
|
+ if (st == DIG || st == DIG_DEC)
|
|
720
|
+ st = EXP;
|
|
721
|
+ else
|
|
722
|
+ return Error(-4, "invalid digital");
|
|
723
|
+ }
|
|
724
|
+ else if (isspace(*p))
|
|
725
|
+ {
|
|
726
|
+ if (!space_after)
|
|
727
|
+ return Error(-4, "invalid digital");
|
|
728
|
+ if (st == DIG || st == DIG_DEC || st == DIG_EXP)
|
|
729
|
+ st = END;
|
|
730
|
+ else if (st == NEED_DIG_DEC)
|
|
731
|
+ st = END;
|
|
732
|
+ else if (st == END)
|
|
733
|
+ ;
|
|
734
|
+ else
|
|
735
|
+ return Error(-4, "invalid digital");
|
|
736
|
+ }
|
|
737
|
+ else
|
|
738
|
+ return Error(-4, "invalid digital");
|
|
739
|
+ }
|
|
740
|
+
|
|
741
|
+ if (st != DIG && st != NEED_DIG_DEC && st != DIG_DEC && st != DIG_EXP && st != END)
|
|
742
|
+ return Error(-4, "invalid digital");
|
|
743
|
+ dbl = atof(d);
|
|
744
|
+ return 0;
|
|
745
|
+ }
|
|
746
|
+
|
|
747
|
+ //这个函数写的很棒啊。。。
|
|
748
|
+ int DmpWfsFilter::pGeometryPointValuePos(char *pos, std::vector<double> &v)
|
|
749
|
+ {
|
|
750
|
+ while (isspace(*pos))
|
|
751
|
+ pos++; /* Eat extra whitespaces if any */ //跳过空格
|
|
752
|
+ /* gml:pos pattern: x1 y1
|
|
753
|
+ * x1 y1 z1
|
|
754
|
+ */
|
|
755
|
+ int gml_dim = 0;
|
|
756
|
+ bool digit = false;
|
|
757
|
+ double dbl;
|
|
758
|
+ for (char *p = pos; *pos; pos++)
|
|
759
|
+ {
|
|
760
|
+ if (isdigit(*pos))
|
|
761
|
+ digit = true;
|
|
762
|
+ if (digit && (*pos == ' ' || *(pos + 1) == '\0'))
|
|
763
|
+ {
|
|
764
|
+ if (*pos == ' ')
|
|
765
|
+ *pos = '\0';
|
|
766
|
+ gml_dim++;
|
|
767
|
+ if (gml_dim == 1)
|
|
768
|
+ {
|
|
769
|
+ int rt = pGeometryDouble(p, true, true, dbl);
|
|
770
|
+ if (rt)
|
|
771
|
+ return rt;
|
|
772
|
+ v.push_back(dbl);
|
|
773
|
+ }
|
|
774
|
+ else if (gml_dim == 2)
|
|
775
|
+ {
|
|
776
|
+ int rt = pGeometryDouble(p, true, true, dbl);
|
|
777
|
+ if (rt)
|
|
778
|
+ return rt;
|
|
779
|
+ v.push_back(dbl);
|
|
780
|
+ }
|
|
781
|
+ else if (gml_dim == 3)
|
|
782
|
+ {
|
|
783
|
+ }
|
|
784
|
+ // pt.z = parse_gml_double(p, true, true);
|
|
785
|
+ p = pos + 1;
|
|
786
|
+ digit = false;
|
|
787
|
+ }
|
|
788
|
+ }
|
|
789
|
+
|
|
790
|
+ return 0;
|
|
791
|
+ }
|
|
792
|
+
|
|
793
|
+ int DmpWfsFilter::pGeometryPointValuePosList(boost::property_tree::ptree& ptree, std::vector<double> &v)
|
|
794
|
+ {
|
|
795
|
+ int dim = 2;
|
|
796
|
+ xml_attribute<char> *pn = n->first_attribute("dimension");
|
|
797
|
+ if (pn)
|
|
798
|
+ {
|
|
799
|
+ dim = atoi(pn->value());
|
|
800
|
+ }
|
|
801
|
+ if (dim > 3 || dim < 2)
|
|
802
|
+ return Error(-6, "dim >3 or dim<2");
|
|
803
|
+ char *poslist = (char *)n->value();
|
|
804
|
+ while (isspace(*poslist))
|
|
805
|
+ poslist++;
|
|
806
|
+ double dbl;
|
|
807
|
+ int gml_dim = 0; //跳过空格
|
|
808
|
+ for (char *p = poslist, digit = false; *poslist; poslist++)
|
|
809
|
+ {
|
|
810
|
+ if (isdigit(*poslist))
|
|
811
|
+ digit = true;
|
|
812
|
+ //以空格分割
|
|
813
|
+ if (digit && (*poslist == ' ' || *(poslist + 1) == '\0'))
|
|
814
|
+ {
|
|
815
|
+ if (*poslist == ' ')
|
|
816
|
+ *poslist = '\0';
|
|
817
|
+
|
|
818
|
+ gml_dim++;
|
|
819
|
+ if (gml_dim == 1)
|
|
820
|
+ {
|
|
821
|
+ int rt = pGeometryDouble(p, true, true, dbl);
|
|
822
|
+ if (rt)
|
|
823
|
+ return rt;
|
|
824
|
+ v.push_back(dbl);
|
|
825
|
+ }
|
|
826
|
+ else if (gml_dim == 2)
|
|
827
|
+ {
|
|
828
|
+ int rt = pGeometryDouble(p, true, true, dbl);
|
|
829
|
+ if (rt)
|
|
830
|
+ return rt;
|
|
831
|
+ v.push_back(dbl);
|
|
832
|
+ }
|
|
833
|
+ //else if (gml_dim == 3) pt.z = parse_gml_double(p, true, true);
|
|
834
|
+
|
|
835
|
+ if (gml_dim == dim)
|
|
836
|
+ {
|
|
837
|
+ gml_dim = 0;
|
|
838
|
+ }
|
|
839
|
+ else if (*(poslist + 1) == '\0')
|
|
840
|
+ {
|
|
841
|
+ return Error(-7, "char missing");
|
|
842
|
+ }
|
|
843
|
+
|
|
844
|
+ p = poslist + 1;
|
|
845
|
+ digit = false;
|
|
846
|
+ }
|
|
847
|
+ }
|
|
848
|
+ return 0;
|
|
849
|
+ }
|
|
850
|
+
|
|
851
|
+ int DmpWfsFilter::pGeometryGetDis(boost::property_tree::ptree& ptree, double &dis)
|
|
852
|
+ {
|
|
853
|
+ //<Distance unit=\"a#meters\">10</Distance> \
|
|
854
|
+
|
|
855
|
+ double ratio = 1;
|
|
856
|
+ {
|
|
857
|
+ rapidxml::xml_attribute<char> *t = n->first_attribute("unit");
|
|
858
|
+ if (t)
|
|
859
|
+ {
|
|
860
|
+ char *p = t->value();
|
|
861
|
+ size_t size = strlen(p);
|
|
862
|
+ int found = 0;
|
|
863
|
+ for (size_t i = size - 1; i >= 0; i--)
|
|
864
|
+ {
|
|
865
|
+ if (p[i] == '#')
|
|
866
|
+ {
|
|
867
|
+ found = 1;
|
|
868
|
+ p += i + 1;
|
|
869
|
+ break;
|
|
870
|
+ }
|
|
871
|
+ }
|
|
872
|
+ if (strcmp(p, "kilometers") == 0)
|
|
873
|
+ {
|
|
874
|
+ ratio = 1000;
|
|
875
|
+ }
|
|
876
|
+ else if (strcmp(p, "kilometer") == 0)
|
|
877
|
+ {
|
|
878
|
+ ratio = 1000;
|
|
879
|
+ }
|
|
880
|
+ }
|
|
881
|
+ }
|
|
882
|
+
|
|
883
|
+ double f = atof(n->value());
|
|
884
|
+ f = f * ratio;
|
|
885
|
+
|
|
886
|
+ dis = f;
|
|
887
|
+ // rapidxml::xml_node<char> * t=n->first_node("X");
|
|
888
|
+
|
|
889
|
+ return 0;
|
|
890
|
+ }
|
|
891
|
+
|
|
892
|
+ /* void DmpWfsFilter::GetQueryField(const char *field)
|
|
893
|
+ {
|
|
894
|
+ if (td)
|
|
895
|
+ {
|
|
896
|
+ fieldTemp = td->GetFieldQuery(field);
|
|
897
|
+ }
|
|
898
|
+ else
|
|
899
|
+ {
|
|
900
|
+ fieldTemp = field;
|
|
901
|
+ }
|
|
902
|
+ }*/
|
|
903
|
+
|
|
904
|
+ int DmpWfsFilter::Error(int code, const char *err)
|
|
905
|
+ {
|
|
906
|
+ error_ = err;
|
|
907
|
+ errorCode_ = code;
|
|
908
|
+ return code;
|
|
909
|
+ }
|
|
910
|
+
|
|
911
|
+ int DmpWfsFilter::pGeometrySql(char *function, char *oracle_mask, int isDisjoin, xml_node<char> *n, bool useBuffer)
|
|
912
|
+ {
|
|
913
|
+ {
|
|
914
|
+ xml_node<char> *nodeP = n->first_node2("PropertyName", "ValueReference"); //,"ogc:PropertyName");
|
|
915
|
+ if (nodeP == 0 || nodeP->value()[0] == 0)
|
|
916
|
+ return Error(-15, "no PropertyName node");
|
|
917
|
+ GetQueryField(nodeP->value());
|
|
918
|
+ }
|
|
919
|
+ double dis;
|
|
920
|
+ if (useBuffer)
|
|
921
|
+ {
|
|
922
|
+ xml_node<char> *nodeD = n->first_node("Distance"); //,"ogc:PropertyName");
|
|
923
|
+ if (nodeD == 0)
|
|
924
|
+ return Error(-15, "no Distance node");
|
|
925
|
+ int rt = pGeometryGetDis(nodeD, dis);
|
|
926
|
+ if (rt)
|
|
927
|
+ return Error(-15, "no Distance node");
|
|
928
|
+ }
|
|
929
|
+
|
|
930
|
+ std::string strOut;
|
|
931
|
+ double x1, y1, x2, y2;
|
|
932
|
+ int ee = GetGeomFromGml(n, strOut, x1, y1, x2, y2);
|
|
933
|
+ if (ee)
|
|
934
|
+ return Error(ee, "gml parse error");
|
|
935
|
+ if (useBuffer)
|
|
936
|
+ {
|
|
937
|
+ x1 -= dis;
|
|
938
|
+ y1 -= dis;
|
|
939
|
+ x2 += dis;
|
|
940
|
+ y2 += dis;
|
|
941
|
+ }
|
|
942
|
+
|
|
943
|
+ if (useBuffer)
|
|
944
|
+ {
|
|
945
|
+ if (strcmp(function, "ST_DWithin") == 0)
|
|
946
|
+ {
|
|
947
|
+ char sz[200];
|
|
948
|
+ sprintf(sz, "%lf", dis);
|
|
949
|
+ std::string s = strOut + ",";
|
|
950
|
+ s += sz;
|
|
951
|
+ strOut = s;
|
|
952
|
+ }
|
|
953
|
+ else
|
|
954
|
+ {
|
|
955
|
+ if (_stricmp(function, "st_intersection") == 0)
|
|
956
|
+ {
|
|
957
|
+ function = "st_intersects";
|
|
958
|
+ }
|
|
959
|
+
|
|
960
|
+ char sz[200];
|
|
961
|
+ sprintf(sz, "%lf", dis);
|
|
962
|
+ std::string s = "st_buffer(";
|
|
963
|
+ s = s + strOut;
|
|
964
|
+ s = s + ",";
|
|
965
|
+ s = s + sz;
|
|
966
|
+ s = s + ")";
|
|
967
|
+ strOut = s;
|
|
968
|
+ }
|
|
969
|
+ }
|
|
970
|
+ sql_ += function;
|
|
971
|
+ sql_ += "(";
|
|
972
|
+ {
|
|
973
|
+ std::string nameOut;
|
|
974
|
+ ConnClassAll::GetSRIDName(fieldTemp, nameOut, (char *)srs.c_str(), this->DatabaseType);
|
|
975
|
+ sql_ += nameOut;
|
|
976
|
+ }
|
|
977
|
+ sql_ += ",";
|
|
978
|
+ sql_ += strOut;
|
|
979
|
+ sql_ += ")";
|
|
980
|
+
|
|
981
|
+ return 0;
|
|
982
|
+ }
|
|
983
|
+ int DmpWfsFilter::pGeometryPointValueCoord(boost::property_tree::ptree& ptree, std::vector<double> &v)
|
|
984
|
+ {
|
|
985
|
+ double x, y;
|
|
986
|
+ rapidxml::xml_node<char> *t = n->first_node("X");
|
|
987
|
+ if (t == 0)
|
|
988
|
+ return Error(-9, "X node not found");
|
|
989
|
+ x = atof(t->value());
|
|
990
|
+ t = n->first_node("Y");
|
|
991
|
+ if (t == 0)
|
|
992
|
+ return Error(-10, "Y node not found");
|
|
993
|
+ y = atof(t->value());
|
|
994
|
+ v.push_back(x);
|
|
995
|
+ v.push_back(y);
|
|
996
|
+ return 0;
|
|
997
|
+ }
|
|
998
|
+ int DmpWfsFilter::pGeometryPointValuePointRep(boost::property_tree::ptree& ptree, std::vector<double> &v)
|
|
999
|
+ {
|
|
1000
|
+ double x, y;
|
|
1001
|
+ rapidxml::xml_node<char> *t = n->first_node("Point");
|
|
1002
|
+ if (t == 0)
|
|
1003
|
+ return Error(-9, "Point node not found");
|
|
1004
|
+ t = t->first_node("pos");
|
|
1005
|
+ if (t == 0)
|
|
1006
|
+ return Error(-9, "pos node not found");
|
|
1007
|
+ char *p = t->value();
|
|
1008
|
+ sscanf(p, "%lf %lf", &x, &y);
|
|
1009
|
+ v.push_back(x);
|
|
1010
|
+ v.push_back(y);
|
|
1011
|
+ return 0;
|
|
1012
|
+ }
|
|
1013
|
+
|
|
1014
|
+ //来看看这个函数
|
|
1015
|
+ int DmpWfsFilter::pGeometryPointValueCoordinates(char *p, std::vector<double> &v)
|
|
1016
|
+ {
|
|
1017
|
+ char cs, ts, dec;
|
|
1018
|
+ cs = ',';
|
|
1019
|
+ ts = ' ';
|
|
1020
|
+ dec = '.';
|
|
1021
|
+ bool digit;
|
|
1022
|
+ int gml_dims;
|
|
1023
|
+ while (isspace(*p))
|
|
1024
|
+ p++;
|
|
1025
|
+ char *q;
|
|
1026
|
+ double dbl; //跳过空格
|
|
1027
|
+ for (q = p, gml_dims = 0, digit = false; *p; p++)
|
|
1028
|
+ {
|
|
1029
|
+ if (isdigit(*p))
|
|
1030
|
+ digit = true;
|
|
1031
|
+ //逗号分割
|
|
1032
|
+ if (*p == cs)
|
|
1033
|
+ {
|
|
1034
|
+ *p = '\0';
|
|
1035
|
+ gml_dims++;
|
|
1036
|
+
|
|
1037
|
+ if (*(p + 1) == '\0')
|
|
1038
|
+ return Error(-8, "invalid gml");
|
|
1039
|
+
|
|
1040
|
+ if (gml_dims == 1)
|
|
1041
|
+ {
|
|
1042
|
+ int rt = pGeometryDouble(q, false, true, dbl);
|
|
1043
|
+ if (rt)
|
|
1044
|
+ return rt;
|
|
1045
|
+ v.push_back(dbl);
|
|
1046
|
+ }
|
|
1047
|
+ else if (gml_dims == 2)
|
|
1048
|
+ {
|
|
1049
|
+ int rt = pGeometryDouble(q, false, true, dbl);
|
|
1050
|
+ if (rt)
|
|
1051
|
+ return rt;
|
|
1052
|
+ v.push_back(dbl);
|
|
1053
|
+ }
|
|
1054
|
+
|
|
1055
|
+ q = p + 1;
|
|
1056
|
+ }
|
|
1057
|
+ //空格分割...
|
|
1058
|
+ else if (digit && (*p == ts || *(p + 1) == '\0'))
|
|
1059
|
+ {
|
|
1060
|
+ if (*p == ts)
|
|
1061
|
+ *p = '\0';
|
|
1062
|
+ gml_dims++;
|
|
1063
|
+
|
|
1064
|
+ if (gml_dims < 2 || gml_dims > 3)
|
|
1065
|
+ {
|
|
1066
|
+ return Error(-8, "invalid gml");
|
|
1067
|
+ }
|
|
1068
|
+
|
|
1069
|
+ if (gml_dims == 3)
|
|
1070
|
+ {
|
|
1071
|
+ int rt = pGeometryDouble(q, false, true, dbl);
|
|
1072
|
+ if (rt)
|
|
1073
|
+ return rt;
|
|
1074
|
+ }
|
|
1075
|
+ else
|
|
1076
|
+ {
|
|
1077
|
+ int rt = pGeometryDouble(q, false, true, dbl);
|
|
1078
|
+ if (rt)
|
|
1079
|
+ return rt;
|
|
1080
|
+ v.push_back(dbl);
|
|
1081
|
+ //*hasz = false;
|
|
1082
|
+ }
|
|
1083
|
+
|
|
1084
|
+ // dynptarray_addPoint4d(dpa, &pt, 0);
|
|
1085
|
+ digit = false;
|
|
1086
|
+
|
|
1087
|
+ q = p + 1;
|
|
1088
|
+ gml_dims = 0;
|
|
1089
|
+
|
|
1090
|
+ /* Need to put standard decimal separator to atof handle */
|
|
1091
|
+ }
|
|
1092
|
+ else if (*p == dec && dec != '.')
|
|
1093
|
+ *p = '.'; //处理小数
|
|
1094
|
+ }
|
|
1095
|
+ return 0;
|
|
1096
|
+ }
|
|
1097
|
+
|
|
1098
|
+ //得到点数组
|
|
1099
|
+ int DmpWfsFilter::pGeometryPointArray(boost::property_tree::ptree& ptree, std::vector<double> &v)
|
|
1100
|
+ {
|
|
1101
|
+ for (auto ptchild =ptree.begin(); ptchild != ptree.end(); ++ptchild)
|
|
1102
|
+ {
|
|
1103
|
+ if (!strcmp((char *)node->name(), "pos") || !strcmp((char *)node->name(), "gml:pos")) //以空格分割的坐标数据
|
|
1104
|
+ {
|
|
1105
|
+ return pGeometryPointValuePos(node->value(), v);
|
|
1106
|
+ }
|
|
1107
|
+ else if (!strcmp((char *)node->name(), "posList") || !strcmp((char *)node->name(), "gml:posList")) //有维度,以空格分割的坐标数据
|
|
1108
|
+ {
|
|
1109
|
+ return pGeometryPointValuePosList(node, v);
|
|
1110
|
+ }
|
|
1111
|
+ else if (!strcmp((char *)node->name(), "coordinates") || !strcmp((char *)node->name(), "gml:coordinates")) //以空格或者逗号分割的数据
|
|
1112
|
+ {
|
|
1113
|
+ return pGeometryPointValueCoordinates(node->value(), v);
|
|
1114
|
+ }
|
|
1115
|
+ else if (!strcmp((char *)node->name(), "coord") || !strcmp((char *)node->name(), "gml:coord")) //坐标,似乎只能得到一个点哦。。。
|
|
1116
|
+ {
|
|
1117
|
+ return pGeometryPointValueCoord(node, v);
|
|
1118
|
+ }
|
|
1119
|
+ else if ((!strcmp((char *)node->name(), "pointRep")) || (!strcmp((char *)node->name(), "pointProperty")) || (!strcmp((char *)node->name(), "gml:pointRep")) || (!strcmp((char *)node->name(), "gml:pointProperty")))
|
|
1120
|
+ {
|
|
1121
|
+ return pGeometryPointValuePointRep(node, v);
|
|
1122
|
+ }
|
|
1123
|
+ }
|
|
1124
|
+ return Error(-10, "point node not exist");
|
|
1125
|
+ }
|
|
1126
|
+
|
|
1127
|
+ int DmpWfsFilter::pGeometryEnvope(boost::property_tree::ptree& ptree, DmpWfsGmlObject **g)
|
|
1128
|
+ {
|
|
1129
|
+ pParsesrsName(n);
|
|
1130
|
+ double x1, y1, x2, y2;
|
|
1131
|
+ int re = pEnvelope(n, &x1, &y1, &x2, &y2);
|
|
1132
|
+ if (re)
|
|
1133
|
+ return Error(-25, "Envope error");
|
|
1134
|
+ clsGmlBBox *mp = new clsGmlBBox(x1, y1, x2, y2);
|
|
1135
|
+ *g = mp;
|
|
1136
|
+ return 0;
|
|
1137
|
+ }
|
|
1138
|
+
|
|
1139
|
+ int DmpWfsFilter::pGeometryMultiPoint(boost::property_tree::ptree& ptree, DmpWfsGmlObject **g)
|
|
1140
|
+ {
|
|
1141
|
+ xml_node<char> *node;
|
|
1142
|
+ clsGmlMultiPoint *mp = new clsGmlMultiPoint();
|
|
1143
|
+ clsGmlPoint *l;
|
|
1144
|
+ for (node = n->first_node2("pointMember", "pointMembers"); node; node = node->next_sibling2("pointMember", "pointMembers"))
|
|
1145
|
+ {
|
|
1146
|
+ rapidxml::xml_node<char> *t1 = node->first_node("Point");
|
|
1147
|
+ if (t1 == 0)
|
|
1148
|
+ {
|
|
1149
|
+ delete mp;
|
|
1150
|
+ return Error(-13, "no Point node");
|
|
1151
|
+ }
|
|
1152
|
+ int rt = pGeometryPoint(t1, (DmpWfsGmlObject **)(&l));
|
|
1153
|
+ if (rt)
|
|
1154
|
+ {
|
|
1155
|
+ delete mp;
|
|
1156
|
+ return rt;
|
|
1157
|
+ }
|
|
1158
|
+ mp->x.push_back(l->x);
|
|
1159
|
+ mp->y.push_back(l->y);
|
|
1160
|
+ }
|
|
1161
|
+ if (mp->x.size() < 1)
|
|
1162
|
+ {
|
|
1163
|
+ delete mp;
|
|
1164
|
+ return Error(-14, "no Point node");
|
|
1165
|
+ }
|
|
1166
|
+ *g = mp;
|
|
1167
|
+ return 0;
|
|
1168
|
+ }
|
|
1169
|
+
|
|
1170
|
+ int DmpWfsFilter::pGeometryMultiPolyline(boost::property_tree::ptree& ptree, DmpWfsGmlObject **g)
|
|
1171
|
+ {
|
|
1172
|
+ xml_node<char> *node;
|
|
1173
|
+ clsGmlPolyline *plyg = new clsGmlPolyline();
|
|
1174
|
+ for (node = n->first_node("polylineMember"); node; node = node->next_sibling("polylineMember"))
|
|
1175
|
+ {
|
|
1176
|
+ xml_node<char> *nodeN;
|
|
1177
|
+ for (nodeN = node->first_node("Polyline"); nodeN; nodeN = nodeN->next_sibling("Polyline"))
|
|
1178
|
+ {
|
|
1179
|
+ DmpWfsGmlObject *gT;
|
|
1180
|
+ pGeometryPolyline(nodeN, &gT);
|
|
1181
|
+ if (gT)
|
|
1182
|
+ {
|
|
1183
|
+ plyg->Append((clsGmlPolyline *)gT);
|
|
1184
|
+ delete gT;
|
|
1185
|
+ }
|
|
1186
|
+ }
|
|
1187
|
+ }
|
|
1188
|
+ if (plyg->outer.size() < 1)
|
|
1189
|
+ {
|
|
1190
|
+ delete plyg;
|
|
1191
|
+ return Error(-14, "no line string");
|
|
1192
|
+ }
|
|
1193
|
+ *g = plyg;
|
|
1194
|
+ return 0;
|
|
1195
|
+ }
|
|
1196
|
+
|
|
1197
|
+ int DmpWfsFilter::pGeometryMultiPolygon(boost::property_tree::ptree& ptree, DmpWfsGmlObject **g)
|
|
1198
|
+ {
|
|
1199
|
+ xml_node<char> *node;
|
|
1200
|
+ clsGmlPolygon *plyg = new clsGmlPolygon();
|
|
1201
|
+ for (node = n->first_node2("polygonMember", "PolygonMember"); node; node = node->next_sibling2("polygonMember", "PolygonMember"))
|
|
1202
|
+ {
|
|
1203
|
+ xml_node<char> *nodeN;
|
|
1204
|
+ for (nodeN = node->first_node("Polygon"); nodeN; nodeN = nodeN->next_sibling("Polygon"))
|
|
1205
|
+ {
|
|
1206
|
+ DmpWfsGmlObject *gT = NULL;
|
|
1207
|
+ pGeometryPolygon(nodeN, &gT);
|
|
1208
|
+ if (gT)
|
|
1209
|
+ {
|
|
1210
|
+ plyg->Append((clsGmlPolygon *)gT);
|
|
1211
|
+ delete gT;
|
|
1212
|
+ }
|
|
1213
|
+ }
|
|
1214
|
+ }
|
|
1215
|
+
|
|
1216
|
+ if (plyg->outer.size() < 1)
|
|
1217
|
+ {
|
|
1218
|
+ delete plyg;
|
|
1219
|
+ return Error(-14, "no exterior ring");
|
|
1220
|
+ }
|
|
1221
|
+ *g = plyg;
|
|
1222
|
+ return 0;
|
|
1223
|
+ }
|
|
1224
|
+ int DmpWfsFilter::pGeometryPolygon(boost::property_tree::ptree& ptree, DmpWfsGmlObject **g)
|
|
1225
|
+ {
|
|
1226
|
+ xml_node<char> *node;
|
|
1227
|
+ clsGmlPolygon *plyg = new clsGmlPolygon();
|
|
1228
|
+ DmpWfsGmlObject *l;
|
|
1229
|
+ for (node = n->first_node2("exterior", "outerBoundaryIs"); node; node = node->next_sibling2("exterior", "outerBoundaryIs"))
|
|
1230
|
+ {
|
|
1231
|
+ rapidxml::xml_node<char> *t1 = node->first_node("LinearRing");
|
|
1232
|
+ if (t1 == 0)
|
|
1233
|
+ t1 = node->first_node2("LineString", "lineString");
|
|
1234
|
+ if (t1 == 0)
|
|
1235
|
+ {
|
|
1236
|
+ delete plyg;
|
|
1237
|
+ return Error(-13, "no LineString node");
|
|
1238
|
+ }
|
|
1239
|
+ int rt = pGeometryLineString(t1, &l);
|
|
1240
|
+ if (rt)
|
|
1241
|
+ {
|
|
1242
|
+ delete plyg;
|
|
1243
|
+ return rt;
|
|
1244
|
+ }
|
|
1245
|
+ plyg->outer.push_back((clsGmlLineString *)l);
|
|
1246
|
+ }
|
|
1247
|
+ for (node = n->first_node2("interior", "innerBoundaryIs"); node; node = node->next_sibling2("interior", "innerBoundaryIs"))
|
|
1248
|
+ {
|
|
1249
|
+ rapidxml::xml_node<char> *t1 = node->first_node("LinearRing");
|
|
1250
|
+ if (t1 == 0)
|
|
1251
|
+ t1 = node->first_node2("LineString", "lineString");
|
|
1252
|
+ if (t1 == 0)
|
|
1253
|
+ {
|
|
1254
|
+ delete plyg;
|
|
1255
|
+ return Error(-13, "no LineString node");
|
|
1256
|
+ }
|
|
1257
|
+ int rt = pGeometryLineString(t1, &l);
|
|
1258
|
+ if (rt)
|
|
1259
|
+ {
|
|
1260
|
+ delete plyg;
|
|
1261
|
+ return rt;
|
|
1262
|
+ }
|
|
1263
|
+ plyg->inner.push_back((clsGmlLineString *)l);
|
|
1264
|
+ }
|
|
1265
|
+ if (plyg->outer.size() < 1)
|
|
1266
|
+ {
|
|
1267
|
+ delete plyg;
|
|
1268
|
+ return Error(-14, "no exterior ring");
|
|
1269
|
+ }
|
|
1270
|
+
|
|
1271
|
+ *g = plyg;
|
|
1272
|
+ return 0;
|
|
1273
|
+ }
|
|
1274
|
+
|
|
1275
|
+ int DmpWfsFilter::pGeometryPolyline(boost::property_tree::ptree& ptree, DmpWfsGmlObject **g)
|
|
1276
|
+ {
|
|
1277
|
+ xml_node<char> *node;
|
|
1278
|
+ clsGmlPolyline *plyg = new clsGmlPolyline();
|
|
1279
|
+ DmpWfsGmlObject *l;
|
|
1280
|
+ for (node = n->first_node2("lineStringMember", "gml::lineStringMember"); node; node = node->next_sibling2("lineStringMember", "gml::lineStringMember"))
|
|
1281
|
+ {
|
|
1282
|
+ rapidxml::xml_node<char> *t1 = node->first_node("LinearRing");
|
|
1283
|
+ if (t1 == 0)
|
|
1284
|
+ t1 = node->first_node2("LineString", "lineString");
|
|
1285
|
+ if (t1 == 0)
|
|
1286
|
+ {
|
|
1287
|
+ delete plyg;
|
|
1288
|
+ return Error(-13, "no LineString node");
|
|
1289
|
+ }
|
|
1290
|
+ int rt = pGeometryLineString(t1, &l);
|
|
1291
|
+ if (rt)
|
|
1292
|
+ {
|
|
1293
|
+ delete plyg;
|
|
1294
|
+ return rt;
|
|
1295
|
+ }
|
|
1296
|
+ plyg->outer.push_back((clsGmlLineString *)l);
|
|
1297
|
+ }
|
|
1298
|
+ if (plyg->outer.size() < 1)
|
|
1299
|
+ {
|
|
1300
|
+ delete plyg;
|
|
1301
|
+ return Error(-14, "no linestring");
|
|
1302
|
+ }
|
|
1303
|
+ *g = plyg;
|
|
1304
|
+ return 0;
|
|
1305
|
+ }
|
|
1306
|
+
|
|
1307
|
+ int DmpWfsFilter::pGeometryLineString(boost::property_tree::ptree& ptree, DmpWfsGmlObject **g)
|
|
1308
|
+ {
|
|
1309
|
+ //rapidxml::xml_node<char> * t=n->first_node();
|
|
1310
|
+ //if(t==0)return Error(-3,"point have no children");
|
|
1311
|
+ std::vector<double> v;
|
|
1312
|
+ int rt = pGeometryPointArray(n, v);
|
|
1313
|
+ if (rt)
|
|
1314
|
+ return rt;
|
|
1315
|
+ size_t vs = (size_t)v.size();
|
|
1316
|
+ if (vs < 4)
|
|
1317
|
+ return Error(-11, "point array too small");
|
|
1318
|
+ size_t vs2 = vs / 2;
|
|
1319
|
+ if ((2 * vs2) != vs)
|
|
1320
|
+ return Error(-12, "point array error");
|
|
1321
|
+
|
|
1322
|
+ clsGmlLineString *l = new clsGmlLineString();
|
|
1323
|
+ //l.size=
|
|
1324
|
+ l->x.resize(vs2);
|
|
1325
|
+ l->y.resize(vs2);
|
|
1326
|
+ for (size_t i = 0, j = 0; i < vs2; i++)
|
|
1327
|
+ {
|
|
1328
|
+ l->x[i] = v[j];
|
|
1329
|
+ j++;
|
|
1330
|
+ l->y[i] = v[j];
|
|
1331
|
+ j++;
|
|
1332
|
+ }
|
|
1333
|
+
|
|
1334
|
+ *g = l;
|
|
1335
|
+ return 0;
|
|
1336
|
+ }
|
|
1337
|
+
|
|
1338
|
+ void DmpWfsFilter::parse_gml_srs(boost::property_tree::ptree& ptree, gmlSrs *srs)
|
|
1339
|
+ {
|
|
1340
|
+ char *p;
|
|
1341
|
+ int is_planar;
|
|
1342
|
+ bool latlon = false;
|
|
1343
|
+ char sep = ':';
|
|
1344
|
+
|
|
1345
|
+ const char *srsname;
|
|
1346
|
+ xml_attribute<char> *pn = n->first_attribute("srsName");
|
|
1347
|
+ if (pn)
|
|
1348
|
+ {
|
|
1349
|
+ srsname = pn->value();
|
|
1350
|
+ }
|
|
1351
|
+ else
|
|
1352
|
+ {
|
|
1353
|
+ srs->srid = initConfig.DefaultSRID;
|
|
1354
|
+ srs->reverse_axis = false;
|
|
1355
|
+ return;
|
|
1356
|
+ }
|
|
1357
|
+
|
|
1358
|
+ if (!strncmp((char *)srsname, "EPSG:", 5))
|
|
1359
|
+ {
|
|
1360
|
+ sep = ':';
|
|
1361
|
+ latlon = false;
|
|
1362
|
+ }
|
|
1363
|
+ else if (!strncmp((char *)srsname, "urn:ogc:def:crs:EPSG:", 21) || !strncmp((char *)srsname, "urn:x-ogc:def:crs:EPSG:", 23) || !strncmp((char *)srsname, "urn:EPSG:geographicCRS:", 23))
|
|
1364
|
+ {
|
|
1365
|
+ sep = ':';
|
|
1366
|
+ latlon = true;
|
|
1367
|
+ }
|
|
1368
|
+ else if (!strncmp((char *)srsname,
|
|
1369
|
+ "http://www.opengis.net/gml/srs/epsg.xml#", 40))
|
|
1370
|
+ {
|
|
1371
|
+ sep = '#';
|
|
1372
|
+ latlon = false;
|
|
1373
|
+ }
|
|
1374
|
+ else
|
|
1375
|
+ {
|
|
1376
|
+ srs->srid = initConfig.DefaultSRID;
|
|
1377
|
+ srs->reverse_axis = false;
|
|
1378
|
+ return;
|
|
1379
|
+ }
|
|
1380
|
+
|
|
1381
|
+ /* retrieve the last ':' or '#' char */
|
|
1382
|
+ for (p = (char *)srsname; *p; p++)
|
|
1383
|
+ ;
|
|
1384
|
+ for (--p; *p != sep; p--)
|
|
1385
|
+ {
|
|
1386
|
+ if (!isdigit(*p))
|
|
1387
|
+ {
|
|
1388
|
+ srs->srid = initConfig.DefaultSRID;
|
|
1389
|
+ srs->reverse_axis = false;
|
|
1390
|
+ return;
|
|
1391
|
+ }
|
|
1392
|
+ }
|
|
1393
|
+
|
|
1394
|
+ srs->srid = p;
|
|
1395
|
+ p++; // atoi(++p);
|
|
1396
|
+ int id = atoi(srs->srid.c_str());
|
|
1397
|
+ return;
|
|
1398
|
+ }
|
|
1399
|
+
|
|
1400
|
+ int DmpWfsFilter::pGeometryPoint(boost::property_tree::ptree& ptree, DmpWfsGmlObject **g)
|
|
1401
|
+ {
|
|
1402
|
+ //rapidxml::xml_node<char> * t=n->first_node();
|
|
1403
|
+ //if(t==0)return Error(-3,"point have no children");
|
|
1404
|
+
|
|
1405
|
+ std::vector<double> v;
|
|
1406
|
+ int rt = pGeometryPointArray(n, v);
|
|
1407
|
+ if (rt)
|
|
1408
|
+ return rt;
|
|
1409
|
+ if (v.size() < 2)
|
|
1410
|
+ return Error(-10, "point array too small");
|
|
1411
|
+ clsGmlPoint *p = new clsGmlPoint();
|
|
1412
|
+ p->x = v[0];
|
|
1413
|
+ p->y = v[1];
|
|
1414
|
+ *g = p;
|
|
1415
|
+ return 0;
|
|
1416
|
+ }
|
|
1417
|
+ int DmpWfsFilter::pGeometry(boost::property_tree::ptree& ptree, DmpWfsGmlObject **g)
|
|
1418
|
+ {
|
|
1419
|
+ rapidxml::xml_node<char> *t;
|
|
1420
|
+ //这种方式更好
|
|
1421
|
+ //for (auto ptchild =ptree.begin(); ptchild != ptree.end(); ++ptchild);
|
|
1422
|
+
|
|
1423
|
+ t = n->first_node2("Point", "gml:Point");
|
|
1424
|
+ if (t)
|
|
1425
|
+ {
|
|
1426
|
+ pParsesrsName(t);
|
|
1427
|
+ return pGeometryPoint(t, g);
|
|
1428
|
+ }
|
|
1429
|
+ t = n->first_node2("LineString", "gml:LineString");
|
|
1430
|
+ if (t)
|
|
1431
|
+ {
|
|
1432
|
+ pParsesrsName(t);
|
|
1433
|
+ return pGeometryLineString(t, g);
|
|
1434
|
+ }
|
|
1435
|
+ t = n->first_node2("Polygon", "MultiPolygonString");
|
|
1436
|
+ t = t ? t : n->first_node2("gml:Polygon", "gml:MultiPolygonString");
|
|
1437
|
+ if (t)
|
|
1438
|
+ {
|
|
1439
|
+ pParsesrsName(t);
|
|
1440
|
+ return pGeometryPolygon(t, g);
|
|
1441
|
+ }
|
|
1442
|
+ t = n->first_node2("MultiPolygon", "gml:MultiPolygon");
|
|
1443
|
+ if (t)
|
|
1444
|
+ {
|
|
1445
|
+ pParsesrsName(t);
|
|
1446
|
+ return pGeometryMultiPolygon(t, g);
|
|
1447
|
+ }
|
|
1448
|
+ t = n->first_node2("Polyline", "MultiLineString");
|
|
1449
|
+ t = t ? t : n->first_node2("gml:Polyline", "gml:MultiLineString");
|
|
1450
|
+ if (t)
|
|
1451
|
+ {
|
|
1452
|
+ pParsesrsName(t);
|
|
1453
|
+ return pGeometryPolyline(t, g);
|
|
1454
|
+ }
|
|
1455
|
+ t = n->first_node2("MultiPolyline", "gml:MultiPolyline");
|
|
1456
|
+ if (t)
|
|
1457
|
+ {
|
|
1458
|
+ pParsesrsName(t);
|
|
1459
|
+ return pGeometryMultiPolyline(t, g);
|
|
1460
|
+ }
|
|
1461
|
+ t = n->first_node2("Polyline", "MultiLine");
|
|
1462
|
+ t = t ? t : n->first_node2("gml:Polyline", "gml:MultiLine");
|
|
1463
|
+ if (t)
|
|
1464
|
+ {
|
|
1465
|
+ pParsesrsName(t);
|
|
1466
|
+ return pGeometryPolyline(t, g);
|
|
1467
|
+ }
|
|
1468
|
+ t = n->first_node2("MultiPoint", "gml:MultiPoint");
|
|
1469
|
+ if (t)
|
|
1470
|
+ {
|
|
1471
|
+ pParsesrsName(t);
|
|
1472
|
+ return pGeometryMultiPoint(t, g);
|
|
1473
|
+ }
|
|
1474
|
+ t = n->first_node2("Envelope", "gml:Envelope");
|
|
1475
|
+ if (t)
|
|
1476
|
+ {
|
|
1477
|
+ pParsesrsName(t);
|
|
1478
|
+ return pGeometryEnvope(t, g);
|
|
1479
|
+ }
|
|
1480
|
+ t = n->first_node2("BBox", "gml:BBox");
|
|
1481
|
+ if (t)
|
|
1482
|
+ {
|
|
1483
|
+ pParsesrsName(t);
|
|
1484
|
+ return pGeometryEnvope(t, g);
|
|
1485
|
+ }
|
|
1486
|
+ return 0;
|
|
1487
|
+ }
|
|
1488
|
+
|
|
1489
|
+ int DmpWfsFilter::ParseOrder(char *xml, void *tdp, int dtp)
|
|
1490
|
+ {
|
|
1491
|
+ err[0] = 0;
|
|
1492
|
+ sql = "";
|
|
1493
|
+ this->td = (TableDesc *)tdp;
|
|
1494
|
+ this->DatabaseType = dtp;
|
|
1495
|
+ try
|
|
1496
|
+ {
|
|
1497
|
+ xml_document<> doc; // character type defaults to char
|
|
1498
|
+ doc.parse<0>(xml);
|
|
1499
|
+ xml_node<char> *n = doc.first_node();
|
|
1500
|
+ if (n == 0)
|
|
1501
|
+ {
|
|
1502
|
+ return Error(-12, "bad xml");
|
|
1503
|
+ }
|
|
1504
|
+ string name = this->GetFieldName(n->name());
|
|
1505
|
+ const char *p = name.c_str();
|
|
1506
|
+ if (strcmp(p, "SortBy"))
|
|
1507
|
+ return Error(-12, "no filter node");
|
|
1508
|
+ //sql="order by ";
|
|
1509
|
+ int nc = 0; //<SortBy><SortProperty><ValueReference>OBJECTID</ValueReference><SortOrder>DESC</SortOrder></SortProperty><SortProperty><ValueReference>AREA</ValueReference><SortOrder>DESC</SortOrder></SortProperty></SortBy>
|
|
1510
|
+ for (auto ptchild =ptree.begin(); ptchild != ptree.end(); ++ptchild)
|
|
1511
|
+ {
|
|
1512
|
+ if (strcmp(node->name(), "SortProperty") == 0)
|
|
1513
|
+ {
|
|
1514
|
+ xml_node<char> *node1 = node->first_node2("ValueReference", "PropertyName");
|
|
1515
|
+ if (node1 == 0)
|
|
1516
|
+ continue;
|
|
1517
|
+ if (nc == 0)
|
|
1518
|
+ {
|
|
1519
|
+ sql_ += " order by ";
|
|
1520
|
+ }
|
|
1521
|
+ else
|
|
1522
|
+ {
|
|
1523
|
+ sql_ += ",";
|
|
1524
|
+ }
|
|
1525
|
+ _AppendProperty(sql, node1->value());
|
|
1526
|
+ node1 = node->first_node("SortOrder");
|
|
1527
|
+ if (node1)
|
|
1528
|
+ {
|
|
1529
|
+ sql_ += " ";
|
|
1530
|
+ sql_ += node1->value();
|
|
1531
|
+ }
|
|
1532
|
+ nc++;
|
|
1533
|
+ }
|
|
1534
|
+ }
|
|
1535
|
+ }
|
|
1536
|
+ catch (parse_error e)
|
|
1537
|
+ {
|
|
1538
|
+ //const char *w=e.what();
|
|
1539
|
+ strncpy(this->err, e.what(), sizeof(this->err));
|
|
1540
|
+ return -13;
|
|
1541
|
+ }
|
|
1542
|
+ catch (...)
|
|
1543
|
+ {
|
|
1544
|
+ strncpy(this->err, "unknow error", sizeof(this->err));
|
|
1545
|
+ return -14;
|
|
1546
|
+ }
|
|
1547
|
+ return 0;
|
|
1548
|
+ }
|
|
1549
|
+
|
|
1550
|
+ int DmpWfsFilter::GetGeomFromGml(void *nn, std::string &strOut, double &x1, double &y1, double &x2, double &y2, void **geoOut)
|
|
1551
|
+ {
|
|
1552
|
+ if (geoOut)
|
|
1553
|
+ {
|
|
1554
|
+ *geoOut = 0;
|
|
1555
|
+ }
|
|
1556
|
+ strOut = "";
|
|
1557
|
+ xml_node<char> *node = (xml_node<char> *)nn;
|
|
1558
|
+ DmpWfsGmlObject *g = 0;
|
|
1559
|
+ int e = pGeometry(node, &g); //很重要的函数
|
|
1560
|
+ // char sz[100];//int srid=-1;
|
|
1561
|
+ // itoa(srs,sz,10);
|
|
1562
|
+ //strcpy(sz,"NULL");
|
|
1563
|
+ if (g)
|
|
1564
|
+ {
|
|
1565
|
+ g->GetRect(x1, y1, x2, y2);
|
|
1566
|
+ std::string sql;
|
|
1567
|
+ g->GetString(sql);
|
|
1568
|
+ switch (DatabaseType)
|
|
1569
|
+ {
|
|
1570
|
+ //case DatabaseTypeOracle:
|
|
1571
|
+ // {
|
|
1572
|
+ // if(geoOut)
|
|
1573
|
+ // {
|
|
1574
|
+ // SDOGeometry *sg=new SDOGeometry();
|
|
1575
|
+ // g->GetObj(sg);
|
|
1576
|
+ // if(strcmp(srs,"NULL"))
|
|
1577
|
+ // {
|
|
1578
|
+ // sg->setSdo_srid(atoi(srs)); //getobj测试, // this->DataType
|
|
1579
|
+ // }
|
|
1580
|
+ // *geoOut=(void *)sg; //构造ORACLE SPATIAL 的SDO_GEOMETRY结构
|
|
1581
|
+ // }
|
|
1582
|
+ // //else
|
|
1583
|
+ // {
|
|
1584
|
+ // //这里似乎用的是WKT的形式啊。。。
|
|
1585
|
+ // strOut="SDO_GEOMETRY('";
|
|
1586
|
+ // strOut=strOut+sql;
|
|
1587
|
+ // strOut=strOut+"',";
|
|
1588
|
+ // strOut=strOut+srs;
|
|
1589
|
+ // strOut=strOut+")";
|
|
1590
|
+ // }
|
|
1591
|
+ // }
|
|
1592
|
+ // break;
|
|
1593
|
+ case DatabaseTypePostgreSQL:
|
|
1594
|
+ {
|
|
1595
|
+ strOut = initConfig.geometryfromtext;
|
|
1596
|
+ strOut += "st_geomfromtext('"; //strOut="geometryfromtext('";
|
|
1597
|
+ strOut = strOut + sql;
|
|
1598
|
+ strOut = strOut + "',";
|
|
1599
|
+ //initConfig.DefaultGID;
|
|
1600
|
+ strOut = strOut + srs;
|
|
1601
|
+ strOut = strOut + ")";
|
|
1602
|
+ }
|
|
1603
|
+ break;
|
|
1604
|
+ default:
|
|
1605
|
+ return -18741;
|
|
1606
|
+ break;
|
|
1607
|
+ }
|
|
1608
|
+ }
|
|
1609
|
+ else
|
|
1610
|
+ {
|
|
1611
|
+ return -28102;
|
|
1612
|
+ }
|
|
1613
|
+
|
|
1614
|
+ return 0;
|
|
1615
|
+ }
|
35
|
1616
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|