提交 7ddd0ecd46b6c9ae2d4823850e5e1ca19893982e

作者 qingxiongf
1 个父辈 0e4c22ef

getfeatueinfo2

... ... @@ -4,6 +4,7 @@
4 4
5 5 SET (MAPSERVER_SRCS
6 6 dmpmapserver.cpp
  7 + dmpmapserverutil.cpp
7 8 dmppgsql.cpp
8 9 dmppgsqlpool.cpp
9 10 dmppgsqlsourcepools.cpp
... ... @@ -12,10 +13,12 @@ SET (MAPSERVER_SRCS
12 13 wms/dmpwmsparameters.cpp
13 14 wms/dmpwmsgetcapabilities.cpp
14 15 wms/dmpwmsgetmap.cpp
  16 + wms/dmpwmsgetfeatureinfo.cpp
15 17 )
16 18
17 19 SET (MAPSERVER_HDRS
18 20 dmpmapserver.h
  21 + dmpmapserverutil.h
19 22 dmppgsql.h
20 23 dmppgsqlpool.h
21 24 dmppgsqlsourcepools.h
... ... @@ -24,6 +27,7 @@ SET (MAPSERVER_HDRS
24 27 wms/dmpwmsparameters.h
25 28 wms/dmpwmsgetcapabilities.h
26 29 wms/dmpwmsgetmap.h
  30 + wms/dmpwmsgetfeatureinfo.h
27 31 )
28 32
29 33 ########################################################
... ...
  1 +/**************************************************************************
  2 +* file: dmpmapserverutil.cpp
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-21 11:02:18
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include "dmpmapserverutil.h"
  10 +#include <string.h>
  11 +
  12 +namespace mapserver
  13 +{
  14 +
  15 + //以GeoJson的形式返回
  16 +void DmpMapServerUtil::responseGeojson(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const string& srid)
  17 +{
  18 + double xg1, yg1, xg2, yg2;
  19 + int havegSet = 0;
  20 + int count = 0;
  21 + int pointCountTemp = 0;
  22 + std::string stringTime;
  23 + char buff[5000] = {0};
  24 +
  25 + responseData.append(R"({"type":"FeatureCollection","features":[)");
  26 + try
  27 + {
  28 + int fieldsCount = pPgsqlConn->GetFieldCount();
  29 + for (int featureIndex = 0; pPgsqlConn->next(); featureIndex++)
  30 + {
  31 +
  32 + if (featureIndex > 0)
  33 + responseData.append(",");
  34 + //ab->AppendString(R"({"type":"Feature")");
  35 +
  36 + string geometry = "";
  37 + string properties = "";
  38 +
  39 + for (int i = 0; i < fieldsCount; i++)
  40 + {
  41 + const char *sfieldName = pPgsqlConn->GetFieldName(i); //pPgsqlConn->field_name[i].c_str();
  42 + if (sfieldName == 0)
  43 + {
  44 + break;
  45 + }
  46 +
  47 + if (strncmp(sfieldName, "RN_RN", 5) == 0)
  48 + continue;
  49 + std::string strFieldName = sfieldName;
  50 + //XML转义
  51 + DmpMapServerUtil::toJsonString(strFieldName);
  52 + sfieldName = strFieldName.c_str();
  53 +
  54 + if (strFieldName == "geometry_as_geojson")
  55 + {
  56 + geometry = pPgsqlConn->getString(i);
  57 + continue;
  58 + }
  59 + else
  60 + {
  61 + const char *v = pPgsqlConn->getString(i);
  62 + std::sprintf(buff, R"(,"%s":"%s")", sfieldName, v);
  63 + properties += buff;
  64 + }
  65 + }
  66 +
  67 + if (geometry != "")
  68 + {
  69 + responseData.append(R"(,"geometry":)");
  70 + responseData.append(geometry.c_str());
  71 + }
  72 +
  73 + if (properties != "")
  74 + {
  75 + responseData.append(R"(,"properties":)");
  76 + properties[0] = '{';
  77 + responseData.append(properties.c_str());
  78 + responseData.append("}");
  79 + }
  80 + responseData.append("}");
  81 + count++;
  82 + }
  83 + }
  84 + catch (...)
  85 + {
  86 + return;
  87 + }
  88 +
  89 + responseData.append("]}");
  90 +
  91 + return;
  92 +}
  93 +
  94 +
  95 + void DmpMapServerUtil::toJsonString(std::string &s)
  96 + {
  97 + const char *str1 = s.c_str();
  98 + if (strstr(str1, "\\"))
  99 + {
  100 + s = replace(s, "\\", "\\\\");
  101 + str1 = s.c_str();
  102 + }
  103 + if (strstr(str1, "/"))
  104 + {
  105 + s = replace(s, "/", "\\/");
  106 + str1 = s.c_str();
  107 + }
  108 + if (strstr(str1, "\""))
  109 + {
  110 + s = replace(s, "\"", "\\\"");
  111 + str1 = s.c_str();
  112 + }
  113 + if (strstr(str1, "\\r"))
  114 + {
  115 + s = replace(s, "\\r", "");
  116 + str1 = s.c_str();
  117 + }
  118 + if (strstr(str1, "\\n"))
  119 + {
  120 + s = replace(s, "\\n", "");
  121 + str1 = s.c_str();
  122 + }
  123 + if (strstr(str1, "\r"))
  124 + {
  125 + s = replace(s, "\r", "");
  126 + str1 = s.c_str();
  127 + }
  128 + if (strstr(str1, "\n"))
  129 + {
  130 + s = replace(s, "\n", "");
  131 + str1 = s.c_str();
  132 + }
  133 + if (strstr(str1, "\t"))
  134 + {
  135 + s = replace(s, "'", "\\t");
  136 + }
  137 + return;
  138 + }
  139 +
  140 + std::string DmpMapServerUtil::replace(std::string strsrc, std::string strfind, std::string strrep)
  141 + {
  142 + for(std::string::size_type pos(0); pos!=std::string::npos;pos+=strrep.length())
  143 + {
  144 + if((pos=strsrc.find(strfind,pos))!=std::string::npos)
  145 + strsrc.replace(pos,strfind.length(),strrep);
  146 + else
  147 + break;
  148 + }
  149 + return strsrc;
  150 + }
  151 +}
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: dmpmapserverutil.h
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-21 11:02:10
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __dmpmapserverutil_h__
  11 +#define __dmpmapserverutil_h__
  12 +
  13 +#include <string>
  14 +#include <memory>
  15 +#include "dmppgsqlsourcepools.h"
  16 +
  17 +namespace mapserver
  18 +{
  19 + class DmpMapServerUtil
  20 + {
  21 + public:
  22 + static void responseGeojson(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const std::string &srid);
  23 + static void toJsonString(std::string &s);
  24 + static std::string replace(std::string strsrc, std::string strfind, std::string strrep);
  25 + };
  26 +}
  27 +
  28 +#endif // __dmpmapserverutil_h__
... ...
... ... @@ -234,8 +234,28 @@ namespace mapserver
234 234
235 235 bool DmpPgsql::TryReconn()
236 236 {
237   - if (Connect(this->sConnInfo_.c_str()))return true;
  237 + if (Connect(this->sConnInfo_.c_str()))
  238 + return true;
238 239 return false;
239 240 }
240 241
  242 + int DmpPgsql::GetRowCount()
  243 + {
  244 + return PQnparams(pPGresult_);
  245 + }
  246 +
  247 + int DmpPgsql::GetFieldCount()
  248 + {
  249 + return PQnfields(pPGresult_);
  250 + }
  251 +
  252 + char *DmpPgsql::GetFieldName(int index)
  253 + {
  254 + return PQfname(pPGresult_, index);
  255 + }
  256 +
  257 + int DmpPgsql::GetFieldType(int index)
  258 + {
  259 + return PQftype(pPGresult_, index);
  260 + }
241 261 }
\ No newline at end of file
... ...
... ... @@ -61,10 +61,11 @@ namespace mapserver
61 61
62 62 PGresult* GetPGresult(){ return pPGresult_;}
63 63
64   - // int GetRowCount();
65   - // int GetFieldCount();
66   - // char *GetFieldName(int index);
67   - // int GetFieldType(int index);
  64 +
  65 + int GetRowCount();
  66 + int GetFieldCount();
  67 + char* GetFieldName(int index);
  68 + int GetFieldType(int index);
68 69 public:
69 70
70 71 //void PrepareFieldhead();
... ...
... ... @@ -6,7 +6,7 @@
6 6 * Email: qingxiongf@chinadci.com
7 7 * copyright: 广州城市信息研究所有限公司
8 8 ***************************************************************************/
9   -#include "dmpwmsgetcapabilities.h"
  9 +#include "dmpwmsgetfeatureinfo.h"
10 10 #include "dmpwmsrenderer.h"
11 11 #include "dmpserverresponse.h"
12 12 #include "dmpserverrequest.h"
... ... @@ -14,74 +14,73 @@
14 14 #include <memory>
15 15 namespace DmpWms
16 16 {
17   - void writeFeatureInfo(const DmpServerContext &context,const DmpWmsParameters& params,
18   - const DmpProject* project,
19   - bool projectSettings )
20   - {
21   - string exception = WmsGetMap(context,params, project,projectSettings);
22   - if(exception.length() >0)
  17 + void writeFeatureInfo(const DmpServerContext &context, const DmpWmsParameters &params,
  18 + const DmpProject *project,
  19 + bool projectSettings)
  20 + {
  21 + string exception = WmsGetFeatureInfo(context, params, project, projectSettings);
  22 + if (exception.length() > 0)
23 23 {
24   -
25 24 }
26   - }
  25 + }
27 26
28   -
29   - std::string WmsGetFeatureInfo(const DmpServerContext &context, const DmpWmsParameters& params,
30   - const DmpProject* project, bool projectSettings)
31   - {
32   - try
  27 + std::string WmsGetFeatureInfo(const DmpServerContext &context, const DmpWmsParameters &params,
  28 + const DmpProject *project, bool projectSettings)
  29 + {
  30 + try
33 31 {
34   -
  32 +
35 33 double boxX1, boxY1, boxX2, boxY2;
36   - std::string srs = params.Srs();
37   - std::string recbox = params.BBox();
  34 + std::string srs = params.Srs();
  35 + std::string recbox = params.BBox();
38 36
39   - int width = params.Width();
40   - int height = params.Height();
  37 + int width = params.Width();
  38 + int height = params.Height();
41 39
42   - if (boost::iequals(srs, "CRS:84")|| boost::iequals(srs, "EPSG:4326"))
  40 + if (boost::iequals(srs, "CRS:84") || boost::iequals(srs, "EPSG:4326"))
43 41 {
44   - sscanf(recbox.c_str(), "%lf,%lf,%lf,%lf", &boxY1, &boxX1, &boxY2, &boxX2);
  42 + sscanf(recbox.c_str(), "%lf,%lf,%lf,%lf", &boxY1, &boxX1, &boxY2, &boxX2);
45 43 }
46 44 else
47 45 {
48   - sscanf(recbox.c_str(), "%lf,%lf,%lf,%lf", &boxX1, &boxY1, &boxX2, &boxY2);
  46 + sscanf(recbox.c_str(), "%lf,%lf,%lf,%lf", &boxX1, &boxY1, &boxX2, &boxY2);
49 47 }
50   -
  48 +
51 49 //stbstb:应该检查大量地方的 width和height不为零 ,char* regionDefs
52   - if (width <= 0 || height <= 0) return "width和height 参数错误";
53   -
  50 + if (width <= 0 || height <= 0)
  51 + return "width和height 参数错误";
  52 +
54 53 DmpWms::DmpWmsRenderer mapRenderer(height, width);
55 54
56   - std::string layers = params.QueryLayers();
57   - if (layers !="")
  55 + std::string layers = params.QueryLayers();
  56 + if (layers != "")
58 57 {
59 58 mapRenderer.AddWmsMapLayers(project);
60 59 }
61 60 else
62 61 {
63 62 char strlayers[1000] = {0};
64   - strcpy(strlayers,(char *)layers.c_str());
  63 + strcpy(strlayers, (char *)layers.c_str());
65 64 mapRenderer.AddWmsMapLayers(project, strlayers);
66 65 }
67 66
68   - int x = params.X();
69   - int y = params.Y();
70   - int featureCount = params.FeatureCount();
71   -
72   - shared_ptr<Rect> rect (new Rect(boxY2, boxX2, boxY1, boxX1));
  67 + int x = params.X();
  68 + int y = params.Y();
  69 + int featureCount = params.FeatureCount();
  70 +
  71 + shared_ptr<Rect> rect(new Rect(boxY2, boxX2, boxY1, boxX1));
73 72 mapRenderer.SetExtent(rect);
74   - string responseData;
75   - mapRenderer.GetFeatureInfo(responseData, "", x, y,featureCount);
  73 + string responseData;
  74 + mapRenderer.GetFeatureInfo(responseData, x, y, featureCount);
76 75 context.response()->removeHeader("Content-Type");
77   - context.response()->setHeader("Content-Type", "image/png");
  76 + context.response()->setHeader("Content-Type", "image/png");
78 77 context.response()->write(responseData);
79 78 return "";
80 79 }
81 80 catch (const std::exception &e)
82 81 {
83 82 std::cerr << " GetMap " << e.what() << '\n';
84   - return e.what();
  83 + return e.what();
85 84 }
86   - }
  85 + }
87 86 }
\ No newline at end of file
... ...
... ... @@ -6,36 +6,40 @@
6 6 * Email: qingxiongf@chinadci.com
7 7 * copyright: 广州城市信息研究所有限公司
8 8 ***************************************************************************/
  9 +#include <boost/property_tree/ptree.hpp>
  10 +#include <boost/property_tree/xml_parser.hpp>
  11 +#include <boost/typeof/typeof.hpp>
9 12 #include "dmpwmsrenderer.h"
  13 +#include "dmpmapserverutil.h"
10 14 #include <sstream>
11 15 #include <stdarg.h>
12 16 #include <set>
13 17 #include <png.h>
14 18 #include <math.h>
  19 +
15 20 namespace DmpWms
16 21 {
17 22 static cairo_status_t cairo_write_func(void *pbuff, const unsigned char *data, unsigned int length)
18 23 {
19   - std::string* responseData = (std::string*)pbuff;
20   - responseData->append((char*)data,length);
  24 + std::string *responseData = (std::string *)pbuff;
  25 + responseData->append((char *)data, length);
21 26 return CAIRO_STATUS_SUCCESS;
22 27 }
23 28
24 29 static void png_write_data_to_buffer(png_structp png_ptr, png_bytep data, png_size_t length)
25 30 {
26   -
27   - std::string* responseData = (std::string*)png_get_io_ptr(png_ptr);
28   - responseData->append((char*)data,length);
  31 +
  32 + std::string *responseData = (std::string *)png_get_io_ptr(png_ptr);
  33 + responseData->append((char *)data, length);
29 34 }
30 35
31 36 static void png_flush_data(png_structp png_ptr)
32   - {
33   -
34   - }
  37 + {
  38 + }
35 39
36   - DmpWmsRenderer::DmpWmsRenderer(double height, double width)
37   - {
38   - rasterBufferObj* rb = (rasterBufferObj*)malloc(sizeof(rasterBufferObj));
  40 + DmpWmsRenderer::DmpWmsRenderer(double height, double width)
  41 + {
  42 + rasterBufferObj *rb = (rasterBufferObj *)malloc(sizeof(rasterBufferObj));
39 43 initializeRasterBufferCairo(rb, width, height);
40 44
41 45 pRasterBufferObj = rb;
... ... @@ -47,9 +51,9 @@ namespace DmpWms
47 51 m_vLayers = {};
48 52 m_WMSServers = {};
49 53 m_iN = 1;
50   - m_iBackColor = 0xffffffff; //背景默认白色
51   - cairo_surface_t *surface = cairo_image_surface_create_for_data(rb->data.rgba.pixels,
52   - CAIRO_FORMAT_ARGB32, (int)m_dWidth, (int)m_dHeight,rb->data.rgba.row_step); //cairo_win32_surface_create(hdc);
  54 + m_iBackColor = 0xffffffff; //背景默认白色
  55 + cairo_surface_t *surface = cairo_image_surface_create_for_data(rb->data.rgba.pixels,
  56 + CAIRO_FORMAT_ARGB32, (int)m_dWidth, (int)m_dHeight, rb->data.rgba.row_step); //cairo_win32_surface_create(hdc);
53 57 m_pClsSurfDC = new clsCrSurf(surface);
54 58 cairo_surface_t *surfaceBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (int)m_dWidth, (int)m_dHeight);
55 59 m_pClsSurfBuff = new clsCrSurf(surfaceBuffer);
... ... @@ -57,33 +61,33 @@ namespace DmpWms
57 61 m_pClsMaxSurfBuffer = new clsCrSurf(maxSurfaceBuffer);
58 62
59 63 m_pExtent = shared_ptr<Rect>(new Rect(0, 0, 0, 0));
60   - }
61   -
62   - int DmpWmsRenderer::initializeRasterBufferCairo(rasterBufferObj *rb, int width, int height)
63   - {
64   - rb->type = MS_BUFFER_BYTE_RGBA;
65   - rb->width = width;
66   - rb->height = height;
67   - rb->data.rgba.pixel_step = 4;
68   - rb->data.rgba.row_step = width * 4;
69   - rb->data.rgba.pixels = (unsigned char*)calloc(width*height*4,sizeof(unsigned char));
70   - rb->data.rgba.r = &(rb->data.rgba.pixels[2]);
71   - rb->data.rgba.g = &(rb->data.rgba.pixels[1]);
72   - rb->data.rgba.b = &(rb->data.rgba.pixels[0]);
73   - rb->data.rgba.a = &(rb->data.rgba.pixels[3]);
74   - return MS_SUCCESS;
75   - }
  64 + }
  65 +
  66 + int DmpWmsRenderer::initializeRasterBufferCairo(rasterBufferObj *rb, int width, int height)
  67 + {
  68 + rb->type = MS_BUFFER_BYTE_RGBA;
  69 + rb->width = width;
  70 + rb->height = height;
  71 + rb->data.rgba.pixel_step = 4;
  72 + rb->data.rgba.row_step = width * 4;
  73 + rb->data.rgba.pixels = (unsigned char *)calloc(width * height * 4, sizeof(unsigned char));
  74 + rb->data.rgba.r = &(rb->data.rgba.pixels[2]);
  75 + rb->data.rgba.g = &(rb->data.rgba.pixels[1]);
  76 + rb->data.rgba.b = &(rb->data.rgba.pixels[0]);
  77 + rb->data.rgba.a = &(rb->data.rgba.pixels[3]);
  78 + return MS_SUCCESS;
  79 + }
76 80
77 81 DmpWmsRenderer::~DmpWmsRenderer()
78 82 {
79 83 m_vLayers.clear();
80   - if(this->pRasterBufferObj)
  84 + if (this->pRasterBufferObj)
81 85 {
82 86 cairo_surface_finish(m_pClsSurfDC->m_pSurf);
83   - if( this->pRasterBufferObj->data.rgba.pixels)
  87 + if (this->pRasterBufferObj->data.rgba.pixels)
84 88 {
85 89 free(this->pRasterBufferObj->data.rgba.pixels);
86   - this->pRasterBufferObj->data.rgba.pixels = nullptr;
  90 + this->pRasterBufferObj->data.rgba.pixels = nullptr;
87 91 }
88 92 free(this->pRasterBufferObj);
89 93 this->pRasterBufferObj = nullptr;
... ... @@ -107,7 +111,7 @@ namespace DmpWms
107 111 }
108 112 }
109 113
110   - std::string DmpWmsRenderer::format(const char *fmt, ...)
  114 + std::string DmpWmsRenderer::format(const char *fmt, ...)
111 115 {
112 116 va_list argptr;
113 117 int cnt;
... ... @@ -121,9 +125,7 @@ namespace DmpWms
121 125 return buffer;
122 126 }
123 127
124   -
125   -
126   - string DmpWmsRenderer::GetDrawSQL(DmpVectorLayer* layer, Rect *pRect, const char *layerdef)
  128 + string DmpWmsRenderer::GetDrawSQL(DmpVectorLayer *layer, Rect *pRect, const char *layerdef)
127 129 {
128 130 if (layer == 0 || layer->geom().size() == 0)
129 131 return "";
... ... @@ -131,7 +133,7 @@ namespace DmpWms
131 133 //char sql[6000];
132 134 string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
133 135
134   - shared_ptr<Renderer> renderer = layer->GetRenderer30();
  136 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
135 137
136 138 // int renType = renderer->RendererType();
137 139 vector<string> vFieldName;
... ... @@ -166,18 +168,16 @@ namespace DmpWms
166 168 ss += " and ";
167 169 ss += layerdef;
168 170 }
169   - ss += format(" limit %d ",MAXCOUNT);
  171 + ss += format(" limit %d ", MAXCOUNT);
170 172 //ss += " limit 40000 ";
171 173
172 174 double t = pRect->m_dTop, r = pRect->m_dRight, b = pRect->m_dBottom, l = pRect->m_dLeft;
173 175 std::string sql = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(), tableName.c_str(), shapeName.c_str(), l, b, r, t);
174   - //printf("%s\r\n",sql.c_str());
  176 + //printf("%s\r\n",sql.c_str());
175 177 return sql;
176 178 }
177 179
178   -
179   -
180   - string DmpWmsRenderer::GetRegionQuerySQL(DmpVectorLayer* layer,Rect *pRect,string srid, const char *regionDef,const char *layerdef)
  180 + string DmpWmsRenderer::GetRegionQuerySQL(DmpVectorLayer *layer, Rect *pRect, string srid, const char *regionDef, const char *layerdef)
