提交 5b4fbc2ef9388b50325063c9c9746043c3daaeb8

作者 qingxiongf
1 个父辈 8cc18324

分类查询

... ... @@ -53,22 +53,34 @@ namespace DmapCore_30
53 53 for (auto ptchild = pt.begin(); ptchild != pt.end(); ++ptchild)
54 54 {
55 55 string sz = ptchild->first;
  56 +
56 57 if (boost::iequals(sz, "OTHER"))
57 58 {
58   - //rapidxml::xml_node<char>* node2 = node1->first_node();
59   - clsXML::XMLParse(ptchild->first,ptchild->second, &m_pDefaultSymbol);
  59 + for(auto ptchild2 = ptchild->second.begin(); ptchild2 != ptchild->second.end(); ptchild2++)
  60 + {
  61 + if(ptchild2->first != "<xmlattr>")
  62 + {
  63 + clsXML::XMLParse(ptchild2->first,ptchild2->second, &m_pDefaultSymbol);
  64 + break;
  65 + }
  66 + }
  67 +
60 68 }
61 69 else if (boost::iequals(sz, "EXACT"))
62 70 {
63 71 string sValue = clsXML::XMLGetPropByString(ptchild->second, "value");
64   -
65   - //rapidxml::xml_node<char>* node2 = node1->first_node();//exact 只有一个子节点 ,存着简单样
66   - Renderer* pSymbol = NULL;
67   - clsXML::XMLParse(ptchild->first, ptchild->second, &pSymbol);
68   -
69   - ValueMapRendererComponent* vmrc = new ValueMapRendererComponent(pSymbol, sValue);
70   -
71   - m_vComponents.push_back(vmrc);//引用只需要一份, 无需AddRef
  72 + //auto ptchild2 = ptchild->second.begin();
  73 + for(auto ptchild2 = ptchild->second.begin(); ptchild2 != ptchild->second.end(); ptchild2++)
  74 + {
  75 + if (ptchild2->first != "<xmlattr>")
  76 + {
  77 + Renderer *pSymbol = NULL;
  78 + clsXML::XMLParse(ptchild2->first, ptchild2->second, &pSymbol);
  79 + ValueMapRendererComponent *vmrc = new ValueMapRendererComponent(pSymbol, sValue);
  80 + m_vComponents.push_back(vmrc); //引用只需要一份, 无需AddRef
  81 + break;
  82 + }
  83 + }
72 84 }
73 85 else{ ; }
74 86 }
... ...
... ... @@ -9,6 +9,7 @@ SET (MAPSERVER_SRCS
9 9 dmppgsqlpool.cpp
10 10 dmppgsqlsourcepools.cpp
11 11 wfs/dmpwfs.cpp
  12 + wfs/dmpgmlfilter.cpp
12 13 wfs/dmpwfsgetcapabilities.cpp
13 14 wfs/dmpwfsgetfeature.cpp
14 15 wfs/dmpwfsparameters.cpp
... ... @@ -31,6 +32,7 @@ SET (MAPSERVER_HDRS
31 32 dmppgsqlpool.h
32 33 dmppgsqlsourcepools.h
33 34 wfs/dmpwfs.h
  35 + wfs/dmpgmlfilter.h
34 36 wfs/dmpwfsgetcapabilities.h
35 37 wfs/dmpwfsgetfeature.h
36 38 wfs/dmpwfsparameters.h
... ...
... ... @@ -102,6 +102,7 @@ namespace DmpMapping
102 102 json.append(",");
103 103 }
104 104 layer->writejson(json);
  105 + i++;
105 106 }
106 107
107 108 json.append("]}");
... ... @@ -132,6 +133,114 @@ namespace DmpMapping
132 133 return false;
133 134 }
134 135
  136 + bool loadProjectService(const DmpServerContext &context,ProjectMap& vectorMappingProjects)
  137 + {
  138 + const char *data = (char *)(context.request()->GetData());
  139 + if(data== nullptr || *data == '\0')
  140 + {
  141 + LOGGER_ERROR("post 参数错误");
  142 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}");
  143 + return false;
  144 + }
  145 +
  146 + try
  147 + {
  148 + std::stringstream stream(data);
  149 + boost::property_tree::ptree pt;
  150 + boost::property_tree::read_json(stream, pt);
  151 +
  152 + std::string guid = pt.get<std::string>("guid");
  153 + std::string project = pt.get<std::string>("project");
  154 + if(!guid.empty() && !project.empty())
  155 + {
  156 + std::string projData;
  157 + if (!DmpServerUtils::Base64Decode(project, &projData))
  158 + {
  159 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"base64转码错误\"}");
  160 + return false;
  161 + }
  162 + shared_ptr<DmpProject> project(new DmpProject());
  163 + if (!project->Read(projData))
  164 + {
  165 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"DMD文档错误\"}");
  166 + return false;
  167 + }
  168 + vectorMappingProjects[guid] = project;
  169 +
  170 + int i = 0;
  171 + double minx, miny, maxx, maxy;
  172 + std::map<std::string, DmpMapLayer *> mapLayers = project->mapLayers();
  173 + for (std::map<std::string, DmpMapLayer *>::iterator iter = mapLayers.begin(); iter != mapLayers.end(); iter++)
  174 + {
  175 + DmpMapLayer *layer = iter->second;
  176 + if (i == 0)
  177 + {
  178 + minx = layer->extent().xmin();
  179 + miny = layer->extent().ymin();
  180 + maxx = layer->extent().xmax();
  181 + maxy = layer->extent().ymax();
  182 + }
  183 + else
  184 + {
  185 + if (minx > layer->extent().xmin())
  186 + minx = layer->extent().xmin();
  187 + if (miny > layer->extent().ymin())
  188 + miny = layer->extent().ymin();
  189 + if (maxx < layer->extent().xmax())
  190 + maxx = layer->extent().xmax();
  191 + if (maxy < layer->extent().ymax())
  192 + maxy = layer->extent().ymax();
  193 + }
  194 + }
  195 +
  196 + char buff[250];
  197 + sprintf(buff, "{\"name\":\"%s\",\"title\":\"%s\",\"boundingBox\":{\"minx\":%f, \"miny\":%f,\"maxx\":%f, \"maxy\":%f }",
  198 + guid.c_str(), "",minx, miny, maxx, maxy);
  199 +
  200 + std::string json = buff;
  201 + json.append(",\"maplayer\":[");
  202 +
  203 + i = 0;
  204 + for (std::map<std::string, DmpMapLayer *>::iterator iter = mapLayers.begin(); iter != mapLayers.end(); iter++)
  205 + {
  206 + DmpVectorLayer *layer = (DmpVectorLayer*) iter->second;
  207 + if(i>0)
  208 + {
  209 + json.append(",");
  210 + }
  211 + layer->writejson(json);
  212 + i++;
  213 + }
  214 +
  215 + json.append("]}");
  216 +
  217 + context.response()->writeJson( json);
  218 + return true;
  219 + }
  220 + else
  221 + {
  222 + LOGGER_ERROR("post 参数错误");
  223 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}");
  224 + return false;
  225 + }
  226 + }
  227 + catch (boost::property_tree::ptree_bad_path &e)
  228 + {
  229 + LOGGER_ERROR(e.what());
  230 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误\"}");
  231 + return false;
  232 + }
  233 + catch (boost::property_tree::ptree_bad_data &e)
  234 + {
  235 + LOGGER_ERROR(e.what());
  236 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误\"}");
  237 + return false;
  238 + }
  239 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"未知错误\"}");
  240 + return false;
  241 + }
  242 +
  243 +
