正在显示
15 个修改的文件
包含
428 行增加
和
110 行删除
| ... | ... | @@ -94,6 +94,78 @@ bool DmpVectorLayer::writeXml(boost::property_tree::ptree &layerNode) |
| 94 | 94 | return true; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | +bool DmpVectorLayer::writejson(std::string& json) | |
| 98 | +{ | |
| 99 | + string shapeTypeString ="UNKNOWORD"; | |
| 100 | + | |
| 101 | + switch (wkbType_) | |
| 102 | + { | |
| 103 | + case DmpWkbTypes::Point: shapeTypeString = "POINT"; | |
| 104 | + break; | |
| 105 | + case DmpWkbTypes::MultiPoint: shapeTypeString = "MULTIPOINT"; | |
| 106 | + break; | |
| 107 | + case DmpWkbTypes::LineString: shapeTypeString = "LINESTRING"; | |
| 108 | + break; | |
| 109 | + case DmpWkbTypes::MultiLineString: shapeTypeString = "MULTILINESTRING"; | |
| 110 | + break; | |
| 111 | + case DmpWkbTypes::Polygon : shapeTypeString = "POLYGON"; | |
| 112 | + break; | |
| 113 | + case DmpWkbTypes::MultiPolygon : shapeTypeString = "MULTIPOLYGON"; | |
| 114 | + break; | |
| 115 | + default: | |
| 116 | + shapeTypeString ="UNKNOWORD"; | |
| 117 | + break; | |
| 118 | + } | |
| 119 | + | |
| 120 | + bool alwaysShow = this->minScale() == 0 && this->maxScale() >10000000000; | |
| 121 | + char buff_maxscale[100]; | |
| 122 | + char buff_minscale[100]; | |
| 123 | + if(this->maxScale() > 100000000) | |
| 124 | + { | |
| 125 | + sprintf(buff_maxscale,"%e", this->maxScale()); | |
| 126 | + } | |
| 127 | + else | |
| 128 | + { | |
| 129 | + sprintf(buff_maxscale,"%.0f", this->maxScale()); | |
| 130 | + } | |
| 131 | + | |
| 132 | + if(this->minScale() > 100000000) | |
| 133 | + { | |
| 134 | + sprintf(buff_minscale,"%e", this->minScale() ); | |
| 135 | + } | |
| 136 | + else | |
| 137 | + { | |
| 138 | + sprintf(buff_minscale,"%.0f", this->minScale() ); | |
| 139 | + } | |
| 140 | + //Display scale setting type="1" geometry="Point" alwaysShow="true" maxScale="0" maxScale="50000"> | |
| 141 | + char resultbuff[1000]; | |
| 142 | + sprintf(resultbuff, | |
| 143 | + R"({"workspace":"","type":"1","dbsourceid":"%s","data":"","schema":"%s","alias":"%s","name":"%s","id":"%s","filter":"%s","visible":"%s","tag":"","minScale":"%s","maxScale":"%s","geometry":"%s","alwaysShow":"%s")", | |
| 144 | + this->source().c_str(), | |
| 145 | + this->schema().c_str(), | |
| 146 | + this->title().c_str(), | |
| 147 | + this->name().c_str(), | |
| 148 | + this->id().c_str(), | |
| 149 | + this->wherestr_.c_str(), | |
| 150 | + "true", | |
| 151 | + buff_minscale,buff_maxscale, | |
| 152 | + shapeTypeString.c_str(), | |
| 153 | + alwaysShow?"true":"false" | |
| 154 | + ); | |
| 155 | + | |
| 156 | + json.append(resultbuff); | |
| 157 | + if(this->renderer_30_ != nullptr) | |
| 158 | + { | |
| 159 | + | |
| 160 | + json.append(","); | |
| 161 | + DmapCore_30::AppendBuffer ab; | |
| 162 | + this->renderer_30_->ToJson(&ab); | |
| 163 | + json.append(ab.GetString()); | |
| 164 | + } | |
| 165 | + json.append("}"); | |
| 166 | + return true; | |
| 167 | +} | |
| 168 | + | |
| 97 | 169 | void DmpVectorLayer::setRenderer(DmpFeatureRenderer *renderer) |
| 98 | 170 | { |
| 99 | 171 | ... | ... |
| ... | ... | @@ -44,6 +44,7 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer |
| 44 | 44 | DmpMapLayerRenderer *createMapRenderer(DmpRenderContext &rendererContext); |
| 45 | 45 | bool readXml(const boost::property_tree::ptree &layerNode); |
| 46 | 46 | bool writeXml(boost::property_tree::ptree &layerNode); |
| 47 | + bool writejson(std::string& json); | |
| 47 | 48 | |
| 48 | 49 | DmpFeatureRenderer *renderer() { return renderer_; } |
| 49 | 50 | void setRenderer(DmpFeatureRenderer *renderer); | ... | ... |
| ... | ... | @@ -148,4 +148,45 @@ void DmpMapServerUtil::responseGeojson(shared_ptr<DmpPgsql> pPgsqlConn, std::str |
| 148 | 148 | } |
| 149 | 149 | return strsrc; |
| 150 | 150 | } |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + std::vector<std::string> DmpMapServerUtil::stringSplit(const std::string &str, const std::string &pattern) | |
| 155 | + { | |
| 156 | + vector<std::string> stringList; | |
| 157 | + std::string subStr; | |
| 158 | + std::string tPattern; | |
| 159 | + size_t patternLen = pattern.length(); | |
| 160 | + for (size_t i = 0; i < str.length(); i++) | |
| 161 | + { | |
| 162 | + if(pattern[0] == str[i]) | |
| 163 | + { | |
| 164 | + tPattern = str.substr(i, patternLen); | |
| 165 | + if(tPattern == pattern) | |
| 166 | + { | |
| 167 | + i += patternLen -1; | |
| 168 | + if(!subStr.empty()) | |
| 169 | + { | |
| 170 | + stringList.push_back(subStr); | |
| 171 | + subStr.clear(); | |
| 172 | + } | |
| 173 | + } | |
| 174 | + else | |
| 175 | + { | |
| 176 | + subStr.push_back(str[i]); | |
| 177 | + } | |
| 178 | + } | |
| 179 | + else | |
| 180 | + { | |
| 181 | + subStr.push_back(str[i]); | |
| 182 | + } | |
| 183 | + } | |
| 184 | + | |
| 185 | + if(!subStr.empty()) | |
| 186 | + { | |
| 187 | + stringList.push_back(subStr); | |
| 188 | + } | |
| 189 | + return stringList; | |
| 190 | + | |
| 191 | + } | |
| 151 | 192 | } |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -22,6 +22,8 @@ namespace mapserver |
| 22 | 22 | static void responseGeojson(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const std::string &srid); |
| 23 | 23 | static void toJsonString(std::string &s); |
| 24 | 24 | static std::string replace(std::string strsrc, std::string strfind, std::string strrep); |
| 25 | + | |
| 26 | + static std::vector<std::string> stringSplit(const std::string &str, const std::string &pattern); | |
| 25 | 27 | }; |
| 26 | 28 | } |
| 27 | 29 | ... | ... |
| ... | ... | @@ -11,6 +11,7 @@ |
| 11 | 11 | #include "dmpserverresponse.h" |
| 12 | 12 | #include "dmpserverrequest.h" |
| 13 | 13 | #include "dmpproject.h" |
| 14 | +#include "dmpvectorlayer.h" | |
| 14 | 15 | #include "dmpserverproject.h" |
| 15 | 16 | #include <boost/property_tree/ptree.hpp> |
| 16 | 17 | #include <boost/property_tree/json_parser.hpp> |
| ... | ... | @@ -21,6 +22,9 @@ namespace DmpMapping |
| 21 | 22 | bool loadService(const DmpServerContext &context, ProjectMap& vectorMappingProjects) |
| 22 | 23 | { |
| 23 | 24 | const char *data = (char *)(context.request()->GetData()); |
| 25 | + std::string name = context.serverProject()->name(); | |
| 26 | + std::string title = context.serverProject()->title(); | |
| 27 | + | |
| 24 | 28 | if(data== nullptr || *data == '\0') |
| 25 | 29 | { |
| 26 | 30 | LOGGER_ERROR("post 参数错误"); |
| ... | ... | @@ -54,9 +58,54 @@ namespace DmpMapping |
| 54 | 58 | return false; |
| 55 | 59 | } |
| 56 | 60 | vectorMappingProjects[guid] = project; |
| 57 | - context.response()->removeHeader("Content-Type"); | |
| 58 | - context.response()->setHeader("Content-Type", "text/xml;charset=utf-8"); | |
| 59 | - context.response()->write(projectData); | |
| 61 | + | |
| 62 | + int i = 0; | |
| 63 | + double minx, miny, maxx, maxy; | |
| 64 | + std::map<std::string, DmpMapLayer *> mapLayers = project->mapLayers(); | |
| 65 | + for (std::map<std::string, DmpMapLayer *>::iterator iter = mapLayers.begin(); iter != mapLayers.end(); iter++) | |
| 66 | + { | |
| 67 | + DmpMapLayer *layer = iter->second; | |
| 68 | + if (i == 0) | |
| 69 | + { | |
| 70 | + minx = layer->extent().xmin(); | |
| 71 | + miny = layer->extent().ymin(); | |
| 72 | + maxx = layer->extent().xmax(); | |
| 73 | + maxy = layer->extent().ymax(); | |
| 74 | + } | |
| 75 | + else | |
| 76 | + { | |
| 77 | + if (minx > layer->extent().xmin()) | |
| 78 | + minx = layer->extent().xmin(); | |
| 79 | + if (miny > layer->extent().ymin()) | |
| 80 | + miny = layer->extent().ymin(); | |
| 81 | + if (maxx < layer->extent().xmax()) | |
| 82 | + maxx = layer->extent().xmax(); | |
| 83 | + if (maxy < layer->extent().ymax()) | |
| 84 | + maxy = layer->extent().ymax(); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + | |
| 88 | + char buff[250]; | |
| 89 | + sprintf(buff, "{\"name\":\"%s\",\"title\":\"%s\",\"boundingBox\":{\"minx\":%f, \"miny\":%f,\"maxx\":%f, \"maxy\":%f }", | |
| 90 | + name.c_str(), title.c_str(),minx, miny, maxx, maxy); | |
| 91 | + | |
| 92 | + std::string json = buff; | |
| 93 | + json.append(",\"maplayer\":["); | |
| 94 | + | |
| 95 | + i = 0; | |
| 96 | + for (std::map<std::string, DmpMapLayer *>::iterator iter = mapLayers.begin(); iter != mapLayers.end(); iter++) | |
| 97 | + { | |
| 98 | + DmpVectorLayer *layer = (DmpVectorLayer*) iter->second; | |
| 99 | + if(i>0) | |
| 100 | + { | |
| 101 | + json.append(","); | |
| 102 | + } | |
| 103 | + layer->writejson(json); | |
| 104 | + } | |
| 105 | + | |
| 106 | + json.append("]}"); | |
| 107 | + | |
| 108 | + context.response()->write( project->WriteJson()); | |
| 60 | 109 | return true; |
| 61 | 110 | } |
| 62 | 111 | else |
| ... | ... | @@ -105,11 +154,13 @@ namespace DmpMapping |
| 105 | 154 | std::string projData; |
| 106 | 155 | if (!DmpServerUtils::Base64Decode(project, &projData)) |
| 107 | 156 | { |
| 157 | + context.response()->writeJson("{\"status\":\"false\",\"message\":\"base64转码错误\"}"); | |
| 108 | 158 | return false; |
| 109 | 159 | } |
| 110 | 160 | shared_ptr<DmpProject> project(new DmpProject()); |
| 111 | 161 | if (!project->Read(projData)) |
| 112 | 162 | { |
| 163 | + context.response()->writeJson("{\"status\":\"false\",\"message\":\"DMD文档错误\"}"); | |
| 113 | 164 | return false; |
| 114 | 165 | } |
| 115 | 166 | vectorMappingProjects[guid] = project; |
| ... | ... | @@ -121,7 +172,6 @@ namespace DmpMapping |
| 121 | 172 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); |
| 122 | 173 | return false; |
| 123 | 174 | } |
| 124 | - | |
| 125 | 175 | } |
| 126 | 176 | catch (boost::property_tree::ptree_bad_path &e) |
| 127 | 177 | { |
| ... | ... | @@ -135,7 +185,8 @@ namespace DmpMapping |
| 135 | 185 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误\"}"); |
| 136 | 186 | return false; |
| 137 | 187 | } |
| 138 | - return false; | |
| 188 | + context.response()->writeJson("{\"status\":\"false\",\"message\":\"未知错误\"}"); | |
| 189 | + return false; | |
| 139 | 190 | } |
| 140 | 191 | |
| 141 | 192 | } |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -97,7 +97,10 @@ namespace DmpMapping |
| 97 | 97 | std::string DmpMappingParameters::MapGuid() const |
| 98 | 98 | { |
| 99 | 99 | std::string value = ""; |
| 100 | - GetStringParameter("GUID",value); | |
| 100 | + if(!GetStringParameter("GUID",value)) | |
| 101 | + { | |
| 102 | + GetStringParameter("MappingGUID",value); | |
| 103 | + } | |
| 101 | 104 | return value; |
| 102 | 105 | } |
| 103 | 106 | ... | ... |
| ... | ... | @@ -37,27 +37,27 @@ namespace DmpWfs |
| 37 | 37 | |
| 38 | 38 | void DmpSqlFactory::appendCondition(char *c) |
| 39 | 39 | { |
| 40 | - if (condition.size() == 0) | |
| 40 | + if (condition_.size() == 0) | |
| 41 | 41 | { |
| 42 | - condition = c; | |
| 42 | + condition_ = c; | |
| 43 | 43 | } |
| 44 | 44 | else |
| 45 | 45 | { |
| 46 | - condition += " and "; | |
| 46 | + condition_ += " and "; | |
| 47 | 47 | condition += c; |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | void DmpSqlFactory::appendCondition(std::string &c) |
| 52 | 52 | { |
| 53 | - if (condition.size() == 0) | |
| 53 | + if (condition_.size() == 0) | |
| 54 | 54 | { |
| 55 | 55 | condition = c; |
| 56 | 56 | } |
| 57 | 57 | else |
| 58 | 58 | { |
| 59 | - condition += " and "; | |
| 60 | - condition += c; | |
| 59 | + condition_ += " and "; | |
| 60 | + condition_ += c; | |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| ... | ... | @@ -70,27 +70,27 @@ namespace DmpWfs |
| 70 | 70 | } |
| 71 | 71 | else |
| 72 | 72 | { |
| 73 | - if (this->prop.size() == 0) | |
| 73 | + if (this->prop_.size() == 0) | |
| 74 | 74 | { |
| 75 | 75 | sql += "*"; |
| 76 | 76 | } |
| 77 | 77 | else |
| 78 | - sql += this->prop; | |
| 78 | + sql += this->prop_; | |
| 79 | 79 | } |
| 80 | 80 | sql += " from \""; |
| 81 | - sql += this->table; | |
| 81 | + sql += this->table_; | |
| 82 | 82 | sql += "\" where "; |
| 83 | - if (this->condition.size() == 0) | |
| 83 | + if (this->condition_.size() == 0) | |
| 84 | 84 | { |
| 85 | 85 | sql += "1=1"; |
| 86 | 86 | } |
| 87 | 87 | else |
| 88 | 88 | { |
| 89 | - sql += this->condition; | |
| 89 | + sql += this->condition_; | |
| 90 | 90 | } |
| 91 | - if (this->order.size() > 0) | |
| 91 | + if (this->order_.size() > 0) | |
| 92 | 92 | { |
| 93 | - sql += this->order; | |
| 93 | + sql += this->order_; | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | if (count_ <= 0) |
| ... | ... | @@ -106,4 +106,6 @@ namespace DmpWfs |
| 106 | 106 | return sql; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | + | |
| 110 | + | |
| 109 | 111 | } |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -20,15 +20,18 @@ namespace DmpWfs |
| 20 | 20 | ~DmpSqlFactory(void); |
| 21 | 21 | |
| 22 | 22 | void setStartIndexCount(int startIndex, int count, const std::string &resultType); |
| 23 | - void appendCondition(std::string &c); | |
| 23 | + void appendCondition(const std::string &c); | |
| 24 | 24 | void appendCondition(char *c); |
| 25 | + void setProp(const std::string& prop) { prop_ = prop; } | |
| 26 | + void setTable(const std::string& table){ table_ = table; } | |
| 27 | + void setOrder(const std::string& order){ order_ = order; } | |
| 25 | 28 | std::string getSql(); |
| 26 | 29 | |
| 27 | 30 | private: |
| 28 | - std::string prop; | |
| 29 | - std::string condition; | |
| 30 | - std::string order; | |
| 31 | - std::string table; | |
| 31 | + std::string prop_; | |
| 32 | + std::string condition_; | |
| 33 | + std::string order_; | |
| 34 | + std::string table_; | |
| 32 | 35 | |
| 33 | 36 | std::string resultType_; |
| 34 | 37 | int startIndex_; | ... | ... |
| ... | ... | @@ -6,15 +6,30 @@ |
| 6 | 6 | * Email: qingxiongf@chinadci.com |
| 7 | 7 | * copyright: 广州城市信息研究所有限公司 |
| 8 | 8 | ***************************************************************************/ |
| 9 | + | |
| 9 | 10 | #include "dmpwfsfilter.h" |
| 11 | + | |
| 12 | + | |
| 10 | 13 | namespace DmpWfs |
| 11 | 14 | { |
| 12 | 15 | |
| 13 | - dmpwfsfilter::dmpwfsfilter(/* args */) | |
| 16 | + DmpWfsFilter::DmpWfsFilter(/* args */) | |
| 14 | 17 | { |
| 15 | 18 | } |
| 16 | 19 | |
| 17 | - dmpwfsfilter::~dmpwfsfilter() | |
| 20 | + DmpWfsFilter::~DmpWfsFilter() | |
| 18 | 21 | { |
| 19 | 22 | } |
| 23 | + | |
| 24 | + bool DmpWfsFilter::Parse(const std::string& filter) | |
| 25 | + { | |
| 26 | + | |
| 27 | + return false; | |
| 28 | + } | |
| 29 | + | |
| 30 | + bool DmpWfsFilter::ParseOrder(const std::string& orderby) | |
| 31 | + { | |
| 32 | + return false; | |
| 33 | + } | |
| 34 | + | |
| 20 | 35 | } |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -9,19 +9,55 @@ |
| 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> | |
| 14 | +#include <boost/typeof/typeof.hpp> | |
| 15 | +#include <string> | |
| 16 | +#include "dmpwfsgmlobject.h" | |
| 12 | 17 | |
| 13 | 18 | namespace DmpWfs |
| 14 | 19 | { |
| 15 | - class dmpwfsfilter | |
| 16 | - { | |
| 20 | + class DmpWfsFilter | |
| 21 | + { | |
| 17 | 22 | public: |
| 18 | - dmpwfsfilter(/* args */); | |
| 19 | - ~dmpwfsfilter(); | |
| 23 | + DmpWfsFilter(/* args */); | |
| 24 | + ~DmpWfsFilter(); | |
| 25 | + | |
| 26 | + bool Parse(const std::string &filter); | |
| 27 | + bool ParseOrder(const std::string &orderby); | |
| 28 | + std::string getSql() const { return sql_; } | |
| 29 | + | |
| 20 | 30 | private: |
| 21 | - /* data */ | |
| 31 | + std::string sql_; | |
| 32 | + | |
| 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); | |
| 43 | + int pGeometryPointValue(char *p, std::vector<double> &v); | |
| 44 | + int pGeometryDouble(char *d, bool space_before, bool space_after, double &dbl); | |
| 45 | + int pGeometryPointValuePos(char *p, std::vector<double> &v); | |
| 46 | + int pGeometryPointValuePosList(boost::property_tree::ptree ptree, std::vector<double> &v); | |
| 47 | + 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); | |
| 52 | + private: | |
| 53 | + void GetQueryField(const char *field); | |
| 54 | + 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); | |
| 22 | 59 | }; |
| 23 | - | |
| 24 | - | |
| 60 | + | |
| 25 | 61 | } |
| 26 | 62 | |
| 27 | 63 | #endif // __dmpwfsfilter_h__ | ... | ... |
| ... | ... | @@ -8,6 +8,11 @@ |
| 8 | 8 | ***************************************************************************/ |
| 9 | 9 | #include "dmpwfsgetfeature.h" |
| 10 | 10 | #include "dmpsqlfactory.h" |
| 11 | +#include "dmpmapserverutil.h" | |
| 12 | +#include "dmpvectorlayer.h" | |
| 13 | +#include "dmpwfsfilter.h" | |
| 14 | +#include <string.h> | |
| 15 | + | |
| 11 | 16 | namespace DmpWfs |
| 12 | 17 | { |
| 13 | 18 | void writeGetFeature(const DmpServerContext &context,const DmpWfsParameters& params, |
| ... | ... | @@ -30,6 +35,11 @@ namespace DmpWfs |
| 30 | 35 | std::string featureID = params.FeatureID(); |
| 31 | 36 | std::string propertyName = params.PropertyName(); |
| 32 | 37 | std::string resultType = params.ResultType(); |
| 38 | + std::string filter = params.Filter(); | |
| 39 | + | |
| 40 | + std::string sortby = params.Sortby(); | |
| 41 | + | |
| 42 | + | |
| 33 | 43 | |
| 34 | 44 | sqlFactory.setStartIndexCount(startIndex, maxFeatures, resultType); |
| 35 | 45 | |
| ... | ... | @@ -38,95 +48,86 @@ namespace DmpWfs |
| 38 | 48 | { |
| 39 | 49 | char *idstring[1000]; |
| 40 | 50 | //将ID值以逗号分开,并返回个数 |
| 41 | - /* | |
| 42 | - int idn = StringHelp::ParseStringTok(parseString.featureid, ',', idstring, 1000); | |
| 43 | - for (int i = 0; i < idn; i++) | |
| 51 | + | |
| 52 | + vector<string> stringlist = mapserver::DmpMapServerUtil::stringSplit(propertyName, ","); | |
| 53 | + for (int i = 0; i < stringlist.size(); i++) | |
| 44 | 54 | { |
| 45 | 55 | char *ss[2]; |
| 46 | 56 | //形式:LayerName.ID |
| 47 | - int n = StringHelp::ParseStringTok(idstring[i], '.', ss, 2); | |
| 48 | - if (n == 2) | |
| 57 | + vector<string> stringList1 = mapserver::DmpMapServerUtil::stringSplit(idstring[i], "."); | |
| 58 | + // int n = StringHelp::ParseStringTok(idstring[i], '.', ss, 2); | |
| 59 | + if (stringList1.size() == 2) | |
| 49 | 60 | { |
| 50 | - if (parseString.layerName == 0) | |
| 61 | + if (typeName.empty()) | |
| 51 | 62 | { |
| 52 | - parseString.layerName = ss[0]; | |
| 63 | + typeName = stringList1[0]; | |
| 53 | 64 | } |
| 54 | - ids.push_back(ss[1]); | |
| 65 | + ids.push_back(stringList1[1]); | |
| 55 | 66 | } |
| 56 | - else if (n == 1) | |
| 67 | + else if (stringList1.size() == 1) | |
| 57 | 68 | { |
| 58 | - ids.push_back(ss[0]); | |
| 69 | + ids.push_back(stringList1[0]); | |
| 59 | 70 | } |
| 60 | 71 | } |
| 61 | - */ | |
| 62 | 72 | } |
| 63 | 73 | |
| 64 | - /* std::vector<std::string> props; | |
| 74 | + std::vector<std::string> props; | |
| 65 | 75 | std::vector<std::string> propsAs; |
| 66 | 76 | if (propertyName.empty()) |
| 67 | 77 | { |
| 68 | - char *idstring[1000]; | |
| 69 | - int idn = StringHelp::ParseStringTok(parseString.propertyname, ',', idstring, 1000); | |
| 70 | - for (int i = 0; i < idn; i++) | |
| 78 | + | |
| 79 | + vector<string> stringlist = mapserver::DmpMapServerUtil::stringSplit(propertyName, ","); | |
| 80 | + for (int i = 0; i < stringlist.size(); i++) | |
| 71 | 81 | { |
| 72 | - char *ss[2]; | |
| 82 | + // char *ss[2]; | |
| 73 | 83 | std::string sProp, sPropAs; |
| 74 | - int n = StringHelp::ParseStringTok(idstring[i], '.', ss, 2); | |
| 75 | - if (n == 2) | |
| 84 | + vector<string> layernameSplit = mapserver::DmpMapServerUtil::stringSplit(stringlist[i], "."); | |
| 85 | + if (layernameSplit.size() == 2) | |
| 76 | 86 | { |
| 77 | - if (parseString.layerName == 0) | |
| 87 | + if (typeName.empty()) | |
| 78 | 88 | { |
| 79 | - parseString.layerName = ss[0]; | |
| 89 | + typeName = layernameSplit[0]; | |
| 80 | 90 | } |
| 81 | 91 | //又以空格分开 |
| 82 | - StringHelp::GetAsStringSql(ss[1], sProp, sPropAs); | |
| 92 | + // StringHelp::GetAsStringSql(ss[1], sProp, sPropAs); | |
| 83 | 93 | props.push_back(sProp); |
| 84 | 94 | propsAs.push_back(sPropAs); |
| 85 | 95 | //sPropOrig=ss[1]; |
| 86 | 96 | } |
| 87 | - else if (n == 1) | |
| 97 | + else if (layernameSplit.size() == 1) | |
| 88 | 98 | { |
| 89 | - StringHelp::GetAsStringSql(ss[0], sProp, sPropAs); | |
| 99 | + // StringHelp::GetAsStringSql(ss[0], sProp, sPropAs); | |
| 90 | 100 | props.push_back(sProp); |
| 91 | 101 | propsAs.push_back(sPropAs); //props.push_back(ss[0]); |
| 92 | 102 | } |
| 93 | 103 | } |
| 94 | 104 | } |
| 95 | - */ | |
| 96 | - | |
| 97 | - // if (parseString.layerName == 0) | |
| 98 | - // return Error(buff, ErrorClass::ParaError, "layername not exist", ab); | |
| 99 | - | |
| 100 | - //const char *realLayer=0; | |
| 101 | - //GetUpLayerID是干什么的? | |
| 102 | - //似乎就是加了些L啊什么的。。 。 | |
| 103 | - // if (_GetUperLayerId(parseString.layerName, sLayer) == false) | |
| 104 | - // return Error(buff, ErrorClass::ParaError, "layer not exist", ab); | |
| 105 | + | |
| 105 | 106 | |
| 106 | - /* shared_ptr<MapLayer> mapLayer = service->GetLayer(parseString.layerName); | |
| 107 | + if (typeName.empty()) | |
| 108 | + { | |
| 109 | + return "layername not exist"; | |
| 110 | + } | |
| 107 | 111 | |
| 108 | - | |
| 112 | + DmpVectorLayer* mapLayer =(DmpVectorLayer*) project->getLayer(typeName);//GetLayer(parseString.layerName); | |
| 109 | 113 | if(mapLayer == nullptr) |
| 110 | 114 | { |
| 111 | - return Error(buff, ErrorClass::ParaError, "layer not find", ab); | |
| 115 | + return "layer not find"; | |
| 112 | 116 | } |
| 113 | 117 | |
| 114 | - shared_ptr<Workspace> pWorkspace = DataSourcePools::get_instance()->GetWorkspace(mapLayer->m_dbSource); | |
| 115 | - if(pWorkspace == nullptr) | |
| 118 | + shared_ptr<DmpPgsql> pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(mapLayer->source()); | |
| 119 | + if(pPgsqlConn == nullptr) | |
| 116 | 120 | { |
| 117 | - return Error(buff, ErrorClass::DatabaseDisconnect, "连接数据库失败", ab); | |
| 121 | + return "连接数据库失败"; | |
| 118 | 122 | } |
| 119 | - shared_ptr<dmapFields> fields = pWorkspace->GetFields(mapLayer->m_layerName,""); | |
| 123 | + // shared_ptr<dmapFields> fields = pWorkspace->GetFields(mapLayer->m_layerName,""); | |
| 120 | 124 | |
| 121 | - if(fields == nullptr) | |
| 125 | + //if(fields == nullptr) | |
| 122 | 126 | { |
| 123 | - return Error(buff, ErrorClass::ParaError, "layername not exist", ab); | |
| 127 | + //return Error(buff, ErrorClass::ParaError, "layername not exist", ab); | |
| 124 | 128 | } |
| 125 | 129 | |
| 126 | - | |
| 127 | - | |
| 128 | - | |
| 129 | - shared_ptr<TableDesc> pTabledesc = this->ToTableDesc(fields,mapLayer->m_layerName); | |
| 130 | + // shared_ptr<TableDesc> pTabledesc = this->ToTableDesc(fields,mapLayer->m_layerName); | |
| 130 | 131 | |
| 131 | 132 | |
| 132 | 133 | size_t propCount = props.size(); |
| ... | ... | @@ -145,63 +146,62 @@ namespace DmpWfs |
| 145 | 146 | { |
| 146 | 147 | sleft = s.substr(0, at1); |
| 147 | 148 | sright = s.substr(at1 + 1, s.length() - 2 - at1); |
| 148 | - if (_stricmp(sleft.c_str(), "distinct") == 0) | |
| 149 | + if (boost::iequals(sleft, "distinct")) | |
| 149 | 150 | { |
| 150 | - sF = sF + sleft + " " + fields->GetFieldQuery(sright.c_str()); | |
| 151 | + // sF = sF + sleft + " " + fields->GetFieldQuery(sright.c_str()); | |
| 151 | 152 | } |
| 152 | 153 | else |
| 153 | 154 | { |
| 154 | - sF = sF + sleft + "(" + fields->GetFieldQuery(sright.c_str()) + ")"; | |
| 155 | + // sF = sF + sleft + "(" + fields->GetFieldQuery(sright.c_str()) + ")"; | |
| 155 | 156 | } |
| 156 | 157 | } |
| 157 | 158 | else |
| 158 | 159 | { |
| 159 | - sF = sF + fields->GetFieldQuery(s.c_str()); | |
| 160 | + // sF = sF + fields->GetFieldQuery(s.c_str()); | |
| 160 | 161 | } |
| 161 | 162 | |
| 162 | 163 | } |
| 163 | - sqlF.prop = sF; | |
| 164 | + | |
| 165 | + sqlFactory.setProp(sF); | |
| 164 | 166 | } |
| 165 | 167 | else |
| 166 | 168 | { |
| 167 | - bool isJson = (parseString.format && (strcmpi(parseString.format, "geojson") ==0 || strcmpi(parseString.format, "json") ==0)); | |
| 168 | - this->GetAllField( srsOut, sqlF.prop,mapLayer,pWorkspace,isJson); | |
| 169 | + // bool isJson = (parseString.format && (strcmpi(parseString.format, "geojson") ==0 || strcmpi(parseString.format, "json") ==0)); | |
| 170 | + // this->GetAllField( srsOut, sqlF.prop,mapLayer,pWorkspace,isJson); | |
| 169 | 171 | } |
| 170 | 172 | |
| 171 | 173 | size_t idCount = ids.size(); |
| 172 | 174 | |
| 173 | - | |
| 174 | - | |
| 175 | - if (parseString.filter) | |
| 175 | + | |
| 176 | + if (!filter.empty()) | |
| 176 | 177 | { |
| 177 | - clsFilter filter(mapLayer->m_srid); | |
| 178 | + DmpWfsFilter wfsFilter; | |
| 178 | 179 | |
| 179 | - if (filter.Parse(parseString.filter, pTabledesc.get(),DatabaseTypePostgreSQL)) | |
| 180 | + if(wfsFilter.Parse(filter)) | |
| 180 | 181 | { |
| 181 | - return Error(buff, ErrorClass::FilterError, filter.err, ab); | |
| 182 | + return "解析查询器错误"; | |
| 182 | 183 | } |
| 183 | 184 | |
| 184 | - sqlF.AppendCondition(filter.sql); | |
| 185 | + sqlFactory.appendCondition(wfsFilter.getSql()); | |
| 185 | 186 | } |
| 186 | - if (parseString.sortby) | |
| 187 | + | |
| 188 | + if (!sortby.empty()) | |
| 187 | 189 | { |
| 188 | - clsFilter filter(mapLayer->m_srid); | |
| 189 | - if (filter.ParseOrder(parseString.sortby, pTabledesc.get(), DatabaseTypePostgreSQL)) | |
| 190 | + DmpWfsFilter wfsFilter; | |
| 191 | + if (wfsFilter.ParseOrder(sortby)) | |
| 190 | 192 | { |
| 191 | - return Error(buff, ErrorClass::SortError, filter.err, ab); | |
| 193 | + return "参数sortby 解析错误!"; | |
| 192 | 194 | } |
| 193 | - sqlF.order = filter.sql; | |
| 195 | + sqlFactory.setOrder(wfsFilter.getSql()); | |
| 194 | 196 | } |
| 195 | - sqlF.table = mapLayer->m_layerName; | |
| 196 | - std::string sq = sqlF.GetSql(DatabaseTypePostgreSQL); | |
| 197 | - | |
| 198 | - bool returnResult = pWorkspace->ExecWaitBinary(sq); | |
| 199 | - if (!returnResult) | |
| 197 | + sqlFactory.setTable(mapLayer->name()); | |
| 198 | + std::string sql = sqlFactory.getSql(); | |
| 199 | + if (!pPgsqlConn->ExecWaitBinary(sql)) | |
| 200 | 200 | { |
| 201 | - return Error(buff, ErrorClass::QueryError, pWorkspace->m_sError.c_str(), ab); | |
| 201 | + return "查询错误:" + pPgsqlConn->error(); | |
| 202 | 202 | } |
| 203 | - int ver = ParseString::GetGMLVersion(parseString.version, parseString.outputFormat); | |
| 204 | - if (parseString.format && (strcmpi(parseString.format, "geojson") ==0|| strcmpi(parseString.format, "json")==0)) | |
| 203 | + // int ver = ParseString::GetGMLVersion(parseString.version, parseString.outputFormat); | |
| 204 | + /* if (parseString.format && (strcmpi(parseString.format, "geojson") ==0|| strcmpi(parseString.format, "json")==0)) | |
| 205 | 205 | { |
| 206 | 206 | isPicture = 10; |
| 207 | 207 | return this->FormatWFSJsonCAll(pWorkspace, ab, parseString.layerName, buff, ver); |
| ... | ... | @@ -214,6 +214,20 @@ namespace DmpWfs |
| 214 | 214 | return ""; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - | |
| 218 | - | |
| 217 | + void getAsStringSql(const string& str, std::string &sProp, std::string &sAs) | |
| 218 | + { | |
| 219 | + //char *ss[2]; | |
| 220 | + vector<string> layernameSplit = mapserver::DmpMapServerUtil::stringSplit(str, "."); | |
| 221 | + //int n = ParseStringTok(str, ' ', ss, 2); | |
| 222 | + if (layernameSplit.size() == 1) | |
| 223 | + { | |
| 224 | + sProp = layernameSplit[0]; | |
| 225 | + sAs = ""; | |
| 226 | + } | |
| 227 | + else if (layernameSplit.size() > 1) | |
| 228 | + { | |
| 229 | + sProp = layernameSplit[0]; | |
| 230 | + sAs = layernameSplit[1]; | |
| 231 | + } | |
| 232 | + } | |
| 219 | 233 | } |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -14,11 +14,12 @@ |
| 14 | 14 | #include <boost/typeof/typeof.hpp> |
| 15 | 15 | #include <memory> |
| 16 | 16 | #include <vector> |
| 17 | +#include <string> | |
| 17 | 18 | #include "dmpproject.h" |
| 18 | 19 | #include "dmpwfsparameters.h" |
| 19 | 20 | #include "dmpservercontext.h" |
| 20 | 21 | #include "dmppgsqlsourcepools.h" |
| 21 | - | |
| 22 | +using namespace mapserver; | |
| 22 | 23 | namespace DmpWfs |
| 23 | 24 | { |
| 24 | 25 | void writeGetFeature(const DmpServerContext &context,const DmpWfsParameters& params, |
| ... | ... | @@ -29,7 +30,9 @@ namespace DmpWfs |
| 29 | 30 | // const DmpProject* project, |
| 30 | 31 | // bool projectSettings = false); |
| 31 | 32 | |
| 32 | - | |
| 33 | + | |
| 34 | + void getAsStringSql(const string& str,std::string &sProp,std::string &sAs); | |
| 35 | + | |
| 33 | 36 | } |
| 34 | 37 | |
| 35 | 38 | #endif // __dmpwfsgetfeature_h__ | ... | ... |
| 1 | +/************************************************************************** | |
| 2 | +* file: dmpwfsgmlobject.cpp | |
| 3 | + | |
| 4 | +* Author: qingxiongf | |
| 5 | +* Date: 2022-01-06 13:39:11 | |
| 6 | +* Email: qingxiongf@chinadci.com | |
| 7 | +* copyright: 广州城市信息研究所有限公司 | |
| 8 | +***************************************************************************/ | |
| 9 | + | |
| 10 | +#include "dmpwfsgmlobject.h" | |
| 11 | + | |
| 12 | + | |
| 13 | + DmpWfsGmlObject::DmpWfsGmlObject() | |
| 14 | +{ | |
| 15 | + | |
| 16 | +} | |
| 17 | + | |
| 18 | + | |
| 19 | + ~DmpWfsGmlObject::DmpWfsGmlObject() | |
| 20 | +{ | |
| 21 | + | |
| 22 | +} | |
| \ No newline at end of file | ... | ... |
| 1 | +/************************************************************************** | |
| 2 | +* file: dmpwfsgmlobject.h | |
| 3 | + | |
| 4 | +* Author: qingxiongf | |
| 5 | +* Date: 2022-01-06 13:39:03 | |
| 6 | +* Email: qingxiongf@chinadci.com | |
| 7 | +* copyright: 广州城市信息研究所有限公司 | |
| 8 | +***************************************************************************/ | |
| 9 | + | |
| 10 | +#ifndef __dmpwfsgmlobject_h__ | |
| 11 | +#define __dmpwfsgmlobject_h__ | |
| 12 | +#include <string> | |
| 13 | + | |
| 14 | +namespace DmpWfs | |
| 15 | +{ | |
| 16 | + class DmpWfsGmlObject | |
| 17 | + { | |
| 18 | + public: | |
| 19 | + DmpWfsGmlObject(void); | |
| 20 | + | |
| 21 | + public: | |
| 22 | + ~DmpWfsGmlObject(void); | |
| 23 | + | |
| 24 | + public: | |
| 25 | + virtual void getString(std::string &str) = 0; | |
| 26 | + virtual void getObj(void *sg) = 0; | |
| 27 | + virtual void getRect(double &x1, double &y1, double &x2, double &y2) = 0; | |
| 28 | + }; | |
| 29 | + | |
| 30 | + class DmpWfsGmlPoint : public DmpWfsGmlObject | |
| 31 | + { | |
| 32 | + public: | |
| 33 | + DmpWfsGmlPoint(void); | |
| 34 | + DmpWfsGmlPoint(double x, double y); | |
| 35 | + ~DmpWfsGmlPoint(void); | |
| 36 | + | |
| 37 | + public: | |
| 38 | + void getObj(void *sg); | |
| 39 | + void getString(std::string &s); | |
| 40 | + void getRect(double &x11, double &y11, double &x22, double &y22); | |
| 41 | + | |
| 42 | + private: | |
| 43 | + double x; | |
| 44 | + double y; | |
| 45 | + }; | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | +} | |
| 51 | + | |
| 52 | +#endif // __dmpwfsgmlobject_h__ | ... | ... |
请
注册
或
登录
后发表评论