181 181 {
182 182 if (layer == 0 || layer->geom().size() == 0)
183 183 return "";
... ... @@ -186,69 +186,65 @@ namespace DmpWms
186 186 if (pPgsqlConn != nullptr)
187 187 {
188 188 double t = pRect->m_dTop, r = pRect->m_dRight, b = pRect->m_dBottom, l = pRect->m_dLeft;
189   - // if(pPgsqlConn->ExecWait(sql.c_str()) && pPgsqlConn->next())
190   - {
191   - // const char * polygon = pPgsqlConn->getString(0);
192   - string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
  189 + // if(pPgsqlConn->ExecWait(sql.c_str()) && pPgsqlConn->next())
  190 + {
  191 + // const char * polygon = pPgsqlConn->getString(0);
  192 + string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
193 193
194   - shared_ptr<Renderer> renderer = layer->GetRenderer30();
  194 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
195 195
196   - // int renType = renderer->RendererType();
197   - vector<string> vFieldName;
198   - renderer->TryAddField(vFieldName);
  196 + // int renType = renderer->RendererType();
  197 + vector<string> vFieldName;
  198 + renderer->TryAddField(vFieldName);
199 199
200   - int length = (int)(vFieldName.size());
201   - for (int i = 0; i < length; i++)
202   - {
203   - string filename = vFieldName[i];
204   - ss += ",\"" + (filename) + "\"::varchar ";
205   - }
  200 + int length = (int)(vFieldName.size());
  201 + for (int i = 0; i < length; i++)
  202 + {
  203 + string filename = vFieldName[i];
  204 + ss += ",\"" + (filename) + "\"::varchar ";
  205 + }
206 206
207   - string tableName = layer->name(); //layer->name();
208   - string shapeName = layer->geom();
209   - shared_ptr<DmpVectorThinLayer> pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR);
  207 + string tableName = layer->name(); //layer->name();
  208 + string shapeName = layer->geom();
  209 + shared_ptr<DmpVectorThinLayer> pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR);
210 210
211   - if (pVectorThinLayer != nullptr)
212   - {
213   - tableName = pVectorThinLayer->tableName();
214   - }
  211 + if (pVectorThinLayer != nullptr)
  212 + {
  213 + tableName = pVectorThinLayer->tableName();
  214 + }
215 215
216   - ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
217   - ss += " WHERE ST_Intersects( (select (ST_Intersection(ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),'%s'::Geometry)) ),\"%s\" )";
218   - if (layer->wherestr().length() > 0)
219   - {
220   - ss += " and ";
221   - ss += layer->wherestr();
222   - }
  216 + ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
  217 + ss += " WHERE ST_Intersects( (select (ST_Intersection(ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),'%s'::Geometry)) ),\"%s\" )";
  218 + if (layer->wherestr().length() > 0)
  219 + {
  220 + ss += " and ";
  221 + ss += layer->wherestr();
  222 + }
223 223
224 224 if (layerdef != nullptr && strcmp(layerdef, "") != 0)
225 225 {
226 226 ss += " and ";
227 227 ss += layerdef;
228 228 }
229   - ss += format(" limit %d ",MAXCOUNT);
230   - // ss += " limit 40000 ";
  229 + ss += format(" limit %d ", MAXCOUNT);
  230 + // ss += " limit 40000 ";
231 231 //size_t size = strlen(regionDef);
232 232 std::string sql1 = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(),
233   - tableName.c_str(),l,t, r,t, r, b, l, b ,l, t,srid.c_str(), regionDef,shapeName.c_str() );
234   -
235   - // printf("%s\r\n",sql1.c_str());
  233 + tableName.c_str(), l, t, r, t, r, b, l, b, l, t, srid.c_str(), regionDef, shapeName.c_str());