135 244 bool editService(const DmpServerContext &context,ProjectMap& vectorMappingProjects)
136 245 {
137 246 const char *data = (char *)(context.request()->GetData());
... ... @@ -166,6 +275,7 @@ namespace DmpMapping
166 275 }
167 276 vectorMappingProjects[guid] = project;
168 277 context.response()->writeJson("{\"status\":\"true\",\"message\":\"创建编辑服务工作空间成功!\"}");
  278 + return true;
169 279 }
170 280 else
171 281 {
... ...
... ... @@ -22,7 +22,7 @@ namespace DmpMapping
22 22
23 23 bool loadService(const DmpServerContext &context,ProjectMap& vectorMappingProjects);
24 24
25   -
  25 + bool loadProjectService(const DmpServerContext &context,ProjectMap& vectorMappingProjects);
26 26 bool editService(const DmpServerContext &context,ProjectMap& vectorMappingProjects);
27 27
28 28 }
... ...
... ... @@ -187,7 +187,8 @@ namespace DmpMapping
187 187 else
188 188 {
189 189 LOGGER_ERROR("not find dir " + imagePath);
190   - context.response()->writeJson(R"("{"value":[]}")");
  190 + context.response()->writeJson(R"({"value":[]}")");
  191 + return ;
191 192 }
192 193
193 194 ptDoc.add_child("value", ptRoot);
... ... @@ -234,6 +235,8 @@ namespace DmpMapping
234 235 else
235 236 {
236 237 LOGGER_ERROR("not find dir " + imagePath);
  238 + context.response()->writeJson(R"({"value":[]}")");
  239 + return ;
237 240 }
238 241
239 242 ptDoc.add_child("value", ptRoot);
... ...
... ... @@ -50,6 +50,10 @@ namespace DmpMapping
50 50 {
51 51 loadService(context, vectorMappingProjects_);
52 52 }
  53 + else if (boost::iequals(request, "loadDmdService"))
  54 + {
  55 + loadProjectService(context, vectorMappingProjects_);
  56 + }