236 234
237   - return sql1;
238   - }
239   - // else
240   - {
241   - return "";
242   - }
  235 + // printf("%s\r\n",sql1.c_str());
243 236
244   -
  237 + return sql1;
  238 + }
  239 + // else
  240 + {
  241 + return "";
  242 + }
245 243 }
246 244 return "";
247 245 }
248 246
249   -
250   -
251   - string DmpWmsRenderer::GetRegionQuerySQL(DmpVectorLayer* layer,Rect *pRect,string srid, const string &regionLayerName,const string &regionDef,const char *layerdef)
  247 + string DmpWmsRenderer::GetRegionQuerySQL(DmpVectorLayer *layer, Rect *pRect, string srid, const string &regionLayerName, const string &regionDef, const char *layerdef)
252 248 {
253 249 if (layer == 0 || layer->geom().size() == 0)
254 250 return "";
... ... @@ -258,62 +254,59 @@ namespace DmpWms
258 254 {
259 255 double t = pRect->m_dTop, r = pRect->m_dRight, b = pRect->m_dBottom, l = pRect->m_dLeft;
260 256 size_t pos = regionDef.find("not in");
261   - if(pos == string::npos)
  257 + if (pos == string::npos)
262 258 {
263   - sql = format( "select ST_Intersection( \
  259 + sql = format("select ST_Intersection( \
264 260 ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
265 261 (select st_union(geom) from \"%s\" where %s))",
266   - l,t, r,t, r, b, l, b ,l, t, srid.c_str(),regionLayerName.c_str(),regionDef.c_str());
  262 + l, t, r, t, r, b, l, b, l, t, srid.c_str(), regionLayerName.c_str(), regionDef.c_str());
267 263 }
268 264 else
269 265 {
270 266 string field = regionDef.substr(0, pos);
271   - string exp = regionDef.substr(pos+6);
272   - sql = format( "select (ST_Difference( \
  267 + string exp = regionDef.substr(pos + 6);
  268 + sql = format("select (ST_Difference( \
273 269 ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
274 270 (select st_union(geom) from \"%s\" where %s in %s)))",
275   - l,t, r,t, r, b, l, b ,l, t, srid.c_str(), regionLayerName.c_str(),field.c_str(),exp.c_str());
  271 + l, t, r, t, r, b, l, b, l, t, srid.c_str(), regionLayerName.c_str(), field.c_str(), exp.c_str());
276 272
277 273 //regionDef = StringHelp::
278 274 }
279 275
280   -
281   -
282   -
283   - // if(pPgsqlConn->ExecWait(sql.c_str()) && pPgsqlConn->next())
284   - {
285   - // const char * polygon = pPgsqlConn->getString(0);
286   - string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
  276 + // if(pPgsqlConn->ExecWait(sql.c_str()) && pPgsqlConn->next())
  277 + {
  278 + // const char * polygon = pPgsqlConn->getString(0);
  279 + string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
287 280
288   - shared_ptr<Renderer> renderer = layer->GetRenderer30();
  281 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
289 282
290   - // int renType = renderer->RendererType();
291   - vector<string> vFieldName;
292   - renderer->TryAddField(vFieldName);
  283 + // int renType = renderer->RendererType();
  284 + vector<string> vFieldName;
  285 + renderer->TryAddField(vFieldName);
293 286
294   - int length = (int)(vFieldName.size());
295   - for (int i = 0; i < length; i++)
296   - {
297   - string filename = vFieldName[i];
298   - ss += ",\"" + (filename) + "\"::varchar ";
299   - }
  287 + int length = (int)(vFieldName.size());
  288 + for (int i = 0; i < length; i++)
  289 + {
  290 + string filename = vFieldName[i];
  291 + ss += ",\"" + (filename) + "\"::varchar ";
  292 + }
300 293
301   - string tableName = layer->name(); //layer->name();
302   - string shapeName = layer->geom();
303   - shared_ptr<DmpVectorThinLayer> pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR);
  294 + string tableName = layer->name(); //layer->name();
  295 + string shapeName = layer->geom();
  296 + shared_ptr<DmpVectorThinLayer> pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR);
304 297
305   - if (pVectorThinLayer != nullptr)
306   - {
307   - tableName = pVectorThinLayer->tableName();
308   - }
  298 + if (pVectorThinLayer != nullptr)
  299 + {
  300 + tableName = pVectorThinLayer->tableName();
  301 + }
309 302
310   - ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
311   - ss += " WHERE \"%s\" && \'BOX3D(%lf %lf,%lf %lf)\'::box3d and ST_Intersects( (%s),\"%s\" )"; //'%s'::Geometry
312   - if (layer->wherestr().length() > 0)
313   - {
314   - ss += " and ";
315   - ss += layer->wherestr();
316   - }
  303 + ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
  304 + ss += " WHERE \"%s\" && \'BOX3D(%lf %lf,%lf %lf)\'::box3d and ST_Intersects( (%s),\"%s\" )"; //'%s'::Geometry
  305 + if (layer->wherestr().length() > 0)
  306 + {
  307 + ss += " and ";
  308 + ss += layer->wherestr();
  309 + }
317 310
318 311 if (layerdef != nullptr && strcmp(layerdef, "") != 0)
319 312 {
... ... @@ -321,27 +314,24 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
321 314 ss += layerdef;
322 315 }
323 316
324   - ss += format(" limit %d ",MAXCOUNT);
  317 + ss += format(" limit %d ", MAXCOUNT);
325 318
326 319 std::string sql1 = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(),
327   - tableName.c_str(), shapeName.c_str(), l, b, r, t, sql.c_str(),shapeName.c_str() );
  320 + tableName.c_str(), shapeName.c_str(), l, b, r, t, sql.c_str(), shapeName.c_str());
328 321
329 322 //printf("%s\r\n",sql1.c_str());
330 323
331   - return sql1;
332   - }
333   - //else
334   - {
335   - return "";
336   - }
337   -
338   -
  324 + return sql1;
  325 + }
  326 + //else
  327 + {
  328 + return "";
  329 + }
339 330 }
340   - return "";
  331 + return "";
341 332 }
342   -
343 333
344   - string DmpWmsRenderer::GetDrawSQLAll_Catch(DmpVectorLayer* layer, shared_ptr<DmpVectorThinLayer> pVectorThinLayer)
  334 + string DmpWmsRenderer::GetDrawSQLAll_Catch(DmpVectorLayer *layer, shared_ptr<DmpVectorThinLayer> pVectorThinLayer)
345 335 {
346 336 if (layer == 0 || layer->geom().size() == 0)
347 337 return "";
... ... @@ -349,7 +339,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
349 339 //char sql[6000];
350 340 string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
351 341
352   - shared_ptr<Renderer> renderer = layer->GetRenderer30();
  342 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
353 343
354 344 // int renType = renderer->RendererType();
355 345 vector<string> vFieldName;
... ... @@ -383,15 +373,15 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
383 373 return sql;
384 374 }
385 375
386   - string DmpWmsRenderer::GetDrawSQLAll(DmpVectorLayer* layer)
  376 + string DmpWmsRenderer::GetDrawSQLAll(DmpVectorLayer *layer)
387 377 {
388   - if (layer == 0 || layer->geom().size() == 0)
  378 + if (layer == 0 || layer->geom().size() == 0)
389 379 return "";
390 380
391 381 //char sql[6000];
392 382 string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
393 383
394   - shared_ptr<Renderer> renderer = layer->GetRenderer30();
  384 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
395 385
396 386 // int renType = renderer->RendererType();
397 387 vector<string> vFieldName;
... ... @@ -421,15 +411,15 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
421 411 return sql;
422 412 }
423 413
424   - string DmpWmsRenderer::GetDrawSQLAllOrderby(DmpVectorLayer* layer)
  414 + string DmpWmsRenderer::GetDrawSQLAllOrderby(DmpVectorLayer *layer)
425 415 {
426   - if (layer == 0 || layer->geom().size() == 0)
  416 + if (layer == 0 || layer->geom().size() == 0)
427 417 return "";
428 418
429 419 //char sql[6000];
430 420 string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
431 421
432   - shared_ptr<Renderer> renderer = layer->GetRenderer30();
  422 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
433 423
434 424 // int renType = renderer->RendererType();
435 425 vector<string> vFieldName;
... ... @@ -451,7 +441,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
451 441 ss += layer->wherestr();
452 442 }
453 443
454   - ss += format(" limit %d ",MAXCOUNT);
  444 + ss += format(" limit %d ", MAXCOUNT);
455 445
456 446 string tableName = layer->name();
457 447 string shapeName = layer->geom();
... ... @@ -461,9 +451,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
461 451 return sql;
462 452 }
463 453
464   - string DmpWmsRenderer::GetCountSQL(DmpVectorLayer* layer)
  454 + string DmpWmsRenderer::GetCountSQL(DmpVectorLayer *layer)
465 455 {
466   - if (layer == 0 || layer->geom().size() == 0)
  456 + if (layer == 0 || layer->geom().size() == 0)
467 457 return "";
468 458
469 459 //char sql[6000];
... ... @@ -488,13 +478,11 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
488 478 return sql;
489 479 }
490 480
491   - string DmpWmsRenderer::GetFeatureInfoSQL(DmpVectorLayer* layer, double x, double y, double dis,int feature_count)
  481 + string DmpWmsRenderer::GetFeatureInfoSQL(DmpVectorLayer *layer, double x, double y, double dis, int feature_count)