53 57 else if (boost::iequals(request, "editService"))
54 58 {
55 59 editService(context, vectorMappingProjects_);
... ...
  1 +
  2 +/**************************************************************************
  3 +* file: dmpgmlfilter.cpp
  4 +
  5 +* Author: qingxiongf
  6 +* Date: 2022-01-07 14:44:06
  7 +* Email: qingxiongf@chinadci.com
  8 +* copyright: 广州城市信息研究所有限公司
  9 +***************************************************************************/
  10 +#include "dmpgmlfilter.h"
  11 +#include <boost/dll/alias.hpp> // for BOOST_DLL_ALIAS
  12 +#include <boost/filesystem.hpp>
  13 +#include <boost/function.hpp>
  14 +#include <boost/make_shared.hpp>
  15 +#include <boost/algorithm/string/predicate.hpp>
  16 +
  17 +namespace DmpWfs
  18 +{
  19 +
  20 + DmpGmlFilter::DmpGmlFilter(/* args */)
  21 + {
  22 + }
  23 +
  24 + DmpGmlFilter::~DmpGmlFilter()
  25 + {
  26 + }
  27 +
  28 + bool DmpGmlFilter::Parse(const std::string &filter)
  29 + {
  30 + try
  31 + {
  32 + std::stringstream stream(filter);
  33 + boost::property_tree::ptree ptree;
  34 + boost::property_tree::read_xml(stream, ptree);
  35 +
  36 + boost::property_tree::ptree::iterator ptroot = ptree.begin();
  37 + if( ptroot !=ptree.end() && (boost::iequals(ptroot->first,"fes:Filter")|| boost::iequals(ptroot->first,"Filter") || boost::iequals(ptroot->first,"ogc:Filter")))
  38 + {
  39 +
  40 + }
  41 +
  42 + /*if(!(strcmp(p,"fes:Filter")==0||strcmp(p,"Filter")==0 || strcmp(p,"ogc:Filter")==0))return Error(-12,"no filter node");
  43 + bool isFirst = true;
  44 + for (boost::property_tree::ptree::iterator ptchild = ptree.begin(); ptchild != ptree.end(); ++ptchild)
  45 + {
  46 + if (!isFirst)
  47 + {
  48 + sql_ += " or ";
  49 + }
  50 +
  51 + printf("%s\r\n",ptchild->first.c_str());
  52 +
  53 + }*/
  54 + }
  55 + catch (const std::exception &e)
  56 + {
  57 +
  58 + }
  59 +
  60 + return false;
  61 + }
  62 +}
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: dmpgmlfilter.h
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2022-01-07 14:43:56
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __dmpgmlfilter_h__
  11 +#define __dmpgmlfilter_h__
  12 +
  13 +#include <boost/property_tree/ptree.hpp>
  14 +#include <boost/property_tree/xml_parser.hpp>
  15 +#include <boost/typeof/typeof.hpp>
  16 +#include <string>
  17 +#include "dmpwfsgmlobject.h"
  18 +/*
  19 +* 参考文献
  20 +* https://www.mapserver.org/ogc/filter_encoding.html
  21 +*/
  22 +using namespace std;
  23 +namespace DmpWfs
  24 +{
  25 + class DmpGmlFilter
  26 + {
  27 +
  28 + public:
  29 + DmpGmlFilter();
  30 + ~DmpGmlFilter();
  31 +
  32 + bool Parse(const std::string &filter);
  33 +
  34 + private:
  35 + std::string sql_;
  36 + /* data */
  37 + };
  38 +}
  39 +
  40 +#endif // __dmpgmlfilter_h__
... ...
... ... @@ -52,7 +52,7 @@ namespace DmpWfs
52 52 {
53 53 writeGetCapabilities(context,params, project);
54 54 }
55   - else if(boost::iequals(request, "getmap"))
  55 + else if(boost::iequals(request, "getfeature"))
56 56 {
57 57 writeGetFeature(context,params, project);
58 58 }
... ...
... ... @@ -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
... ...
... ... @@ -9,12 +9,12 @@
9 9
10 10 #ifndef __dmpwfsfilter_h__
11 11 #define __dmpwfsfilter_h__
12   -#include <boost/property_tree/ptree.hpp>
13   -#include <boost/property_tree/xml_parser.hpp>
  12 +#include <boost/property_tree/ptree.hpp>
  13 +#include <boost/property_tree/xml_parser.hpp>
14 14 #include <boost/typeof/typeof.hpp>
15 15 #include <string>
16 16 #include "dmpwfsgmlobject.h"
17   -
  17 +using namespace std;
18 18 namespace DmpWfs
19 19 {
20 20 class DmpWfsFilter
... ... @@ -29,33 +29,67 @@ namespace DmpWfs
29 29
30 30 private:
31 31 std::string sql_;
  32 + std::string error_;
  33 + int errorCode_;
  34 +
  35 + std::string GetFieldName(const std::string& name);
  36 +
  37 + int _All(const std::string &name, boost::property_tree::ptree &ptree);
  38 + int _Or(boost::property_tree::ptree &ptree);
  39 + int _Not(boost::property_tree::ptree &ptree);
  40 + int _And(boost::property_tree::ptree &ptree);
  41 + int _BBOX(boost::property_tree::ptree &ptree);
  42 + int _Equals(boost::property_tree::ptree &ptree);
  43 + int _Beyond(boost::property_tree::ptree &ptree);
  44 + int _Within(boost::property_tree::ptree &ptree);
  45 + int _Crosses(boost::property_tree::ptree &ptree);
  46 + int _Touches(boost::property_tree::ptree &ptree);
  47 + int _DWithin(boost::property_tree::ptree &ptree);
  48 + int _Contains(boost::property_tree::ptree &ptree);
  49 + int _Overlaps(boost::property_tree::ptree &ptree);
  50 + int _Disjoint(boost::property_tree::ptree &ptree);
  51 + int _FeatureId(boost::property_tree::ptree &ptree);
  52 + int _Intersects(boost::property_tree::ptree &ptree);
  53 + int _DIntersects(boost::property_tree::ptree &ptree);
  54 + int _GmlObjectId(boost::property_tree::ptree &ptree);
  55 + int _PropertyIsLike(boost::property_tree::ptree &ptree);
  56 + int _PropertyIsNull(boost::property_tree::ptree &ptree);
  57 + int _PropertyIsBetween(boost::property_tree::ptree &ptree);
  58 + int _PropertyIsEqualTo(boost::property_tree::ptree &ptree);
  59 + int _PropertyIsLessThan(boost::property_tree::ptree &ptree);
  60 + int _PropertyIsNotEqualTo(boost::property_tree::ptree &ptree);
  61 + int _PropertyIsGreaterThan(boost::property_tree::ptree &ptree);
  62 + int _PropertyIsLessThanOrEqualTo(boost::property_tree::ptree &ptree);
  63 + int _PropertyIsGreaterThanOrEqualTo(boost::property_tree::ptree &ptree);
  64 + int pEnvelope(boost::property_tree::ptree &ptree, double *x1, double *y1, double *x2, double *y2);
32 65
33   - int pGeometry(boost::property_tree::ptree ptree, DmpWfsGmlObject **g);
34   - int pGeometryPoint(boost::property_tree::ptree ptree, DmpWfsGmlObject **g);
35   - int pGeometryLineString(boost::property_tree::ptree ptree, DmpWfsGmlObject **g);
36   - int pGeometryMultiPolyline(boost::property_tree::ptree ptree, DmpWfsGmlObject **g);
37   - int pGeometryMultiPolygon(boost::property_tree::ptree ptree, DmpWfsGmlObject **g);
38   - int pGeometryPolygon(boost::property_tree::ptree ptree, DmpWfsGmlObject **g);
39   - int pGeometryMultiPoint(boost::property_tree::ptree ptree, DmpWfsGmlObject **g);
40   - int pGeometryPolyline(boost::property_tree::ptree ptree, DmpWfsGmlObject **g);
41   - int pGeometryEnvope(boost::property_tree::ptree ptree, DmpWfsGmlObject **g);
42   - int pGeometryPointArray(boost::property_tree::ptree ptree, std::vector<double> &v);
  66 + int pGeometry(boost::property_tree::ptree &ptree, DmpWfsGmlObject **g);
  67 + int pGeometryPoint(boost::property_tree::ptree &ptree, DmpWfsGmlObject **g);
  68 + int pGeometryLineString(boost::property_tree::ptree &ptree, DmpWfsGmlObject **g);
  69 + int pGeometryMultiPolyline(boost::property_tree::ptree &ptree, DmpWfsGmlObject **g);
  70 + int pGeometryMultiPolygon(boost::property_tree::ptree &ptree, DmpWfsGmlObject **g);
  71 + int pGeometryPolygon(boost::property_tree::ptree &ptree, DmpWfsGmlObject **g);
  72 + int pGeometryMultiPoint(boost::property_tree::ptree &ptree, DmpWfsGmlObject **g);
  73 + int pGeometryPolyline(boost::property_tree::ptree &ptree, DmpWfsGmlObject **g);
  74 + int pGeometryEnvope(boost::property_tree::ptree &ptree, DmpWfsGmlObject **g);
  75 + int pGeometryPointArray(boost::property_tree::ptree &ptree, std::vector<double> &v);
43 76 int pGeometryPointValue(char *p, std::vector<double> &v);
44 77 int pGeometryDouble(char *d, bool space_before, bool space_after, double &dbl);
45 78 int pGeometryPointValuePos(char *p, std::vector<double> &v);
46   - int pGeometryPointValuePosList(boost::property_tree::ptree ptree, std::vector<double> &v);
  79 + int pGeometryPointValuePosList(boost::property_tree::ptree &ptree, std::vector<double> &v);
47 80 int pGeometryPointValueCoordinates(char *p, std::vector<double> &v);
48   - int pGeometryPointValuePointRep(boost::property_tree::ptree ptree, std::vector<double> &v);
49   - int pGeometryPointValueCoord(boost::property_tree::ptree ptree, std::vector<double> &v);
50   - int pGeometryGetDis(boost::property_tree::ptree ptree, double &dis);
51   - int pGeometrySql(char *function, char *oracle_mask, int isDisjoin, boost::property_tree::ptree ptree, bool useBuffer); //char *function,char *field,DmpWfsGmlObject *g,std::string &str);
  81 + int pGeometryPointValuePointRep(boost::property_tree::ptree &ptree, std::vector<double> &v);
  82 + int pGeometryPointValueCoord(boost::property_tree::ptree &ptree, std::vector<double> &v);
  83 + int pGeometryGetDis(boost::property_tree::ptree &ptree, double &dis);
  84 + int pGeometrySql(char *function, char *oracle_mask, int isDisjoin, boost::property_tree::ptree &ptree, bool useBuffer); //char *function,char *field,DmpWfsGmlObject *g,std::string &str);
52 85 private:
53   - void GetQueryField(const char *field);
  86 + int Error(int code,const char * err);
  87 + // void GetQueryField(const char *field);
54 88 void _AppendProperty(std::string &sql, const char *str);
55   - int _PropertyParse(boost::property_tree::ptree ptreeode, int &isExpression, int isLike = 0);
56   - int _PropertyParse4(boost::property_tree::ptree ptreeode, char *f);
57   - int _PropertyParseFunction(boost::property_tree::ptree ptree);
58   - int _PropertyOneEqual(boost::property_tree::ptree ptree, char *type, int isLike = 0);
  89 + int _PropertyParse(const std::string& ptreeName, boost::property_tree::ptree &ptreeode, int &isExpression, int isLike = 0);
  90 + int _PropertyParse4(boost::property_tree::ptree &ptreeode, char *f);
  91 + int _PropertyParseFunction(boost::property_tree::ptree &ptree);
  92 + int _PropertyOneEqual(boost::property_tree::ptree &ptree, char *type, int isLike = 0);
59 93 };
60 94
61 95 }
... ...
... ... @@ -10,7 +10,7 @@
10 10 #include "dmpsqlfactory.h"
11 11 #include "dmpmapserverutil.h"
12 12 #include "dmpvectorlayer.h"
13   -#include "dmpwfsfilter.h"
  13 +#include "dmpgmlfilter.h"