492 482 {
493 483 if (layer == 0 || layer->geom().size() == 0)
494 484 return "";
495 485
496   -
497   -
498 486 string ss = "SELECT "; //这个 %s 是表示 shape 字段
499 487
500 488 string fields_str = "";
... ... @@ -504,9 +492,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
504 492 {
505 493
506 494 char tablesql_buff[300];
507   - sprintf(tablesql_buff, "select column_name,data_type from information_schema.columns where table_schema = '%s' and table_name = '%s'",
508   - layer->schema().c_str(),
509   - layer->name().c_str());
  495 + std::sprintf(tablesql_buff, "select column_name,data_type from information_schema.columns where table_schema = '%s' and table_name = '%s'",
  496 + layer->schema().c_str(),
  497 + layer->name().c_str());
510 498
511 499 int returnResult = pPgsqlConn->ExecWait(tablesql_buff);
512 500 if (!returnResult)
... ... @@ -515,10 +503,10 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
515 503 }
516 504 else
517 505 {
518   -
  506 +
519 507 for (int i = 0; pPgsqlConn->next(); i++)
520 508 {
521   - if (i > 0 && fields_str.length() >0 && fields_str[fields_str.length() -1]!=',')
  509 + if (i > 0 && fields_str.length() > 0 && fields_str[fields_str.length() - 1] != ',')
522 510 {
523 511 fields_str += ",";
524 512 }
... ... @@ -572,8 +560,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
572 560
573 561 if (layer->wherestr().length() > 0)
574 562 {
575   - ss += format("where %s and ", layer->wherestr().c_str() );
576   -
  563 + ss += format("where %s and ", layer->wherestr().c_str());
577 564 }
578 565 else
579 566 {
... ... @@ -584,60 +571,51 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
584 571 std::string sql = format(ss.c_str(), layer->schema().c_str(), tableName.c_str());
585 572
586 573 string shapeName = layer->geom();
587   - sql += format(" ST_DWithin(\"%s\", ST_GeometryFromText('POINT(%f %f)',%s), %f) limit %d ",
588   - shapeName.c_str(),x, y , layer->crs().srid(), dis, feature_count);
  574 + sql += format(" ST_DWithin(\"%s\", ST_GeometryFromText('POINT(%f %f)',%s), %f) limit %d ",
  575 + shapeName.c_str(), x, y, layer->crs().srid(), dis, feature_count);
589 576 //cout<<sql.c_str() <<endl;
590 577 return sql;
591 578 }
592 579
593   -
594   - bool DmpWmsRenderer::GetFeatureInfo(std::string &responseData, int gmlVersion, int x, int y, int feature_count)
  580 + bool DmpWmsRenderer::GetFeatureInfo(std::string &responseData, int x, int y, int feature_count)
595 581 {
596   - if(m_dR == 0)
  582 + if (m_dR == 0)
597 583 return false;
598 584 //double x0 = m_dR * x + m_dXdis;
599 585 //double y0 = -m_dR * y + m_dYdis;
600 586
601   - double x0 =(x - m_dXdis)/ m_dR ;
602   - double y0 = (m_dYdis -y )/m_dR ;
603   - double dis = 1/m_dR;
604   -
  587 + double x0 = (x - m_dXdis) / m_dR;
  588 + double y0 = (m_dYdis - y) / m_dR;
  589 + double dis = 1 / m_dR;
605 590
606   -
607   - for (int i = (int)(m_vLayers.size()) -1; i >=0; i--)
  591 + for (int i = (int)(m_vLayers.size()) - 1; i >= 0; i--)
608 592 {
609   - DmpVectorLayer* layer = (DmpVectorLayer*)m_vLayers[i];
  593 + DmpVectorLayer *layer = (DmpVectorLayer *)m_vLayers[i];
610 594
611 595 //double r1 = layer->m_dUpperScale; // *
612 596 //double r2 = layer->m_dLowerScale; // *
613 597
614   -
615 598 ///if ((this->m_dScaleDenominator > r1 || this->m_dScaleDenominator < r2 || ml->m_pRenderer == 0))
616 599 // continue;
617 600
618 601 double start = clock();
619 602 double cost, cost2;
620 603
621   - string sql = this->GetFeatureInfoSQL(layer, x0, y0, dis,feature_count); //sql语句中使用 ::box
  604 + string sql = this->GetFeatureInfoSQL(layer, x0, y0, dis, feature_count); //sql语句中使用 ::box
622 605 if (sql == "")
623 606 continue;
624 607
625 608 string layerName = layer->name();
626   - //const char *ss__ = "";
627   - //const char **pmsg = &ss__;
628 609 try
629 610 {
630   - shared_ptr<DmpPgsql> pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source());
  611 + shared_ptr<DmpPgsql> pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source());
631 612 if (pPgsqlConn == nullptr)
632 613 break;
633   - if (pPgsqlConn->ExecWaitBinary(sql) )
  614 + if (pPgsqlConn->ExecWaitBinary(sql))
634 615 {
635   -
636   - //PGresult *res = pPgsqlConn->GetPGresult();
637   - string srid = std::__cxx11::to_string(layer->crs().srid());
638   - this->FormatWFSJsonCAll(pPgsqlConn, responseData, layerName, gmlVersion,srid);
639   - return true;
640   -
  616 + string srid = std::__cxx11::to_string(layer->crs().srid());
  617 + mapserver::DmpMapServerUtil::responseGeojson(pPgsqlConn, responseData, layerName, srid);
  618 + return true;
641 619 }
642 620 }
643 621 catch (const std::exception &e)
... ... @@ -646,14 +624,12 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
646 624 }
647 625 }
648 626 return true;
649   - }
650   -
  627 + }
651 628
652   -
653   - bool DmpWmsRenderer::AddWmsMapLayers(const DmpProject* project) //插入型加入
  629 + bool DmpWmsRenderer::AddWmsMapLayers(const DmpProject *project) //插入型加入
654 630 {
655   - std::map<std::string, DmpMapLayer*> mapLayers = project->mapLayers();
656   - for(std::map<std::string, DmpMapLayer*>::iterator iter= mapLayers.begin();
  631 + std::map<std::string, DmpMapLayer *> mapLayers = project->mapLayers();
  632 + for (std::map<std::string, DmpMapLayer *>::iterator iter = mapLayers.begin();
657 633 iter != mapLayers.end(); iter++)
658 634 {
659 635 this->AddMapLayer(-1, (DmpVectorLayer *)iter->second);
... ... @@ -661,7 +637,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
661 637 return true;
662 638 }
663 639
664   - bool DmpWmsRenderer::AddWmsMapLayers(const DmpProject* project, char *layer) //插入型加入
  640 + bool DmpWmsRenderer::AddWmsMapLayers(const DmpProject *project, char *layer) //插入型加入
665 641 {
666 642 bool layerIndex = true;
667 643 for (size_t i = 0; layer[i] != 0; i++)
... ... @@ -693,15 +669,15 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
693 669 i++;
694 670 }
695 671
696   - std::map<std::string, DmpMapLayer*> mapLayers = project->mapLayers();
697   - for (std::map<std::string, DmpMapLayer*>::iterator iter= mapLayers.begin();
698   - iter != mapLayers.end(); iter++)
699   - {
700   - if (set_layer.find(iter->first) != set_layer.end())
  672 + std::map<std::string, DmpMapLayer *> mapLayers = project->mapLayers();
  673 + for (std::map<std::string, DmpMapLayer *>::iterator iter = mapLayers.begin();
  674 + iter != mapLayers.end(); iter++)
  675 + {
  676 + if (set_layer.find(iter->first) != set_layer.end())
701 677 {
702 678 this->AddMapLayer(-1, (DmpVectorLayer *)iter->second);
703 679 }
704   - }
  680 + }
705 681
706 682 /*for (size_t i = 0; i < pWmsServer->layers.size(); i++)
707 683 {
... ... @@ -752,8 +728,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
752 728 return true;
753 729 }
754 730
755   -
756   - bool DmpWmsRenderer::AddMapLayer(int index, DmpVectorLayer* layer)
  731 + bool DmpWmsRenderer::AddMapLayer(int index, DmpVectorLayer *layer)
757 732 {
758 733 if (!layer)
759 734 return false;
... ... @@ -810,23 +785,22 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
810 785 if ((r > std::pow(10, 12)) || (r < std::pow(10, -12)))
811 786 return false;
812 787
813   -
814 788 //m_dR = R1 < R2 ? R1 : R2;
815 789 m_dR = r;
816 790 m_dXdis = m_dWidth / 2.0 - m_dR * (m_pExtent->m_dRight + m_pExtent->m_dLeft) / 2.0;
817 791 m_dYdis = m_dHeight / 2.0 + m_dR * (m_pExtent->m_dTop + m_pExtent->m_dBottom) / 2.0;
818 792
819   - if(R1 < R2)
  793 + if (R1 < R2)
820 794 {
821   - double top = (m_pExtent->m_dTop + m_pExtent->m_dBottom) / 2.0 + m_dHeight/(m_dR * 2);
822   - double bottom = (m_pExtent->m_dTop + m_pExtent->m_dBottom) / 2.0 - m_dHeight/( m_dR * 2) ;
823   - m_pExtent->m_dTop = top;
824   - m_pExtent->m_dBottom = bottom;
  795 + double top = (m_pExtent->m_dTop + m_pExtent->m_dBottom) / 2.0 + m_dHeight / (m_dR * 2);
  796 + double bottom = (m_pExtent->m_dTop + m_pExtent->m_dBottom) / 2.0 - m_dHeight / (m_dR * 2);
  797 + m_pExtent->m_dTop = top;
  798 + m_pExtent->m_dBottom = bottom;
825 799 }
826 800 else
827 801 {
828   - double right= (m_pExtent->m_dRight + m_pExtent->m_dLeft) / 2.0 + m_dWidth/(2 * m_dR);
829   - double left = (m_pExtent->m_dRight + m_pExtent->m_dLeft) / 2.0 - m_dWidth/(2 * m_dR) ;
  802 + double right = (m_pExtent->m_dRight + m_pExtent->m_dLeft) / 2.0 + m_dWidth / (2 * m_dR);
  803 + double left = (m_pExtent->m_dRight + m_pExtent->m_dLeft) / 2.0 - m_dWidth / (2 * m_dR);
830 804 m_pExtent->m_dRight = right;
831 805 m_pExtent->m_dLeft = left;
832 806 }
... ... @@ -874,7 +848,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
874 848 }
875 849 return true;
876 850 }
877   -/*
  851 + /*
878 852 bool DmpWmsRenderer::DrawData(DataCollection *data, Renderer *renderer, clsCrSurf *pClsCS)
879 853 {
880 854
... ... @@ -911,8 +885,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
911 885 return true;
912 886 }
913 887
914   -
915   - bool DmpWmsRenderer::BufferCopy(clsCrSurf *pClsCSFrom, clsCrSurf *pClsCSTo)
  888 + bool DmpWmsRenderer::BufferCopy(clsCrSurf *pClsCSFrom, clsCrSurf *pClsCSTo)
916 889 {
917 890 if (pClsCSFrom == NULL)
918 891 pClsCSFrom = m_pClsSurfBuff;
... ... @@ -940,11 +913,10 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
940 913 cairo_fill(cr);
941 914 return true;
942 915 }
943   -
944 916
945 917 //在DC上绘制时是否使用一个临时的 image_surface, 然后拷上去,这样具体的细节处理就没有区别了
946   - bool DmpWmsRenderer::GetMap(map<string, string> *map_layerDefs,map<string, string> * map_regionDefs, clsCrSurf *pClsCS, bool isThumbnail,
947   - shared_ptr<Rect> pRect, double r__, double x_dis__, double y_dis__)
  918 + bool DmpWmsRenderer::GetMap(map<string, string> *map_layerDefs, map<string, string> *map_regionDefs, clsCrSurf *pClsCS, bool isThumbnail,
  919 + shared_ptr<Rect> pRect, double r__, double x_dis__, double y_dis__)
948 920 {
949 921 /*确定参数*/
950 922 clsCrSurf *pClsSurfThis;
... ... @@ -978,7 +950,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
978 950 y_dis = y_dis__;
979 951 }
980 952
981   - /*
  953 + /*
982 954 * 重置文字避让
983 955 */
984 956 //文字避让是否写成局部??
... ... @@ -990,7 +962,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
990 962 string strRegionColDefs = "";
991 963 string strRegionLayerNameDefs = "";
992 964
993   - if(map_regionDefs)
  965 + if (map_regionDefs)
994 966 {
995 967 map<string, string>::iterator iter_regionDef = map_regionDefs->begin();
996 968 if (iter_regionDef != map_regionDefs->end())
... ... @@ -1000,14 +972,12 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
1000 972 has_regionDefs = true;
1001 973 }
1002 974 }
1003   -
1004 975
1005   - map<DmpVectorLayer*, shared_ptr<DataCollection>> map_DataCollection;
  976 + map<DmpVectorLayer *, shared_ptr<DataCollection>> map_DataCollection;
1006 977
1007 978 for (int i = 0; i < (int)(m_vLayers.size()); i++)
1008 979 {
1009   - DmpVectorLayer* layer = m_vLayers[i];
1010   -
  980 + DmpVectorLayer *layer = m_vLayers[i];
1011 981
1012 982 double r1 = layer->maxScale(); // *
1013 983 double r2 = layer->minScale(); // *
... ... @@ -1028,55 +998,53 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
1028 998 }
1029 999
1030 1000 //bool isbuffQuery = false;
1031   - // double width_scale = abs((layer->m_pDataset->maxx - layer->m_pDataset->minx) / (pExtent->m_dRight - pExtent->m_dLeft));
  1001 + // double width_scale = abs((layer->m_pDataset->maxx - layer->m_pDataset->minx) / (pExtent->m_dRight - pExtent->m_dLeft));
1032 1002 {
1033 1003 //std::printf("db \r\n ");
1034 1004 double start = clock();
1035 1005 double cost, cost2;
1036 1006
1037   - string sql ="";
  1007 + string sql = "";
1038 1008 shared_ptr<DmpVectorThinLayer> pVectorThinLayer = nullptr;
1039 1009
1040 1010 bool renderHeat = false;
1041 1011 shared_ptr<DataCollection> data(new DataCollection());
1042 1012
1043   - if(!has_regionDefs)
  1013 + if (!has_regionDefs)
1044 1014 {
1045   - sql = GetDrawSQL(layer, pExtent.get(), strLayerDef);
  1015 + sql = GetDrawSQL(layer, pExtent.get(), strLayerDef);
1046 1016 }
1047 1017 else
1048 1018 {
1049   - sql = GetRegionQuerySQL(layer, pExtent.get(), format("%d",layer->crs().srid()), strRegionLayerNameDefs,strRegionColDefs, strLayerDef);
  1019 + sql = GetRegionQuerySQL(layer, pExtent.get(), format("%d", layer->crs().srid()), strRegionLayerNameDefs, strRegionColDefs, strLayerDef);
1050 1020 }
1051 1021
1052 1022 pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR);
1053 1023
1054   - // printf( "%s\r\n", sql.c_str());
1055   - // this->GetDrawSQL(layer, pExtent.get(), strLayerDef); //sql语句中使用 ::box
  1024 + // printf( "%s\r\n", sql.c_str());
  1025 + // this->GetDrawSQL(layer, pExtent.get(), strLayerDef); //sql语句中使用 ::box
1056 1026 if (sql == "")
1057 1027 continue;
1058 1028
1059 1029 string tableName = layer->name();
1060 1030
1061   -
1062 1031 if (pVectorThinLayer != nullptr)
1063 1032 {
1064   - tableName = pVectorThinLayer->tableName();
1065   - }
  1033 + tableName = pVectorThinLayer->tableName();
  1034 + }
1066 1035
1067   - if(tableName.length() > 32)
  1036 + if (tableName.length() > 32)
1068 1037 {
1069 1038 tableName = tableName.substr(32);
1070 1039 }
1071 1040
1072   -
1073 1041 const char *ss__ = "";
1074 1042 const char **pmsg = &ss__;
1075 1043 try
1076 1044 {
1077 1045
1078 1046 shared_ptr<DmpPgsql> pPgsqlConn = nullptr;
1079   - if(pVectorThinLayer == nullptr)
  1047 + if (pVectorThinLayer == nullptr)
1080 1048 {
1081 1049 pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source());
1082 1050 }
... ... @@ -1084,9 +1052,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
1084 1052 {
1085 1053 pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetDefaultPgsqlConn();
1086 1054 }
1087   -
  1055 +
1088 1056 if (pPgsqlConn == nullptr)
1089   - break;
  1057 + break;
1090 1058 if (pPgsqlConn->ExecWaitBinary(sql))
1091 1059 {
1092 1060 PGresult *res = pPgsqlConn->GetPGresult();
... ... @@ -1096,7 +1064,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
1096 1064 int shapeType = layer->GeometryType();
1097 1065 shared_ptr<DataCollection> data(new DataCollection());
1098 1066 data->InitDataCollection(res, shapeType, this->m_dWidth, this->m_dHeight, 0, m_dR, m_dScaleDenominator, x_dis, y_dis);
1099   -
  1067 +
1100 1068 //data->InitDataCollection(res, shapeType, this->m_dWidth, this->m_dHeight, (int)layer->subset, m_dR, m_dScaleDenominator, x_dis, y_dis);
1101 1069 map_DataCollection[layer] = data;
1102 1070 //data_ptr = data;
... ... @@ -1104,10 +1072,10 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
1104 1072
1105 1073 allDataCount += PQntuples(res);
1106 1074 this->DrawSimpleData(data.get(), layer->GetRenderer30().get(), pClsSurfThis);
1107   - // DrawText(StringHelp::fmt("data %.0fm",(endTime_data - startTime).count()/1000000.0)
1108   - // ,pClsSurfThis,10,50);
  1075 + // DrawText(StringHelp::fmt("data %.0fm",(endTime_data - startTime).count()/1000000.0)
  1076 + // ,pClsSurfThis,10,50);
1109 1077
1110   - /*
  1078 + /*
1111 1079 DrawText(tableName ,pClsSurfThis,10,100);
1112 1080
1113 1081 char ptext[100] = {0};
... ... @@ -1116,10 +1084,10 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
1116 1084
1117 1085 */
1118 1086 }
1119   - else if(pVectorThinLayer != nullptr)
  1087 + else if (pVectorThinLayer != nullptr)
1120 1088 {
1121   - shared_ptr<DmpPgsql> pPgsqlConn1 = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source());
1122   -
  1089 + shared_ptr<DmpPgsql> pPgsqlConn1 = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source());
  1090 +
1123 1091 if (pPgsqlConn1 == nullptr)
1124 1092 break;
1125 1093 if (pPgsqlConn1->ExecWaitBinary(sql))
... ... @@ -1130,16 +1098,16 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
1130 1098
1131 1099 int shapeType = layer->GeometryType();
1132 1100 shared_ptr<DataCollection> data(new DataCollection());
1133   - if(!renderHeat)
  1101 + if (!renderHeat)
1134 1102 {
1135 1103 data->InitDataCollection(res, shapeType, this->m_dWidth, this->m_dHeight, 0, m_dR, m_dScaleDenominator, x_dis, y_dis);
1136 1104 }
1137 1105 else
1138 1106 {
1139   - data->InitHeatCollection(res, shapeType, this->m_dWidth, this->m_dHeight,
1140   - pExtent->m_dLeft, pExtent->m_dRight, pExtent->m_dBottom, pExtent->m_dTop, 0, m_dR, m_dScaleDenominator, x_dis, y_dis);
  1107 + data->InitHeatCollection(res, shapeType, this->m_dWidth, this->m_dHeight,
  1108 + pExtent->m_dLeft, pExtent->m_dRight, pExtent->m_dBottom, pExtent->m_dTop, 0, m_dR, m_dScaleDenominator, x_dis, y_dis);
1141 1109 }
1142   -
  1110 +
1143 1111 map_DataCollection[layer] = data;
1144 1112
1145 1113 //auto endTime_data = chrono::steady_clock::now();
... ... @@ -1147,14 +1115,12 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
1147 1115
1148 1116 allDataCount += PQntuples(res);
1149 1117 this->DrawSimpleData(data.get(), layer->GetRenderer30().get(), pClsSurfThis);
1150   -
1151 1118 }
1152 1119 else
1153 1120 {
1154   - //DrawText2("获取数据失败,找不到图层" ,pClsSurfThis,10,10);
  1121 + //DrawText2("获取数据失败,找不到图层" ,pClsSurfThis,10,10);
1155 1122 }
1156 1123 }
1157   -
1158 1124 }
1159 1125 catch (const std::exception &e)
1160 1126 {
... ... @@ -1163,7 +1129,6 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
1163 1129 }
1164 1130 }
1165 1131
1166   -
1167 1132 map_DataCollection.clear();
1168 1133
1169 1134 //return true;
... ... @@ -1175,311 +1140,125 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
1175 1140 return true;
1176 1141 }
1177 1142
1178   -
1179   - bool DmpWmsRenderer::ToStream(std::string& responseData)
  1143 + bool DmpWmsRenderer::ToStream(std::string &responseData)