14 14 #include <string.h>
15 15
16 16 namespace DmpWfs
... ... @@ -19,15 +19,15 @@ namespace DmpWfs
19 19 const DmpProject* project,
20 20 bool projectSettings)
21 21 {
22   -
  22 + WfsGetFeature(context, params, project, projectSettings);
23 23 }
24   -
  24 +
25 25 std::string WfsGetFeature(const DmpServerContext &context,const DmpWfsParameters& params,
26 26 const DmpProject* project,
27 27 bool projectSettings)
28 28 {
29 29 char buff[5000];
30   - DmpSqlFactory sqlFactory;
  30 + // DmpSqlFactory sqlFactory;
31 31
32 32 int maxFeatures = params.MaxFeatures();
33 33 int startIndex = params.StartIndex();
... ... @@ -39,8 +39,9 @@ namespace DmpWfs
39 39
40 40 std::string sortby = params.Sortby();
41 41
42   -
43   -
  42 + DmpGmlFilter gmlFilter;
  43 + gmlFilter.Parse(filter);
  44 +/*
44 45 sqlFactory.setStartIndexCount(startIndex, maxFeatures, resultType);
45 46
46 47 std::vector<std::string> ids;
... ... @@ -102,7 +103,7 @@ namespace DmpWfs
102 103 }
103 104 }
104 105 }
105   -
  106 +
106 107
107 108 if (typeName.empty())
108 109 {
... ... @@ -199,7 +200,7 @@ namespace DmpWfs
199 200 if (!pPgsqlConn->ExecWaitBinary(sql))
200 201 {
201 202 return "查询错误:" + pPgsqlConn->error();
202   - }
  203 + } */
203 204 // int ver = ParseString::GetGMLVersion(parseString.version, parseString.outputFormat);
204 205 /* if (parseString.format && (strcmpi(parseString.format, "geojson") ==0|| strcmpi(parseString.format, "json")==0))
205 206 {
... ...
... ... @@ -19,6 +19,7 @@
19 19 #include "dmpwfsparameters.h"
20 20 #include "dmpservercontext.h"
21 21 #include "dmppgsqlsourcepools.h"
  22 +#include "dmpgmlfilter.h"
22 23 using namespace mapserver;
23 24 namespace DmpWfs
24 25 {
... ... @@ -26,9 +27,9 @@ namespace DmpWfs
26 27 const DmpProject* project,
27 28 bool projectSettings = false);
28 29
29   - // std::string WfsGetFeature(const DmpServerContext &context,const DmpWfsParameters& params,
30   - // const DmpProject* project,
31   - // bool projectSettings = false);
  30 + std::string WfsGetFeature(const DmpServerContext &context,const DmpWfsParameters& params,
  31 + const DmpProject* project,
  32 + bool projectSettings = false);
32 33
33 34
34 35 void getAsStringSql(const string& str,std::string &sProp,std::string &sAs);
... ...
注册登录 后发表评论