1180 1144 {
1181 1145 responseData.reserve(10240);
1182   - if(this->pRasterBufferObj == nullptr)
  1146 + if (this->pRasterBufferObj == nullptr)
1183 1147 {
1184 1148 cairo_surface_write_to_png_stream(m_pClsSurfDC->m_pSurf, cairo_write_func, &responseData);
1185 1149 return true;
1186 1150 }
1187 1151 else
1188   - {
  1152 + {
1189 1153 return ToPngStream(this->pRasterBufferObj, responseData);
1190 1154 }
1191 1155 }
1192 1156
1193   -
1194   -bool DmpWmsRenderer::ToPngStream(rasterBufferObj *rb,std::string& responseData)
1195   -{
1196   - png_infop info_ptr;
1197   - int color_type;
1198   - int row;
1199   - unsigned int *rowdata;
1200   - int compression = 9;
1201   - png_structp png_ptr = png_create_write_struct(
1202   - PNG_LIBPNG_VER_STRING, NULL,NULL,NULL);
1203   -
1204   - if (!png_ptr)
1205   - return (false);
1206   -
1207   - png_set_compression_level(png_ptr, compression);
1208   - png_set_filter (png_ptr,0, PNG_FILTER_NONE);
1209   -
1210   - info_ptr = png_create_info_struct(png_ptr);
1211   - if (!info_ptr) {
1212   - png_destroy_write_struct(&png_ptr,
1213   - (png_infopp)NULL);
1214   - return (false);
1215   - }
1216   -
1217   - if (setjmp(png_jmpbuf(png_ptr))) {
1218   - png_destroy_write_struct(&png_ptr, &info_ptr);
1219   - return (false);
1220   - }
1221   - //if(info->fp)
1222   - // png_set_write_fn(png_ptr,info, png_write_data_to_stream, png_flush_data);
1223   - //else
1224   - png_set_write_fn(png_ptr,&responseData, png_write_data_to_buffer, png_flush_data);
1225   -
1226   - if(rb->data.rgba.a)
1227   - color_type = PNG_COLOR_TYPE_RGB_ALPHA;
1228   - else
1229   - color_type = PNG_COLOR_TYPE_RGB;
1230   -
1231   - png_set_IHDR(png_ptr, info_ptr, rb->width, rb->height,
1232   - 8, color_type, PNG_INTERLACE_NONE,
1233   - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
1234   -
1235   - png_write_info(png_ptr, info_ptr);
1236   -
1237   - if(!rb->data.rgba.a && rb->data.rgba.pixel_step==4)
1238   - png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
1239   -
1240   - rowdata = (unsigned int*)malloc(rb->width*sizeof(unsigned int));
1241   - for(row=0; row<rb->height; row++) {
1242   - unsigned int *pixptr = rowdata;
1243   - int col;
1244   - unsigned char *a,*r,*g,*b;
1245   - r=rb->data.rgba.r+row*rb->data.rgba.row_step;
1246   - g=rb->data.rgba.g+row*rb->data.rgba.row_step;
1247   - b=rb->data.rgba.b+row*rb->data.rgba.row_step;
1248   - if(rb->data.rgba.a) {
1249   - a=rb->data.rgba.a+row*rb->data.rgba.row_step;
1250   - for(col=0; col<rb->width; col++) {
1251   - if(*a) {
1252   - double da = *a/255.0;
1253   - unsigned char *pix = (unsigned char*)pixptr;
1254   - pix[0] = *r/da;
1255   - pix[1] = *g/da;
1256   - pix[2] = *b/da;
1257   - pix[3] = *a;
1258   - } else {
1259   - *pixptr=0;
1260   - }
1261   - pixptr++;
1262   - a+=rb->data.rgba.pixel_step;
1263   - r+=rb->data.rgba.pixel_step;
1264   - g+=rb->data.rgba.pixel_step;
1265   - b+=rb->data.rgba.pixel_step;
1266   - }
1267   - } else {
1268   - for(col=0; col<rb->width; col++) {
1269   - unsigned char *pix = (unsigned char*)pixptr;
1270   - pix[0] = *r;
1271   - pix[1] = *g;
1272   - pix[2] = *b;
1273   - pixptr++;
1274   - r+=rb->data.rgba.pixel_step;
1275   - g+=rb->data.rgba.pixel_step;
1276   - b+=rb->data.rgba.pixel_step;
1277   - }
1278   - }
1279   -
1280   - png_write_row(png_ptr,(png_bytep)rowdata);
1281   -
1282   - }
1283   - png_write_end(png_ptr, info_ptr);
1284   - free(rowdata);
1285   - png_destroy_write_struct(&png_ptr, &info_ptr);
1286   - return MS_SUCCESS;
1287   -}
1288   -
  1157 + bool DmpWmsRenderer::ToPngStream(rasterBufferObj *rb, std::string &responseData)
  1158 + {
  1159 + png_infop info_ptr;
  1160 + int color_type;
  1161 + int row;
  1162 + unsigned int *rowdata;
  1163 + int compression = 9;
  1164 + png_structp png_ptr = png_create_write_struct(
  1165 + PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  1166 +
  1167 + if (!png_ptr)
  1168 + return (false);
  1169 +
  1170 + png_set_compression_level(png_ptr, compression);
  1171 + png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
  1172 +
  1173 + info_ptr = png_create_info_struct(png_ptr);
  1174 + if (!info_ptr)
  1175 + {
  1176 + png_destroy_write_struct(&png_ptr,
  1177 + (png_infopp)NULL);
  1178 + return (false);
  1179 + }
1289 1180
1290   -//以GeoJson的形式返回
1291   -void DmpWmsRenderer::FormatWFSJsonCAll(shared_ptr<DmpPgsql> pPgsqlConn, AppendBuffer *ab, char *layerNAMEc,int gmlVersion,char *srsOut)
1292   -{
1293   - double xg1, yg1, xg2, yg2;
1294   - int havegSet = 0;
1295   - int count = 0;
1296   - int pointCountTemp = 0;
  1181 + if (setjmp(png_jmpbuf(png_ptr)))
  1182 + {
  1183 + png_destroy_write_struct(&png_ptr, &info_ptr);
  1184 + return (false);
  1185 + }
  1186 + //if(info->fp)
  1187 + // png_set_write_fn(png_ptr,info, png_write_data_to_stream, png_flush_data);
  1188 + //else
  1189 + png_set_write_fn(png_ptr, &responseData, png_write_data_to_buffer, png_flush_data);
1297 1190
1298   - std::string stringTime;
1299   - char buff[5000] = {0};
1300   -
1301   - ab->AppendString(R"({"type":"FeatureCollection","features":[)");
  1191 + if (rb->data.rgba.a)
  1192 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  1193 + else
  1194 + color_type = PNG_COLOR_TYPE_RGB;
1302 1195
1303   - try
1304   - {
1305   - int fieldsCount = pPgsqlConn->GetFieldCount();
1306   - for (int featureIndex = 0; pPgsqlConn->next(); featureIndex++)
1307   - {
1308   - if (featureIndex > 0)
1309   - ab->AppendString(",");
1310   - ab->AppendString(R"({"type":"Feature")");
  1196 + png_set_IHDR(png_ptr, info_ptr, rb->width, rb->height,
  1197 + 8, color_type, PNG_INTERLACE_NONE,
  1198 + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
1311 1199
  1200 + png_write_info(png_ptr, info_ptr);
1312 1201
1313   - string geometry = "";
1314   - string properties = "";
  1202 + if (!rb->data.rgba.a && rb->data.rgba.pixel_step == 4)
  1203 + png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
1315 1204
1316   - for (int i = 0; i < fieldsCount; i++)
  1205 + rowdata = (unsigned int *)malloc(rb->width * sizeof(unsigned int));
  1206 + for (row = 0; row < rb->height; row++)
  1207 + {
  1208 + unsigned int *pixptr = rowdata;
  1209 + int col;
  1210 + unsigned char *a, *r, *g, *b;
  1211 + r = rb->data.rgba.r + row * rb->data.rgba.row_step;
  1212 + g = rb->data.rgba.g + row * rb->data.rgba.row_step;
  1213 + b = rb->data.rgba.b + row * rb->data.rgba.row_step;
  1214 + if (rb->data.rgba.a)
1317 1215 {
1318   - const char *str = pPgsqlConn->GetFieldName(i); //pPgsqlConn->field_name[i].c_str();
1319   - //printf("%s\r\n",str);
1320   - if(str == 0)
1321   - {
1322   - break;
1323   - }
1324   -
1325   - if (strncmp(str, "RN_RN", 5) == 0)
1326   - continue;
1327   - std::string sT = str;
1328   - //XML转义
1329   - DmapDll::StringHelp::ToJSONString(sT);
1330   - str = sT.c_str();
1331   -
1332   - if( sT == "geometry_as_geojson")
1333   - {
1334   - geometry = pPgsqlConn->getString(i);
1335   - continue;
1336   - }
1337   - // str="a";
1338   - switch (pPgsqlConn->GetPGFieldType(i))
1339   - {
1340   - case PGFieldType::ByteaFieldType:
1341   - {
1342   - const char *s = pPgsqlConn->getBlob2(i);
1343   - sprintf(buff, R"(,"%s":"%s")", str, s);
1344   - properties += buff;
1345   - }
1346   - break;
1347   - case PGFieldType::ClobFieldType:
1348   - {
1349   - const char *s = pPgsqlConn->getClob2(i);
1350   - sprintf(buff, R"(,"%s":"%s")", str, s);
1351   - properties += buff;
1352   - }
1353   - break;
1354   - case PGFieldType::BigIntFieldType:
1355   - {
1356   - long v;
1357   - const char *str1 = pPgsqlConn->getString(i);
1358   - ((char *)&v)[7] = str1[0];
1359   - ((char *)&v)[6] = str1[1];
1360   - ((char *)&v)[5] = str1[2];
1361   - ((char *)&v)[4] = str1[3];
1362   - ((char *)&v)[3] = str1[4];
1363   - ((char *)&v)[2] = str1[5];
1364   - ((char *)&v)[1] = str1[6];
1365   - ((char *)&v)[0] = str1[7];
1366   - sprintf(buff, R"(,"%s":%ld)", str, v);
1367   - properties += buff;
1368   - //sprintf(sql, "<%s:%s>%llu</%s:%s>", "dmp", str, v, "dmp", str);
1369   - //ab->AppendString(sql);
1370   - }
1371   - break;
1372   - case PGFieldType::DateFieldType:
1373   - {
1374   - int v;
1375   - const char *str1 = pPgsqlConn->getString(i);
1376   - ((char *)&v)[3] = str1[0];
1377   - ((char *)&v)[2] = str1[1];
1378   - ((char *)&v)[1] = str1[2];
1379   - ((char *)&v)[0] = str1[3];
1380   - sprintf(buff, R"(,"%s":%d)", str, v);
1381   - properties += buff;
1382   - //sprintf(sql, "<%s:%s>%ld</%s:%s>", "dmp", str, v, "dmp", str);
1383   - //ab->AppendString(sql);
1384   - }
1385   - break;
1386   - case PGFieldType::IntFieldType:
  1216 + a = rb->data.rgba.a + row * rb->data.rgba.row_step;
  1217 + for (col = 0; col < rb->width; col++)
1387 1218 {
1388   - int v;
1389   - const char *str1 = pPgsqlConn->getString(i);
1390   - ((char *)&v)[3] = str1[0];
1391   - ((char *)&v)[2] = str1[1];
1392   - ((char *)&v)[1] = str1[2];
1393   - ((char *)&v)[0] = str1[3];
1394   - sprintf(buff, R"(,"%s":%d)", str, v);
1395   - properties += buff;
1396   - //sprintf(sql, "<%s:%s>%ld</%s:%s>", "dmp", str, v, "dmp", str);
1397   - //ab->AppendString(sql);
1398   - }
1399   - break;
1400   - case PGFieldType::DoubleFieldType:
1401   - {
1402   - double v;
1403   - const char *str1 = pPgsqlConn->getString(i);
1404   - //int vs=PQgetlength(((PgConn *)rs->conn)->res,0,0);
1405   - //memcpy(&v,str1,sizeof(v));
1406   - ((char *)&v)[7] = str1[0];
1407   - ((char *)&v)[6] = str1[1];
1408   - ((char *)&v)[5] = str1[2];
1409   - ((char *)&v)[4] = str1[3];
1410   - ((char *)&v)[3] = str1[4];
1411   - ((char *)&v)[2] = str1[5];
1412   - ((char *)&v)[1] = str1[6];
1413   - ((char *)&v)[0] = str1[7];
1414   - //number 有问题。
1415   -
  1219 + if (*a)
1416 1220 {
1417   - char sz1[100];
1418   - StringHelp::modp_dtoa2(v, sz1, 5);
1419   - sprintf(buff, R"(,"%s":"%s")", str, sz1);
1420   - properties += buff;
1421   - //sprintf(sql, "<%s:%s>%s</%s:%s>", "dmp", str, sz1, "dmp", str);
  1221 + double da = *a / 255.0;
  1222 + unsigned char *pix = (unsigned char *)pixptr;
  1223 + pix[0] = *r / da;
  1224 + pix[1] = *g / da;
  1225 + pix[2] = *b / da;
  1226 + pix[3] = *a;
1422 1227 }
1423   - //sprintf(sql,"<%s:%s>%lf</%s:%s>","dmp",str,v,"dmp",str);
1424   - //ab->AppendString(sql);
1425   - }
1426   - break;
1427   - case PGFieldType::TimestampWithoutTimeZone:
1428   - {
1429   - std::string s = pPgsqlConn->getString(i);
1430   - StringHelp::ToJSONString(s);
1431   - sprintf(buff, R"(,"%s":"%s")", str, s.c_str());
1432   - properties += buff;
1433   - //sprintf(sql, "<%s:%s>%s</%s:%s>", "dmp", str, s.c_str(), "dmp", str);
1434   - //ab->AppendString(sql);
1435   - }
1436   - case PGFieldType::VarCharFieldType:
1437   - {
1438   -
1439   - std::string s = pPgsqlConn->getString(i);
1440   - StringHelp::ToJSONString(s);
1441   - sprintf(buff, R"(,"%s":"%s")", str, s.c_str());
1442   - properties += buff;
1443   - //sprintf(sql, "<%s:%s>%s</%s:%s>", "dmp", str, s.c_str(), "dmp", str);
1444   - ///ab->AppendString(sql);
1445   - }
  1228 + else
  1229 + {
  1230 + *pixptr = 0;
  1231 + }
  1232 + pixptr++;
  1233 + a += rb->data.rgba.pixel_step;
  1234 + r += rb->data.rgba.pixel_step;
  1235 + g += rb->data.rgba.pixel_step;
  1236 + b += rb->data.rgba.pixel_step;
1446 1237 }
1447 1238 }
1448   -
1449   - if(geometry != "")
1450   - {
1451   - ab->AppendString(R"(,"geometry":)");
1452   - ab->AppendString(geometry.c_str());
1453   - }
1454   -
1455   - if (properties != "")
  1239 + else
1456 1240 {
1457   - ab->AppendString(R"(,"properties":)");
1458   - properties[0] = '{';
1459   - ab->AppendString(properties.c_str());
1460   - ab->AppendString("}");
  1241 + for (col = 0; col < rb->width; col++)
  1242 + {
  1243 + unsigned char *pix = (unsigned char *)pixptr;
  1244 + pix[0] = *r;
  1245 + pix[1] = *g;
  1246 + pix[2] = *b;
  1247 + pixptr++;
  1248 + r += rb->data.rgba.pixel_step;
  1249 + g += rb->data.rgba.pixel_step;
  1250 + b += rb->data.rgba.pixel_step;
  1251 + }
1461 1252 }
1462   - ab->AppendString("}");
1463   - //tickAA=GetTickCount();
1464   -
1465   - //sprintf(sql, "</%s:%s>\r", "dmp", layerName);
1466   - //ab->AppendString(sql);
1467   - //ab->AppendString("</gml:featureMember>");
1468 1253
1469   - count++;
1470   - //if(pointCount>25)break;
  1254 + png_write_row(png_ptr, (png_bytep)rowdata);
1471 1255 }
  1256 + png_write_end(png_ptr, info_ptr);
  1257 + free(rowdata);
  1258 + png_destroy_write_struct(&png_ptr, &info_ptr);
  1259 + return MS_SUCCESS;
1472 1260 }
1473   - catch (...)
1474   - {
1475   - return;
1476   - }
1477   -
1478   - ab->AppendString("]}");
1479   -
1480   - return ;
1481   -}
1482   -
1483 1261
  1262 +
1484 1263
1485 1264 }
... ...
... ... @@ -44,7 +44,7 @@ namespace DmpWms
44 44
45 45 bool GetMapLog(std::stringstream& outputStream, map<string,string>* map_layerDefs = NULL,map<string,string>* map_regionDefs = NULL, shared_ptr<Rect> pRect = nullptr, double r__ = -1, double x_dis__ = 0, double y_dis__ = 0);
46 46 bool GetMap(map<string,string>* map_layerDefs = NULL,map<string,string>* map_regionDefs = NULL, clsCrSurf* pClsSurf = NULL,bool isThumbnail = false, shared_ptr<Rect> pRect = nullptr, double r__ = -1, double x_dis__ = 0, double y_dis__ = 0);
47   - bool GetFeatureInfo(string &responseData, int gmlVersion, int x, int y, int feature_count);
  47 + bool GetFeatureInfo(string &responseData, int x, int y, int feature_count);
48 48
49 49 bool GetMapLegend( std::stringstream& ab, shared_ptr<legendParamater> pLegendParamater);
50 50 bool GetMapLegend( shared_ptr<legendParamater> pLegendParamater, clsCrSurf* pClsSurf);
... ... @@ -143,8 +143,8 @@ namespace DmpWms
143 143 bool CollectRules(const char* sRules);
144 144 bool CollectRules2(const char* sRules);
145 145
146   - void FormatWFSJsonCAll(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,int gmlVersion,const char *srid);
147   - void FormatWFSXMLCAll(shared_ptr<DmpPgsql> pPgsqlConn,std::string &responseData, const string& layerName, int gmlVersion,const char *srid);
  146 + //void FormatResponseJson(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const char *srid);
  147 + //void FormatResponseXml(shared_ptr<DmpPgsql> pPgsqlConn,std::string &responseData, const string& layerName, int gmlVersion,const char *srid);
148 148 };
149 149 }
150 150
... ...
注册登录 后发表评论