提交 04ba64955b532dc050a80909ac0ab0fdc09798be
Merge branch 'master' of http://gitlab.ctune.cn/DMapServer/DMapServer4.1
正在显示
13 个修改的文件
包含
3207 行增加
和
12 行删除
... | ... | @@ -47,11 +47,12 @@ bool DmpVectorLayer::writeXml(boost::property_tree::ptree &layerNode) |
47 | 47 | |
48 | 48 | void DmpVectorLayer::setRenderer(DmpFeatureRenderer *renderer) |
49 | 49 | { |
50 | - | |
50 | + | |
51 | 51 | } |
52 | 52 | |
53 | 53 | void DmpVectorLayer::setDataSource(const std::string &dataSource, const std::string &baseName, const std::string &provider, bool loadDefaultStyleFlag) |
54 | 54 | { |
55 | + | |
55 | 56 | DmpWkbTypes::GeometryType geomType = GeometryType(); |
56 | 57 | } |
57 | 58 | ... | ... |
1 | -[Core] | |
2 | -Filter="%Severity% >= debug" | |
3 | - | |
4 | -[Sinks.TextFileSettings] | |
5 | -Destination=TextFile | |
6 | -FileName="dmap_%Y%m%d.log" | |
7 | -AutoFlush=true | |
8 | -Format="[%TimeStamp%] [%Uptime%] [%Scope%] <%Severity%> %Message%" | |
9 | -Asynchronous=false | |
10 | -Append=true | |
1 | +[Core] | |
2 | +Filter="%Severity% >= debug" | |
3 | + | |
4 | +[Sinks.TextFileSettings] | |
5 | +Destination=TextFile | |
6 | +FileName="dmap_%Y%m%d.log" | |
7 | +AutoFlush=true | |
8 | +Format="[%TimeStamp%] [%Uptime%] [%Scope%] <%Severity%> %Message%" | |
9 | +Asynchronous=false | |
10 | +Append=true | ... | ... |
src/core/renderer/AppendBuffer.cpp
0 → 100644
1 | + | |
2 | + | |
3 | +#include "AppendBuffer.h" | |
4 | +#include "stdlib.h" | |
5 | +#include <string.h> | |
6 | +// | |
7 | + | |
8 | +namespace DmapCore_30 | |
9 | +{ | |
10 | + | |
11 | +AppendBuffer::AppendBuffer(void) | |
12 | +{ | |
13 | + allSize=0; | |
14 | + head=0; | |
15 | + now=0; | |
16 | +} | |
17 | + | |
18 | + AppendBuffer::AppendBuffer(const char *fileName) | |
19 | + { | |
20 | + allSize = 0; | |
21 | + head = 0; | |
22 | + now = 0; | |
23 | + if (fileName) | |
24 | + { | |
25 | + f = fopen(fileName, "wb"); | |
26 | + } | |
27 | + } | |
28 | + | |
29 | +AppendBuffer::~AppendBuffer(void) | |
30 | +{ | |
31 | + Reset(); | |
32 | +} | |
33 | + | |
34 | +//分配一个新的BUFFER | |
35 | +AppendBuffer::Buffer *AppendBuffer::NewABuffer(void) | |
36 | +{ | |
37 | + Buffer *buf=new Buffer; | |
38 | + buf->buffer=(char *)malloc(APPEND_BUFFER_SIZE); //每个BUFFER都留这么大的空间? | |
39 | + if(buf->buffer==0) | |
40 | + { | |
41 | + delete buf; | |
42 | + return 0; | |
43 | + } | |
44 | + buf->next=0; | |
45 | + buf->bufferNowCount=0; | |
46 | + | |
47 | + return buf; | |
48 | +} | |
49 | +char *AppendBuffer::GetString() | |
50 | + { | |
51 | + char *s = (char *)malloc(this->allSize + 1); | |
52 | + if (s == 0)return 0; | |
53 | + char *ss = s; int cc = 0; | |
54 | + for (Buffer *h = head; h;) | |
55 | + { | |
56 | + memcpy(ss, h->buffer, h->bufferNowCount); | |
57 | + ss += h->bufferNowCount; | |
58 | + // cc += h->bufferNowCount; | |
59 | + h = h->next; | |
60 | + } | |
61 | + s[this->allSize] = 0; | |
62 | + return s; | |
63 | + } | |
64 | +void AppendBuffer::AppendString(const char * str, int len) | |
65 | +{ | |
66 | + | |
67 | + if(now==0)AddABuffer(); //当前的指针为0 | |
68 | + | |
69 | + int remain; | |
70 | + for(;;) | |
71 | + { | |
72 | + remain=APPEND_BUFFER_SIZE-now->bufferNowCount; | |
73 | + if(remain==0) | |
74 | + { | |
75 | + AddABuffer(); | |
76 | + remain=APPEND_BUFFER_SIZE-now->bufferNowCount; | |
77 | + } | |
78 | + if(remain>=len)//放得下 | |
79 | + { | |
80 | + memcpy(now->buffer+now->bufferNowCount,str,len); | |
81 | + //len-=len; | |
82 | + now->bufferNowCount+=len; | |
83 | + this->allSize+=len; | |
84 | + break; | |
85 | + } | |
86 | + else //放不下 | |
87 | + { | |
88 | + memcpy(now->buffer+now->bufferNowCount,str,remain); | |
89 | + len-=remain; | |
90 | + now->bufferNowCount=APPEND_BUFFER_SIZE; | |
91 | + str+=remain; | |
92 | + this->allSize+=remain; | |
93 | + AddABuffer(); | |
94 | + } | |
95 | + } | |
96 | +} | |
97 | + | |
98 | +//int AppendBuffer::GetSize() | |
99 | +//{ | |
100 | +// int size = 0; | |
101 | +// for (AppendBuffer::Buffer *pb = this->head; pb; pb = pb->next) | |
102 | +// { | |
103 | +// size = size + sizeof(pb->buffer); | |
104 | +// } | |
105 | +// return size; | |
106 | +//} | |
107 | + | |
108 | + | |
109 | +void AppendBuffer::SetBuffer(AppendBuffer::Buffer *buf,const char * str, int len) | |
110 | +{ | |
111 | + memcpy(buf->buffer,str,len); | |
112 | + this->allSize+=len; | |
113 | + buf->bufferNowCount=len; | |
114 | +} | |
115 | + | |
116 | +int AppendBuffer::AppendString(const char * str) | |
117 | +{ | |
118 | + AppendString(str,(int)(strlen(str))); | |
119 | + return 0; | |
120 | +} | |
121 | + | |
122 | + | |
123 | +int AppendBuffer::AddABuffer(void) | |
124 | +{ | |
125 | + if(head==0) | |
126 | + { | |
127 | + head=NewABuffer(); | |
128 | + now=head; //now是当前的指针 | |
129 | + } | |
130 | + else | |
131 | + { | |
132 | + now->next=NewABuffer(); | |
133 | + now=now->next; | |
134 | + } | |
135 | + if(now==0)return 1;//stbstb | |
136 | + return 0; | |
137 | +} | |
138 | + | |
139 | +int AppendBuffer::AppendOtherOne(AppendBuffer * other) | |
140 | +{ | |
141 | + this->now->next=other->head; | |
142 | + this->now=other->now; | |
143 | + this->allSize+=other->allSize; | |
144 | + other->head=0; | |
145 | + //other->allSize=0; //stbstb | |
146 | + //other->now=0; | |
147 | + return 0; | |
148 | +} | |
149 | + | |
150 | +void AppendBuffer::Reset(void) | |
151 | +{ | |
152 | + for(;head;) | |
153 | + { | |
154 | + now=head; | |
155 | + head=now->next; | |
156 | + free(now->buffer); | |
157 | + delete now; | |
158 | + } | |
159 | + head=0; | |
160 | + now=0; | |
161 | + allSize=0; | |
162 | +} | |
163 | + | |
164 | +} | |
\ No newline at end of file | ... | ... |
src/core/renderer/AppendBuffer.h
0 → 100644
1 | +/************************************************************************** | |
2 | +* file: AppendBuffer.h | |
3 | + | |
4 | +* Author: qingxiongf | |
5 | +* Date: 2021-12-12 23:00:46 | |
6 | +* Email: qingxiongf@chinadci.com | |
7 | +* copyright: 广州城市信息研究所有限公司 | |
8 | +***************************************************************************/ | |
9 | + | |
10 | +#ifndef __AppendBuffer_h__ | |
11 | +#define __AppendBuffer_h__ | |
12 | + | |
13 | +#include "dmap_core.h" | |
14 | +#include "stdio.h" | |
15 | +#include <string> | |
16 | + | |
17 | +#define APPEND_BUFFER_SIZE 200000 | |
18 | + | |
19 | +namespace DmapCore_30 | |
20 | +{ | |
21 | + | |
22 | + class CORE_EXPORT AppendBuffer | |
23 | + { | |
24 | + public: | |
25 | + struct Buffer | |
26 | + { | |
27 | + Buffer *next; | |
28 | + char *buffer; | |
29 | + int bufferNowCount; | |
30 | + }; | |
31 | + | |
32 | + private: | |
33 | + FILE *f; | |
34 | + | |
35 | + | |
36 | + public: | |
37 | + int allSize; | |
38 | + AppendBuffer(void); | |
39 | + char *GetString(); | |
40 | + | |
41 | + std::string content_type; | |
42 | + | |
43 | + public: | |
44 | + ~AppendBuffer(void); | |
45 | + AppendBuffer(const char *fileName); | |
46 | + Buffer *head; | |
47 | + Buffer *now; | |
48 | + // char *bufferNow; | |
49 | + // char *bufferNowCount; | |
50 | + AppendBuffer::Buffer *NewABuffer(void); | |
51 | + | |
52 | + public: | |
53 | + void SetBuffer(AppendBuffer::Buffer *buf, const char *str, int len); | |
54 | + void AppendString(const char *str, int len); | |
55 | + /* int GetSize();*/ | |
56 | + public: | |
57 | + int AppendString(const char *str); | |
58 | + int AddABuffer(void); | |
59 | + | |
60 | + //int AppendString(const char * str); | |
61 | + //int AppendString(const char * str); | |
62 | + public: | |
63 | + int AppendOtherOne(AppendBuffer *other); | |
64 | + | |
65 | + public: | |
66 | + void Reset(void); | |
67 | + }; | |
68 | + | |
69 | +} // namespace DmapCore_30 | |
70 | + | |
71 | +#endif // __AppendBuffer_h__ | |
72 | + | ... | ... |
src/core/renderer/DataCollection.cpp
0 → 100644
1 | +#include "DataCollection.h" | |
2 | +#include "clsStruct.h" | |
3 | +//#include "Geometry.h" | |
4 | +#include "clsUtil.h" | |
5 | +#include <stdlib.h> | |
6 | + | |
7 | +namespace DmapCore_30 | |
8 | +{ | |
9 | + | |
10 | + DataCollection::DataCollection() | |
11 | + { | |
12 | + m_iPartCount = 0; | |
13 | + m_iStructType = 0; | |
14 | + m_pData = 0; //此指针只能够是自定义的6种结构体类型 | |
15 | + | |
16 | + m_dR = 1; | |
17 | + m_dScaleDenominator = 1; | |
18 | + m_dXdis = 1; | |
19 | + m_dYdis = 1; | |
20 | + | |
21 | + m_subset = 0; | |
22 | + | |
23 | + m_iN = 0; | |
24 | + } | |
25 | + | |
26 | + | |
27 | + void DataCollection::InitDataCollection(PGresult *res, int shapeType, int imageWidth, int imageHeight, | |
28 | + int subset, double r, | |
29 | + double dScaleDenominator, double x_dis, double y_dis) | |
30 | + { | |
31 | + //InitDataCollection(); | |
32 | + m_iN = 1; | |
33 | + //其他所有变量初始化 | |
34 | + m_iPartCount = PQntuples(res); | |
35 | + m_dR = r; | |
36 | + m_dScaleDenominator = dScaleDenominator; | |
37 | + m_dXdis = x_dis; | |
38 | + m_dYdis = y_dis; | |
39 | + m_imageWidth = imageWidth; | |
40 | + m_imageHeight = imageHeight; | |
41 | + | |
42 | + if (subset < 0) | |
43 | + { | |
44 | + m_subset = 2; | |
45 | + } | |
46 | + else | |
47 | + { | |
48 | + m_subset = subset + 2; | |
49 | + } | |
50 | + | |
51 | + this->CollectFieldName(res); | |
52 | + | |
53 | + switch (shapeType) | |
54 | + { | |
55 | + case GeometryType_Point: | |
56 | + MallocForPoint(res); | |
57 | + break; | |
58 | + case GeometryType_MultiPoint: | |
59 | + break; | |
60 | + case GeometryType_LineString: | |
61 | + MallocForLineStringGeom(res); | |
62 | + break; | |
63 | + case GeometryType_MultiLineString: | |
64 | + MallocForLineStringGeom(res); | |
65 | + break; | |
66 | + case GeometryType_Polygon: | |
67 | + MallocForPolygonForGeom(res); | |
68 | + break; | |
69 | + case GeometryType_MultiPolygon: | |
70 | + MallocForPolygonForGeom(res); | |
71 | + break; | |
72 | + default: | |
73 | + | |
74 | + break; | |
75 | + } | |
76 | + //CollectAllField(res); | |
77 | + } | |
78 | + | |
79 | + | |
80 | +/* | |
81 | + void DataCollection::InitDataCollection(Geometry *geom, double r, double dScaleDenominator, | |
82 | + double x_dis, double y_dis) | |
83 | + { | |
84 | + //InitDataCollection(); | |
85 | + m_iN = 1; | |
86 | + m_iPartCount = 1; | |
87 | + m_dR = r; | |
88 | + m_dScaleDenominator = dScaleDenominator; | |
89 | + m_dXdis = x_dis; | |
90 | + m_dYdis = y_dis; | |
91 | + | |
92 | + int geomType = geom->GeometryType(); | |
93 | + switch (geomType) | |
94 | + { | |
95 | + case dmapGeometryPoint: | |
96 | + { | |
97 | + Point *p = (Point *)geom; | |
98 | + this->MallocForPoint(p); | |
99 | + break; | |
100 | + } | |
101 | + case dmapGeometryMultiPoint: | |
102 | + { | |
103 | + MultiPoint *mp = (MultiPoint *)geom; | |
104 | + this->MallocForMultiPoint(mp); | |
105 | + break; | |
106 | + } | |
107 | + case dmapGeometryPath: | |
108 | + { | |
109 | + Path *path = (Path *)geom; | |
110 | + this->MallocForPath(path); | |
111 | + break; | |
112 | + } | |
113 | + case dmapGeometryMultiLineString: | |
114 | + { | |
115 | + MultiLineString *ml = (MultiLineString *)geom; | |
116 | + this->MallocForMultiLineString(ml); | |
117 | + break; | |
118 | + } | |
119 | + case dmapGeometryRing: | |
120 | + { | |
121 | + Ring *ring = (Ring *)geom; | |
122 | + this->MallocForRing(ring); | |
123 | + break; | |
124 | + } | |
125 | + case dmapGeometryPolygon: | |
126 | + { | |
127 | + Polygon *pPolygon = (Polygon *)geom; | |
128 | + this->MallocForPolygon(pPolygon); | |
129 | + break; | |
130 | + } | |
131 | + case dmapGeometryMultiPolygon: | |
132 | + { | |
133 | + MultiPolygon *mp = (MultiPolygon *)geom; | |
134 | + this->MallocForMultiPolygon(mp); | |
135 | + break; | |
136 | + } | |
137 | + default: | |
138 | + break; | |
139 | + } | |
140 | + }*/ | |
141 | + | |
142 | + | |
143 | + DataCollection::~DataCollection() | |
144 | + { | |
145 | + //cout<<"free begin;" <<endl; | |
146 | + if (m_pData) | |
147 | + { | |
148 | + switch (m_iStructType) | |
149 | + { | |
150 | + case clsStruct::Struct_Point: | |
151 | + { | |
152 | + this->FreeForPOINT(); | |
153 | + break; | |
154 | + } | |
155 | + case clsStruct::Struct_Line: | |
156 | + { | |
157 | + this->FreeForLINE(); | |
158 | + break; | |
159 | + } | |
160 | + case clsStruct::Struct_MLine: | |
161 | + { | |
162 | + this->FreeForMLINE(); | |
163 | + break; | |
164 | + } | |
165 | + case clsStruct::Struct_Polygon: | |
166 | + { | |
167 | + this->FreeForPOLYGON(); | |
168 | + break; | |
169 | + } | |
170 | + case clsStruct::Struct_MPolygon: | |
171 | + { | |
172 | + this->FreeForMPOLYGON(); | |
173 | + break; | |
174 | + } | |
175 | + default: | |
176 | + break; | |
177 | + } | |
178 | + } | |
179 | + //cout<<"free end;" <<endl; | |
180 | + } | |
181 | + | |
182 | + | |
183 | + | |
184 | + /* | |
185 | + Malloc PGresult | |
186 | + */ | |
187 | + bool DataCollection::MallocForPoint(PGresult *res) | |
188 | + { | |
189 | + m_iStructType = clsStruct::Struct_Point; | |
190 | + | |
191 | + int n_fields = PQnfields(res); | |
192 | + map<int, PointClass *> map_Point; | |
193 | + | |
194 | + for (size_t i = 0; i < m_iPartCount; i++) | |
195 | + { | |
196 | + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0); | |
197 | + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16; | |
198 | + unsigned char hasZ = hasZorSrsid / 8; | |
199 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
200 | + | |
201 | + int not_big = here[0]; | |
202 | + here++; | |
203 | + int shapetype = ((int *)here)[0]; | |
204 | + here += 4; | |
205 | + if (hasSrsid) | |
206 | + here += 4; | |
207 | + | |
208 | + double x = ((double *)here)[0]; | |
209 | + here += 8; // clsUtil::ReadDouble(here, not_big); | |
210 | + double y = ((double *)here)[0]; | |
211 | + here += 8; // clsUtil::ReadDouble(here, not_big); | |
212 | + double x0 = 0, y0 = 0; | |
213 | + this->ToScale(x, y, x0, y0); | |
214 | + | |
215 | + int key = ((int)(x0 / m_subset)) * 10000 + ((int)(y0 / m_subset)); | |
216 | + if (map_Point.find(key) == map_Point.end()) | |
217 | + { | |
218 | + PointClass *pointClass = new PointClass(); | |
219 | + pointClass->x = x0; | |
220 | + pointClass->y = y0; | |
221 | + /*clsStruct::POINT* pp0 = new clsStruct::POINT(); | |
222 | + pp0->x = x0; | |
223 | + pp0->y = y0;*/ | |
224 | + map_Point[key] = pointClass; | |
225 | + for (int i0 = 1; i0 < n_fields; i0++) | |
226 | + { | |
227 | + char *vc = PQgetvalue(res, i, i0); | |
228 | + pointClass->m_pdata.push_back(vc); | |
229 | + } | |
230 | + } | |
231 | + } | |
232 | + | |
233 | + clsStruct::POINT *pp = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * map_Point.size()); | |
234 | + if (pp == NULL) | |
235 | + return false; | |
236 | + int index = 0; | |
237 | + | |
238 | + //创建预留空间 | |
239 | + m_vAllField.resize(map_Point.size()); | |
240 | + for (int i = 0; i < map_Point.size(); i++) | |
241 | + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的 | |
242 | + //开辟预留空间后, 可以直接赋值,不需要 pushback | |
243 | + | |
244 | + for (map<int, PointClass *>::iterator iter = map_Point.begin(); iter != map_Point.end(); iter++) | |
245 | + { | |
246 | + PointClass *p = iter->second; | |
247 | + pp[index].x = p->x; | |
248 | + pp[index].y = p->y; | |
249 | + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始 | |
250 | + { | |
251 | + m_vAllField[index][j] = p->m_pdata.at(j); | |
252 | + } | |
253 | + p->m_pdata.clear(); | |
254 | + delete p; | |
255 | + iter->second = NULL; | |
256 | + index++; | |
257 | + } | |
258 | + | |
259 | + this->m_iPartCount = map_Point.size(); | |
260 | + | |
261 | + map_Point.clear(); | |
262 | + | |
263 | + m_pData = pp; | |
264 | + return true; | |
265 | + } | |
266 | + | |
267 | + bool DataCollection::MallocForLineStringGeom(PGresult *res) | |
268 | + { | |
269 | + m_iStructType = clsStruct::Struct_MLine; | |
270 | + // bool isLineZ = false; | |
271 | + int n_fields = PQnfields(res); | |
272 | + clsStruct::MLINE *pp = (clsStruct::MLINE *)malloc(sizeof(clsStruct::MLINE) * m_iPartCount); | |
273 | + if (pp == NULL) | |
274 | + return false; | |
275 | + m_vAllField.resize(m_iPartCount); | |
276 | + for (int i = 0; i < m_iPartCount; i++) | |
277 | + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的 | |
278 | + | |
279 | + for (int i = 0; i < m_iPartCount; i++) | |
280 | + { | |
281 | + | |
282 | + //clsStruct::MLINE ml; | |
283 | + | |
284 | + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0); | |
285 | + unsigned char geom_type = (here)[1]; | |
286 | + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16; | |
287 | + unsigned char hasZ = hasZorSrsid / 8; | |
288 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
289 | + int not_big = clsUtil::ReadByte(here); | |
290 | + int shapetype = clsUtil::ReadInt(here, not_big); | |
291 | + if (hasSrsid) | |
292 | + here += 4; | |
293 | + //if (shapetype < 0) isLineZ = true; | |
294 | + if (geom_type == DCGeometryType::GeometryType_LineString) | |
295 | + { | |
296 | + int nLine = 1;//clsUtil::ReadInt(here, not_big); | |
297 | + clsStruct::LINE *pPath = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nLine); | |
298 | + if (pPath == 0) | |
299 | + continue; | |
300 | + pp[i].nLine = nLine; | |
301 | + pp[i].p = pPath; | |
302 | + | |
303 | + for (int j = 0; j < nLine; j++) | |
304 | + { | |
305 | + //clsStruct::LINE path; | |
306 | + | |
307 | + //int not_big2 = clsUtil::ReadByte(here); | |
308 | + //here += 4; //跳过 shapetype 读取 | |
309 | + | |
310 | + int nPoint = clsUtil::ReadInt(here, not_big); | |
311 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint); | |
312 | + if (pPoint == 0) | |
313 | + continue; | |
314 | + pPath[j].nPoint = nPoint; | |
315 | + pPath[j].p = pPoint; | |
316 | + | |
317 | + for (int k = 0; k < nPoint; k++) | |
318 | + { | |
319 | + //clsStruct::POINT point; | |
320 | + | |
321 | + double x = clsUtil::ReadDouble(here, not_big); | |
322 | + double y = clsUtil::ReadDouble(here, not_big); | |
323 | + if (hasZ) | |
324 | + { | |
325 | + //Z 值跳过 | |
326 | + here += 8; | |
327 | + } | |
328 | + double x0 = 0, y0 = 0; | |
329 | + this->ToScale(x, y, x0, y0); | |
330 | + | |
331 | + pPoint[k].x = x0; | |
332 | + pPoint[k].y = y0; | |
333 | + } | |
334 | + } | |
335 | + } | |
336 | + else if (geom_type == DCGeometryType::GeometryType_MultiLineString) | |
337 | + { | |
338 | + int nLine = clsUtil::ReadInt(here, not_big); | |
339 | + clsStruct::LINE *pPath = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nLine); | |
340 | + if (pPath == 0) | |
341 | + continue; | |
342 | + pp[i].nLine = nLine; | |
343 | + pp[i].p = pPath; | |
344 | + | |
345 | + for (int j = 0; j < nLine; j++) | |
346 | + { | |
347 | + //clsStruct::LINE path; | |
348 | + | |
349 | + int not_big2 = clsUtil::ReadByte(here); | |
350 | + here += 4; //跳过 shapetype 读取 | |
351 | + | |
352 | + int nPoint = clsUtil::ReadInt(here, not_big2); | |
353 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint); | |
354 | + if (pPoint == 0) | |
355 | + continue; | |
356 | + pPath[j].nPoint = nPoint; | |
357 | + pPath[j].p = pPoint; | |
358 | + | |
359 | + for (int k = 0; k < nPoint; k++) | |
360 | + { | |
361 | + //clsStruct::POINT point; | |
362 | + | |
363 | + double x = clsUtil::ReadDouble(here, not_big2); | |
364 | + double y = clsUtil::ReadDouble(here, not_big2); | |
365 | + if (hasZ) | |
366 | + { | |
367 | + //Z 值跳过 | |
368 | + here += 8; | |
369 | + } | |
370 | + double x0 = 0, y0 = 0; | |
371 | + this->ToScale(x, y, x0, y0); | |
372 | + | |
373 | + pPoint[k].x = x0; | |
374 | + pPoint[k].y = y0; | |
375 | + } | |
376 | + } | |
377 | + } | |
378 | + | |
379 | + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始 | |
380 | + { | |
381 | + m_vAllField[i][j] = (char *)PQgetvalue(res, i, j + 1); | |
382 | + } | |
383 | + /*ml.nLine = nLine; | |
384 | + ml.p = pPath; | |
385 | + pp[i] = ml;*/ | |
386 | + } | |
387 | + | |
388 | + m_pData = pp; | |
389 | + return true; | |
390 | + } | |
391 | + | |
392 | + bool DataCollection::MallocForMultiLineString(PGresult *res) | |
393 | + { | |
394 | + m_iStructType = clsStruct::Struct_MLine; | |
395 | + // bool isLineZ = false; | |
396 | + int n_fields = PQnfields(res); | |
397 | + clsStruct::MLINE *pp = (clsStruct::MLINE *)malloc(sizeof(clsStruct::MLINE) * m_iPartCount); | |
398 | + if (pp == NULL) | |
399 | + return false; | |
400 | + m_vAllField.resize(m_iPartCount); | |
401 | + for (int i = 0; i < m_iPartCount; i++) | |
402 | + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的 | |
403 | + | |
404 | + for (int i = 0; i < m_iPartCount; i++) | |
405 | + { | |
406 | + | |
407 | + //clsStruct::MLINE ml; | |
408 | + | |
409 | + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0); | |
410 | + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16; | |
411 | + unsigned char hasZ = hasZorSrsid / 8; | |
412 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
413 | + int not_big = clsUtil::ReadByte(here); | |
414 | + int shapetype = clsUtil::ReadInt(here, not_big); | |
415 | + if (hasSrsid) | |
416 | + here += 4; | |
417 | + //if (shapetype < 0) isLineZ = true; | |
418 | + | |
419 | + int nLine = clsUtil::ReadInt(here, not_big); | |
420 | + clsStruct::LINE *pPath = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nLine); | |
421 | + if (pPath == 0) | |
422 | + continue; | |
423 | + pp[i].nLine = nLine; | |
424 | + pp[i].p = pPath; | |
425 | + | |
426 | + for (int j = 0; j < nLine; j++) | |
427 | + { | |
428 | + //clsStruct::LINE path; | |
429 | + | |
430 | + int not_big2 = clsUtil::ReadByte(here); | |
431 | + here += 4; //跳过 shapetype 读取 | |
432 | + | |
433 | + int nPoint = clsUtil::ReadInt(here, not_big2); | |
434 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint); | |
435 | + if (pPoint == 0) | |
436 | + continue; | |
437 | + pPath[j].nPoint = nPoint; | |
438 | + pPath[j].p = pPoint; | |
439 | + | |
440 | + for (int k = 0; k < nPoint; k++) | |
441 | + { | |
442 | + //clsStruct::POINT point; | |
443 | + | |
444 | + double x = clsUtil::ReadDouble(here, not_big2); | |
445 | + double y = clsUtil::ReadDouble(here, not_big2); | |
446 | + if (hasZ) | |
447 | + { | |
448 | + //Z 值跳过 | |
449 | + here += 8; | |
450 | + } | |
451 | + double x0 = 0, y0 = 0; | |
452 | + this->ToScale(x, y, x0, y0); | |
453 | + | |
454 | + pPoint[k].x = x0; | |
455 | + pPoint[k].y = y0; | |
456 | + } | |
457 | + | |
458 | + /*path.nPoint = nPoint; | |
459 | + path.p = pPoint; | |
460 | + pPath[j] = path;*/ | |
461 | + } | |
462 | + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始 | |
463 | + { | |
464 | + m_vAllField[i][j] = (char *)PQgetvalue(res, i, j + 1); | |
465 | + } | |
466 | + /*ml.nLine = nLine; | |
467 | + ml.p = pPath; | |
468 | + pp[i] = ml;*/ | |
469 | + } | |
470 | + | |
471 | + m_pData = pp; | |
472 | + return true; | |
473 | + } | |
474 | + | |
475 | + | |
476 | + | |
477 | + bool DataCollection::PolygonIsLessThanOnePixel(unsigned char *here, int not_big1) | |
478 | + { | |
479 | + double dpix = 1 / this->m_dR; | |
480 | + here += 9; | |
481 | + int npolygonCount = clsUtil::ReadInt(here, not_big1); | |
482 | + | |
483 | + double x0 = clsUtil::ReadDouble(here, not_big1); | |
484 | + double y0 = clsUtil::ReadDouble(here, not_big1); | |
485 | + | |
486 | + if (npolygonCount < 6) | |
487 | + { | |
488 | + int step = (npolygonCount / 2); | |
489 | + here += step * 16; | |
490 | + double x = clsUtil::ReadDouble(here, not_big1); | |
491 | + double y = clsUtil::ReadDouble(here, not_big1); | |
492 | + if (abs(x - x0) < dpix && abs(y - y0) < dpix) | |
493 | + { | |
494 | + return true; | |
495 | + } | |
496 | + } | |
497 | + else if (npolygonCount < 35) | |
498 | + { | |
499 | + int step = (npolygonCount / 3); | |
500 | + here += step * 16; | |
501 | + double x1 = clsUtil::ReadDouble(here, not_big1); | |
502 | + double y1 = clsUtil::ReadDouble(here, not_big1); | |
503 | + | |
504 | + here += step * 16; | |
505 | + double x2 = clsUtil::ReadDouble(here, not_big1); | |
506 | + double y2 = clsUtil::ReadDouble(here, not_big1); | |
507 | + if (abs(x1 - x0) < dpix && abs(y1 - y0) < dpix && | |
508 | + abs(x2 - x0) < dpix && abs(y2 - y0) < dpix) | |
509 | + { | |
510 | + return true; | |
511 | + } | |
512 | + } | |
513 | + else | |
514 | + { | |
515 | + for (int step = 10; step < npolygonCount; step += 11) | |
516 | + { | |
517 | + here += 10 * 16; | |
518 | + double x1 = clsUtil::ReadDouble(here, not_big1); | |
519 | + double y1 = clsUtil::ReadDouble(here, not_big1); | |
520 | + if (abs(x1 - x0) > dpix || abs(y1 - y0) > dpix) | |
521 | + { | |
522 | + return false; | |
523 | + } | |
524 | + } | |
525 | + | |
526 | + return true; | |
527 | + } | |
528 | + return false; | |
529 | + } | |
530 | + | |
531 | + bool DataCollection::MallocForPolygonForGeom(PGresult *res) | |
532 | + { | |
533 | + bool allPolygonToPoint = false; | |
534 | + | |
535 | + if (m_imageWidth > 0 && m_imageHeight > 0) | |
536 | + { | |
537 | + allPolygonToPoint = m_iPartCount > (m_imageWidth * m_imageHeight / 8); | |
538 | + } | |
539 | + | |
540 | + //double maxcount = (d1* d2)/1.5; | |
541 | + //bool isPolygonZ = false; | |
542 | + m_iStructType = clsStruct::Struct_MPolygon; | |
543 | + int n_fields = PQnfields(res); | |
544 | + | |
545 | + clsStruct::MPOLYGON *pp = (clsStruct::MPOLYGON *)malloc(sizeof(clsStruct::MPOLYGON) * m_iPartCount); | |
546 | + if (pp == NULL) | |
547 | + return false; | |
548 | + m_vAllField.resize(m_iPartCount); | |
549 | + for (int i = 0; i < m_iPartCount; i++) | |
550 | + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的 | |
551 | + | |
552 | + for (int i = 0; i < m_iPartCount; i++) | |
553 | + { | |
554 | + | |
555 | + int not_big1, not_big2, shapetype1, nring, npoint, srid; | |
556 | + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0); | |
557 | + | |
558 | + unsigned char geom_type = (here)[1]; | |
559 | + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16; | |
560 | + unsigned char hasZ = hasZorSrsid / 8; | |
561 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
562 | + // printf("%d %d \r\n",i,geom_type ); | |
563 | + not_big1 = clsUtil::ReadByte(here); | |
564 | + shapetype1 = clsUtil::ReadInt(here, not_big1); | |
565 | + if (hasSrsid) | |
566 | + srid = clsUtil::ReadInt(here, not_big1); //跳过srid | |
567 | + //if (shapetype1 < 0) isPolygonZ = true; | |
568 | + if (geom_type == DCGeometryType::GeometryType_Point) | |
569 | + { | |
570 | + double x = clsUtil::ReadDouble(here, not_big1); | |
571 | + double y = clsUtil::ReadDouble(here, not_big1); | |
572 | + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON)); | |
573 | + if (pPgon == NULL) | |
574 | + { | |
575 | + free(pp); | |
576 | + pp = 0; | |
577 | + break; | |
578 | + } | |
579 | + | |
580 | + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE)); | |
581 | + if (pRing == NULL) | |
582 | + { | |
583 | + free(pp); | |
584 | + pp = 0; | |
585 | + free(pPgon); | |
586 | + pPgon = 0; | |
587 | + break; | |
588 | + } | |
589 | + | |
590 | + pPgon[0].nRing = 1; | |
591 | + pPgon[0].p = pRing; | |
592 | + | |
593 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT)); | |
594 | + | |
595 | + pRing[0].nPoint = 1; | |
596 | + pRing[0].p = pPoint; | |
597 | + | |
598 | + double x0 = 0, y0 = 0; | |
599 | + this->ToScale(x, y, x0, y0); | |
600 | + pPoint[0].x = x0; | |
601 | + pPoint[0].y = y0; | |
602 | + | |
603 | + pp[i].nPolygon = 1; | |
604 | + pp[i].p = pPgon; | |
605 | + } | |
606 | + else if (geom_type == DCGeometryType::GeometryType_Polygon) | |
607 | + { | |
608 | + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON) * 1); | |
609 | + //clsStruct::MPOLYGON mpgon; | |
610 | + if (pPgon == NULL) | |
611 | + continue; | |
612 | + pp[i].nPolygon = 1; | |
613 | + pp[i].p = pPgon; | |
614 | + | |
615 | + //for (int j = 0; j < npolygon; j++) | |
616 | + { | |
617 | + //not_big2 = clsUtil::ReadByte(here); | |
618 | + //here += 4; //跳过 shapetype, 没意义, 必然是polygon | |
619 | + | |
620 | + nring = clsUtil::ReadInt(here, not_big1); | |
621 | + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nring); | |
622 | + if (pRing == NULL) | |
623 | + break; | |
624 | + pPgon[0].nRing = nring; | |
625 | + pPgon[0].p = pRing; | |
626 | + | |
627 | + for (int k = 0; k < nring; k++) | |
628 | + { | |
629 | + npoint = clsUtil::ReadInt(here, not_big1); | |
630 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint); | |
631 | + if (pPoint == NULL) | |
632 | + break; | |
633 | + pRing[k].nPoint = npoint; | |
634 | + pRing[k].p = pPoint; | |
635 | + //clsStruct::LINE ring; | |
636 | + | |
637 | + for (int m = 0; m < npoint; m++) | |
638 | + { | |
639 | + double x = clsUtil::ReadDouble(here, not_big1); | |
640 | + double y = clsUtil::ReadDouble(here, not_big1); | |
641 | + if (hasZ) | |
642 | + { | |
643 | + //Z 值跳过 | |
644 | + here += 8; | |
645 | + } | |
646 | + double x0 = 0, y0 = 0; | |
647 | + this->ToScale(x, y, x0, y0); | |
648 | + | |
649 | + pPoint[m].x = x0; | |
650 | + pPoint[m].y = y0; | |
651 | + } | |
652 | + } | |
653 | + } | |
654 | + } | |
655 | + else if (geom_type == DCGeometryType::GeometryType_MultiPolygon) | |
656 | + { | |
657 | + int npolygon = clsUtil::ReadInt(here, not_big1); | |
658 | + | |
659 | + if (PolygonIsLessThanOnePixel(here, not_big1)) | |
660 | + { | |
661 | + //here += 4; | |
662 | + //npolygon = clsUtil::ReadInt(here, not_big1) | |
663 | + not_big2 = clsUtil::ReadByte(here); | |
664 | + here += 12; | |
665 | + double x = clsUtil::ReadDouble(here, not_big2); | |
666 | + double y = clsUtil::ReadDouble(here, not_big2); | |
667 | + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON)); | |
668 | + if (pPgon == NULL) | |
669 | + { | |
670 | + free(pp); | |
671 | + pp = 0; | |
672 | + break; | |
673 | + } | |
674 | + | |
675 | + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE)); | |
676 | + if (pRing == NULL) | |
677 | + { | |
678 | + free(pp); | |
679 | + pp = 0; | |
680 | + free(pPgon); | |
681 | + pPgon = 0; | |
682 | + break; | |
683 | + } | |
684 | + | |
685 | + pPgon[0].nRing = 1; | |
686 | + pPgon[0].p = pRing; | |
687 | + | |
688 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT)); | |
689 | + | |
690 | + pRing[0].nPoint = 1; | |
691 | + pRing[0].p = pPoint; | |
692 | + | |
693 | + double x0 = 0, y0 = 0; | |
694 | + this->ToScale(x, y, x0, y0); | |
695 | + pPoint[0].x = x0; | |
696 | + pPoint[0].y = y0; | |
697 | + | |
698 | + pp[i].nPolygon = 1; | |
699 | + pp[i].p = pPgon; | |
700 | + } | |
701 | + else | |
702 | + { | |
703 | + | |
704 | + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON) * npolygon); | |
705 | + //clsStruct::MPOLYGON mpgon; | |
706 | + if (pPgon == NULL) | |
707 | + continue; | |
708 | + pp[i].nPolygon = npolygon; | |
709 | + pp[i].p = pPgon; | |
710 | + | |
711 | + for (int j = 0; j < npolygon; j++) | |
712 | + { | |
713 | + not_big2 = clsUtil::ReadByte(here); | |
714 | + here += 4; //跳过 shapetype, 没意义, 必然是polygon | |
715 | + | |
716 | + nring = clsUtil::ReadInt(here, not_big2); | |
717 | + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nring); | |
718 | + if (pRing == NULL) | |
719 | + break; | |
720 | + pPgon[j].nRing = nring; | |
721 | + pPgon[j].p = pRing; | |
722 | + //clsStruct::POLYGON pgon; | |
723 | + | |
724 | + for (int k = 0; k < nring; k++) | |
725 | + { | |
726 | + npoint = clsUtil::ReadInt(here, not_big2); | |
727 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint); | |
728 | + if (pPoint == NULL) | |
729 | + break; | |
730 | + pRing[k].nPoint = npoint; | |
731 | + pRing[k].p = pPoint; | |
732 | + //clsStruct::LINE ring; | |
733 | + | |
734 | + for (int m = 0; m < npoint; m++) | |
735 | + { | |
736 | + double x = clsUtil::ReadDouble(here, not_big2); | |
737 | + double y = clsUtil::ReadDouble(here, not_big2); | |
738 | + if (hasZ) | |
739 | + { | |
740 | + //Z 值跳过 | |
741 | + here += 8; | |
742 | + } | |
743 | + double x0 = 0, y0 = 0; | |
744 | + this->ToScale(x, y, x0, y0); | |
745 | + | |
746 | + pPoint[m].x = x0; | |
747 | + pPoint[m].y = y0; | |
748 | + } | |
749 | + } | |
750 | + } | |
751 | + } | |
752 | + } | |
753 | + | |
754 | + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始 | |
755 | + { | |
756 | + m_vAllField[i][j] = (char *)PQgetvalue(res, i, j + 1); | |
757 | + } | |
758 | + } | |
759 | + | |
760 | + m_pData = pp; | |
761 | + return true; | |
762 | + } | |
763 | + | |
764 | + bool DataCollection::MallocForPolygon(PGresult *res) | |
765 | + { | |
766 | + | |
767 | + //double d1 = (queryX2 - queryX1)*m_dR; | |
768 | + //double d2 = (queryY2 - queryY1)*m_dR; | |
769 | + | |
770 | + bool allPolygonToPoint = false; | |
771 | + | |
772 | + if (m_imageWidth > 0 && m_imageHeight > 0) | |
773 | + { | |
774 | + allPolygonToPoint = m_iPartCount > (m_imageWidth * m_imageHeight / 8); | |
775 | + } | |
776 | + | |
777 | + //double maxcount = (d1* d2)/1.5; | |
778 | + //bool isPolygonZ = false; | |
779 | + m_iStructType = clsStruct::Struct_MPolygon; | |
780 | + int n_fields = PQnfields(res); | |
781 | + | |
782 | + clsStruct::MPOLYGON *pp = (clsStruct::MPOLYGON *)malloc(sizeof(clsStruct::MPOLYGON) * m_iPartCount); | |
783 | + if (pp == NULL) | |
784 | + return false; | |
785 | + m_vAllField.resize(m_iPartCount); | |
786 | + for (int i = 0; i < m_iPartCount; i++) | |
787 | + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的 | |
788 | + | |
789 | + for (int i = 0; i < m_iPartCount; i++) | |
790 | + { | |
791 | + | |
792 | + int not_big1, not_big2, shapetype1, nring, npoint; | |
793 | + // unsigned char *here1 = (unsigned char *)PQgetvalue(res, i, 0); | |
794 | + // shared_ptr<PolygonClass> dd = GetDataPolygon(here1); | |
795 | + // continue; | |
796 | + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0); | |
797 | + | |
798 | + unsigned char geom_type = (here)[1]; | |
799 | + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16; | |
800 | + unsigned char hasZ = hasZorSrsid / 8; | |
801 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
802 | + | |
803 | + not_big1 = clsUtil::ReadByte(here); | |
804 | + shapetype1 = clsUtil::ReadInt(here, not_big1); | |
805 | + if (hasSrsid) | |
806 | + shapetype1 = clsUtil::ReadInt(here, not_big1); //跳过srid | |
807 | + //if (shapetype1 < 0) isPolygonZ = true; | |
808 | + if (geom_type == DCGeometryType::GeometryType_Point) | |
809 | + { | |
810 | + double x = clsUtil::ReadDouble(here, not_big1); | |
811 | + double y = clsUtil::ReadDouble(here, not_big1); | |
812 | + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON)); | |
813 | + if (pPgon == NULL) | |
814 | + { | |
815 | + free(pp); | |
816 | + pp = 0; | |
817 | + break; | |
818 | + } | |
819 | + | |
820 | + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE)); | |
821 | + if (pRing == NULL) | |
822 | + { | |
823 | + free(pp); | |
824 | + pp = 0; | |
825 | + free(pPgon); | |
826 | + pPgon = 0; | |
827 | + break; | |
828 | + } | |
829 | + | |
830 | + pPgon[0].nRing = 1; | |
831 | + pPgon[0].p = pRing; | |
832 | + | |
833 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT)); | |
834 | + | |
835 | + pRing[0].nPoint = 1; | |
836 | + pRing[0].p = pPoint; | |
837 | + | |
838 | + double x0 = 0, y0 = 0; | |
839 | + this->ToScale(x, y, x0, y0); | |
840 | + pPoint[0].x = x0; | |
841 | + pPoint[0].y = y0; | |
842 | + | |
843 | + pp[i].nPolygon = 1; | |
844 | + pp[i].p = pPgon; | |
845 | + } | |
846 | + else | |
847 | + { | |
848 | + //nring = clsUtil::ReadInt(here, not_big1); | |
849 | + //npolygon = clsUtil::ReadInt(here, not_big1); | |
850 | + | |
851 | + if (false) | |
852 | + { | |
853 | + //here += 4; | |
854 | + //npolygon = clsUtil::ReadInt(here, not_big1) | |
855 | + not_big2 = clsUtil::ReadByte(here); | |
856 | + here += 12; | |
857 | + double x = clsUtil::ReadDouble(here, not_big2); | |
858 | + double y = clsUtil::ReadDouble(here, not_big2); | |
859 | + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON)); | |
860 | + if (pPgon == NULL) | |
861 | + { | |
862 | + free(pp); | |
863 | + pp = 0; | |
864 | + break; | |
865 | + } | |
866 | + | |
867 | + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE)); | |
868 | + if (pRing == NULL) | |
869 | + { | |
870 | + free(pp); | |
871 | + pp = 0; | |
872 | + free(pPgon); | |
873 | + pPgon = 0; | |
874 | + break; | |
875 | + } | |
876 | + | |
877 | + pPgon[0].nRing = 1; | |
878 | + pPgon[0].p = pRing; | |
879 | + | |
880 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT)); | |
881 | + | |
882 | + pRing[0].nPoint = 1; | |
883 | + pRing[0].p = pPoint; | |
884 | + | |
885 | + double x0 = 0, y0 = 0; | |
886 | + this->ToScale(x, y, x0, y0); | |
887 | + pPoint[0].x = x0; | |
888 | + pPoint[0].y = y0; | |
889 | + | |
890 | + pp[i].nPolygon = 1; | |
891 | + pp[i].p = pPgon; | |
892 | + } | |
893 | + else | |
894 | + { | |
895 | + | |
896 | + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON) * 1); | |
897 | + //clsStruct::MPOLYGON mpgon; | |
898 | + if (pPgon == NULL) | |
899 | + continue; | |
900 | + pp[i].nPolygon = 1; | |
901 | + pp[i].p = pPgon; | |
902 | + | |
903 | + //for (int j = 0; j < npolygon; j++) | |
904 | + { | |
905 | + //not_big2 = clsUtil::ReadByte(here); | |
906 | + //here += 4; //跳过 shapetype, 没意义, 必然是polygon | |
907 | + | |
908 | + nring = clsUtil::ReadInt(here, not_big2); | |
909 | + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nring); | |
910 | + if (pRing == NULL) | |
911 | + break; | |
912 | + pPgon[0].nRing = nring; | |
913 | + pPgon[0].p = pRing; | |
914 | + | |
915 | + for (int k = 0; k < nring; k++) | |
916 | + { | |
917 | + npoint = clsUtil::ReadInt(here, not_big2); | |
918 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint); | |
919 | + if (pPoint == NULL) | |
920 | + break; | |
921 | + pRing[k].nPoint = npoint; | |
922 | + pRing[k].p = pPoint; | |
923 | + //clsStruct::LINE ring; | |
924 | + | |
925 | + for (int m = 0; m < npoint; m++) | |
926 | + { | |
927 | + double x = clsUtil::ReadDouble(here, not_big2); | |
928 | + double y = clsUtil::ReadDouble(here, not_big2); | |
929 | + if (hasZ) | |
930 | + { | |
931 | + //Z 值跳过 | |
932 | + here += 8; | |
933 | + } | |
934 | + double x0 = 0, y0 = 0; | |
935 | + this->ToScale(x, y, x0, y0); | |
936 | + | |
937 | + pPoint[m].x = x0; | |
938 | + pPoint[m].y = y0; | |
939 | + } | |
940 | + } | |
941 | + } | |
942 | + } | |
943 | + } | |
944 | + | |
945 | + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始 | |
946 | + { | |
947 | + m_vAllField[i][j] = (char *)PQgetvalue(res, i, j + 1); | |
948 | + } | |
949 | + } | |
950 | + | |
951 | + m_pData = pp; | |
952 | + return true; | |
953 | + } | |
954 | + | |
955 | + bool DataCollection::MallocForMultiPolygon(PGresult *res) | |
956 | + { | |
957 | + | |
958 | + //double d1 = (queryX2 - queryX1)*m_dR; | |
959 | + //double d2 = (queryY2 - queryY1)*m_dR; | |
960 | + | |
961 | + bool allPolygonToPoint = false; | |
962 | + | |
963 | + if (m_imageWidth > 0 && m_imageHeight > 0) | |
964 | + { | |
965 | + allPolygonToPoint = m_iPartCount > (m_imageWidth * m_imageHeight / 8); | |
966 | + } | |
967 | + | |
968 | + //double maxcount = (d1* d2)/1.5; | |
969 | + //bool isPolygonZ = false; | |
970 | + m_iStructType = clsStruct::Struct_MPolygon; | |
971 | + int n_fields = PQnfields(res); | |
972 | + | |
973 | + clsStruct::MPOLYGON *pp = (clsStruct::MPOLYGON *)malloc(sizeof(clsStruct::MPOLYGON) * m_iPartCount); | |
974 | + if (pp == NULL) | |
975 | + return false; | |
976 | + m_vAllField.resize(m_iPartCount); | |
977 | + for (int i = 0; i < m_iPartCount; i++) | |
978 | + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的 | |
979 | + | |
980 | + for (int i = 0; i < m_iPartCount; i++) | |
981 | + { | |
982 | + | |
983 | + int not_big1, not_big2, shapetype1, npolygon, nring, npoint; | |
984 | + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0); | |
985 | + unsigned char geom_type = (here)[1]; | |
986 | + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16; | |
987 | + unsigned char hasZ = hasZorSrsid / 8; | |
988 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
989 | + not_big1 = clsUtil::ReadByte(here); | |
990 | + shapetype1 = clsUtil::ReadInt(here, not_big1); | |
991 | + if (hasSrsid) | |
992 | + here += 4; //跳过srid | |
993 | + //if (shapetype1 < 0) isPolygonZ = true; | |
994 | + if (geom_type == DCGeometryType::GeometryType_Point) | |
995 | + { | |
996 | + double x = clsUtil::ReadDouble(here, not_big1); | |
997 | + double y = clsUtil::ReadDouble(here, not_big1); | |
998 | + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON)); | |
999 | + if (pPgon == NULL) | |
1000 | + { | |
1001 | + free(pp); | |
1002 | + pp = 0; | |
1003 | + break; | |
1004 | + } | |
1005 | + | |
1006 | + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE)); | |
1007 | + if (pRing == NULL) | |
1008 | + { | |
1009 | + free(pp); | |
1010 | + pp = 0; | |
1011 | + free(pPgon); | |
1012 | + pPgon = 0; | |
1013 | + break; | |
1014 | + } | |
1015 | + | |
1016 | + pPgon[0].nRing = 1; | |
1017 | + pPgon[0].p = pRing; | |
1018 | + | |
1019 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT)); | |
1020 | + | |
1021 | + pRing[0].nPoint = 1; | |
1022 | + pRing[0].p = pPoint; | |
1023 | + | |
1024 | + double x0 = 0, y0 = 0; | |
1025 | + this->ToScale(x, y, x0, y0); | |
1026 | + pPoint[0].x = x0; | |
1027 | + pPoint[0].y = y0; | |
1028 | + | |
1029 | + pp[i].nPolygon = 1; | |
1030 | + pp[i].p = pPgon; | |
1031 | + } | |
1032 | + else | |
1033 | + { | |
1034 | + npolygon = clsUtil::ReadInt(here, not_big1); | |
1035 | + | |
1036 | + if (PolygonIsLessThanOnePixel(here, not_big1)) | |
1037 | + { | |
1038 | + //here += 4; | |
1039 | + //npolygon = clsUtil::ReadInt(here, not_big1) | |
1040 | + not_big2 = clsUtil::ReadByte(here); | |
1041 | + here += 12; | |
1042 | + double x = clsUtil::ReadDouble(here, not_big2); | |
1043 | + double y = clsUtil::ReadDouble(here, not_big2); | |
1044 | + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON)); | |
1045 | + if (pPgon == NULL) | |
1046 | + { | |
1047 | + free(pp); | |
1048 | + pp = 0; | |
1049 | + break; | |
1050 | + } | |
1051 | + | |
1052 | + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE)); | |
1053 | + if (pRing == NULL) | |
1054 | + { | |
1055 | + free(pp); | |
1056 | + pp = 0; | |
1057 | + free(pPgon); | |
1058 | + pPgon = 0; | |
1059 | + break; | |
1060 | + } | |
1061 | + | |
1062 | + pPgon[0].nRing = 1; | |
1063 | + pPgon[0].p = pRing; | |
1064 | + | |
1065 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT)); | |
1066 | + | |
1067 | + pRing[0].nPoint = 1; | |
1068 | + pRing[0].p = pPoint; | |
1069 | + | |
1070 | + double x0 = 0, y0 = 0; | |
1071 | + this->ToScale(x, y, x0, y0); | |
1072 | + pPoint[0].x = x0; | |
1073 | + pPoint[0].y = y0; | |
1074 | + | |
1075 | + pp[i].nPolygon = 1; | |
1076 | + pp[i].p = pPgon; | |
1077 | + } | |
1078 | + else | |
1079 | + { | |
1080 | + | |
1081 | + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON) * npolygon); | |
1082 | + //clsStruct::MPOLYGON mpgon; | |
1083 | + if (pPgon == NULL) | |
1084 | + continue; | |
1085 | + pp[i].nPolygon = npolygon; | |
1086 | + pp[i].p = pPgon; | |
1087 | + | |
1088 | + for (int j = 0; j < npolygon; j++) | |
1089 | + { | |
1090 | + not_big2 = clsUtil::ReadByte(here); | |
1091 | + here += 4; //跳过 shapetype, 没意义, 必然是polygon | |
1092 | + | |
1093 | + nring = clsUtil::ReadInt(here, not_big2); | |
1094 | + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nring); | |
1095 | + if (pRing == NULL) | |
1096 | + break; | |
1097 | + pPgon[j].nRing = nring; | |
1098 | + pPgon[j].p = pRing; | |
1099 | + //clsStruct::POLYGON pgon; | |
1100 | + | |
1101 | + for (int k = 0; k < nring; k++) | |
1102 | + { | |
1103 | + npoint = clsUtil::ReadInt(here, not_big2); | |
1104 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint); | |
1105 | + if (pPoint == NULL) | |
1106 | + break; | |
1107 | + pRing[k].nPoint = npoint; | |
1108 | + pRing[k].p = pPoint; | |
1109 | + //clsStruct::LINE ring; | |
1110 | + | |
1111 | + for (int m = 0; m < npoint; m++) | |
1112 | + { | |
1113 | + double x = clsUtil::ReadDouble(here, not_big2); | |
1114 | + double y = clsUtil::ReadDouble(here, not_big2); | |
1115 | + if (hasZ) | |
1116 | + { | |
1117 | + //Z 值跳过 | |
1118 | + here += 8; | |
1119 | + } | |
1120 | + double x0 = 0, y0 = 0; | |
1121 | + this->ToScale(x, y, x0, y0); | |
1122 | + | |
1123 | + pPoint[m].x = x0; | |
1124 | + pPoint[m].y = y0; | |
1125 | + } | |
1126 | + } | |
1127 | + } | |
1128 | + } | |
1129 | + } | |
1130 | + | |
1131 | + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始 | |
1132 | + { | |
1133 | + m_vAllField[i][j] = (char *)PQgetvalue(res, i, j + 1); | |
1134 | + } | |
1135 | + } | |
1136 | + | |
1137 | + m_pData = pp; | |
1138 | + return true; | |
1139 | + } | |
1140 | + | |
1141 | +/* | |
1142 | + bool DataCollection::MallocForPoint(Point *p) | |
1143 | + { | |
1144 | + m_iStructType = clsStruct::Struct_Point; | |
1145 | + | |
1146 | + clsStruct::POINT *pp = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT)); | |
1147 | + if (pp == NULL) | |
1148 | + return false; | |
1149 | + double x = p->m_dX; | |
1150 | + double y = p->m_dY; | |
1151 | + double x0 = 0, y0 = 0; | |
1152 | + this->ToScale(x, y, x0, y0); | |
1153 | + | |
1154 | + pp[0].x = x0; | |
1155 | + pp[0].y = y0; | |
1156 | + | |
1157 | + m_pData = pp; | |
1158 | + return true; | |
1159 | + } | |
1160 | + bool DataCollection::MallocForMultiPoint(MultiPoint *mp) | |
1161 | + { | |
1162 | + m_iStructType = clsStruct::Struct_Line; | |
1163 | + | |
1164 | + clsStruct::LINE *pp = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE)); | |
1165 | + if (pp == NULL) | |
1166 | + return false; | |
1167 | + int npoint = (int)(mp->m_vX.size()); | |
1168 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint); | |
1169 | + if (pPoint == NULL) | |
1170 | + return false; | |
1171 | + pp->nPoint = npoint; | |
1172 | + pp->p = pPoint; | |
1173 | + | |
1174 | + for (int i = 0; i < npoint; i++) | |
1175 | + { | |
1176 | + double x = mp->m_vX[i]; | |
1177 | + double y = mp->m_vY[i]; | |
1178 | + double x0 = 0, y0 = 0; | |
1179 | + this->ToScale(x, y, x0, y0); | |
1180 | + | |
1181 | + pPoint[i].x = x0; | |
1182 | + pPoint[i].y = y0; | |
1183 | + } | |
1184 | + | |
1185 | + m_pData = pp; | |
1186 | + return true; | |
1187 | + } | |
1188 | + bool DataCollection::MallocForPath(Path *path) | |
1189 | + { | |
1190 | + m_iStructType = clsStruct::Struct_Line; | |
1191 | + | |
1192 | + clsStruct::LINE *pp = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE)); | |
1193 | + if (pp == NULL) | |
1194 | + return false; | |
1195 | + int npoint = (int)(path->m_vX.size()); | |
1196 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint); | |
1197 | + if (pPoint == NULL) | |
1198 | + return false; | |
1199 | + pp->nPoint = npoint; | |
1200 | + pp->p = pPoint; | |
1201 | + | |
1202 | + for (int i = 0; i < npoint; i++) | |
1203 | + { | |
1204 | + double x = path->m_vX[i]; | |
1205 | + double y = path->m_vY[i]; | |
1206 | + double x0 = 0, y0 = 0; | |
1207 | + this->ToScale(x, y, x0, y0); | |
1208 | + | |
1209 | + pPoint[i].x = x0; | |
1210 | + pPoint[i].y = y0; | |
1211 | + } | |
1212 | + | |
1213 | + m_pData = pp; | |
1214 | + return true; | |
1215 | + } | |
1216 | + bool DataCollection::MallocForMultiLineString(MultiLineString *ml) | |
1217 | + { | |
1218 | + m_iStructType = clsStruct::Struct_MLine; | |
1219 | + | |
1220 | + clsStruct::MLINE *pp = (clsStruct::MLINE *)malloc(sizeof(clsStruct::MLINE)); | |
1221 | + if (pp == NULL) | |
1222 | + return false; | |
1223 | + int nLine = (int)(ml->m_vLineX.size()); | |
1224 | + clsStruct::LINE *pPath = (clsStruct::LINE *)(malloc(sizeof(clsStruct::LINE) * nLine)); | |
1225 | + if (pPath == NULL) | |
1226 | + { | |
1227 | + free(pp); | |
1228 | + pp = 0; | |
1229 | + return false; | |
1230 | + } | |
1231 | + pp->nLine = nLine; | |
1232 | + pp->p = pPath; | |
1233 | + | |
1234 | + for (int i = 0; i < nLine; i++) | |
1235 | + { | |
1236 | + int nPoint = (int)(ml->m_vLineX[i].size()); | |
1237 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint); | |
1238 | + if (pPoint == NULL) | |
1239 | + { | |
1240 | + pPath[i].nPoint = 0; | |
1241 | + pPath[i].p = 0; | |
1242 | + continue; | |
1243 | + } | |
1244 | + pPath[i].nPoint = nPoint; | |
1245 | + pPath[i].p = pPoint; | |
1246 | + | |
1247 | + for (int j = 0; j < nPoint; j++) | |
1248 | + { | |
1249 | + double x = ml->m_vLineX[i][j]; | |
1250 | + double y = ml->m_vLineY[i][j]; | |
1251 | + double x0 = 0, y0 = 0; | |
1252 | + this->ToScale(x, y, x0, y0); | |
1253 | + | |
1254 | + pPoint[j].x = x0; | |
1255 | + pPoint[j].y = y0; | |
1256 | + } | |
1257 | + } | |
1258 | + | |
1259 | + m_pData = pp; | |
1260 | + | |
1261 | + return true; | |
1262 | + } | |
1263 | + bool DataCollection::MallocForRing(Ring *ring) | |
1264 | + { | |
1265 | + m_iStructType = clsStruct::Struct_Line; | |
1266 | + m_iPartCount = 1; | |
1267 | + clsStruct::LINE *pp = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE)); | |
1268 | + if (pp == NULL) | |
1269 | + return false; | |
1270 | + int npoint = (int)(ring->m_vX.size()); | |
1271 | + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint); | |
1272 | + if (pPoint == NULL) | |
1273 | + { | |
1274 | + free(pp); | |
1275 | + pp = 0; | |
1276 | + return false; | |
1277 | + } | |
1278 | + pp->nPoint = npoint; | |
1279 | + pp->p = pPoint; | |
1280 | + | |
1281 | + for (int i = 0; i < npoint; i++) | |
1282 | + { | |
1283 | + double x = ring->m_vX[i]; | |
1284 | + double y = ring->m_vY[i]; | |
1285 | + double x0 = 0, y0 = 0; | |
1286 | + this->ToScale(x, y, x0, y0); | |
1287 | + | |
1288 | + pPoint[i].x = x0; | |
1289 | + pPoint[i].y = y0; | |
1290 | + } | |
1291 | + m_pData = pp; | |
1292 | + return true; | |
1293 | + } | |
1294 | + | |
1295 | + bool DataCollection::MallocForPolygon(Polygon *pPolygon) | |
1296 | + { | |
1297 | + m_iStructType = clsStruct::Struct_Polygon; | |
1298 | + m_iPartCount = 1; | |
1299 | + | |
1300 | + clsStruct::POLYGON *pp = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON)); | |
1301 | + if (pp == NULL) | |
1302 | + return false; | |
1303 | + int nRing = (int)(pPolygon->m_vR.size()); | |
1304 | + clsStruct::LINE *pStRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nRing); | |
1305 | + if (pStRing == NULL) | |
1306 | + { | |
1307 | + free(pp); | |
1308 | + pp = 0; | |
1309 | + return false; | |
1310 | + } | |
1311 | + pp->nRing = nRing; | |
1312 | + pp->p = pStRing; | |
1313 | + | |
1314 | + for (int i = 0; i < nRing; i++) | |
1315 | + { | |
1316 | + Ring *ring = pPolygon->m_vR[i]; | |
1317 | + | |
1318 | + int nPoint = (int)(ring->m_vX.size()); | |
1319 | + clsStruct::POINT *pStPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint); | |
1320 | + if (pStPoint == NULL) | |
1321 | + { | |
1322 | + pStRing[i].nPoint = 0; | |
1323 | + pStRing[i].p = 0; | |
1324 | + continue; | |
1325 | + } | |
1326 | + | |
1327 | + pStRing[i].nPoint = nPoint; | |
1328 | + pStRing[i].p = pStPoint; | |
1329 | + for (int j = 0; j < nPoint; j++) | |
1330 | + { | |
1331 | + double x = ring->m_vX[j]; | |
1332 | + double y = ring->m_vY[j]; | |
1333 | + double x0 = 0, y0 = 0; | |
1334 | + this->ToScale(x, y, x0, y0); | |
1335 | + pStPoint[j].x = x0; | |
1336 | + pStPoint[j].y = y0; | |
1337 | + } | |
1338 | + } | |
1339 | + m_pData = pp; | |
1340 | + return true; | |
1341 | + } | |
1342 | + | |
1343 | + bool DataCollection::MallocForMultiPolygon(MultiPolygon *mp) | |
1344 | + { | |
1345 | + m_iPartCount = 1; | |
1346 | + m_iStructType = clsStruct::Struct_MPolygon; | |
1347 | + clsStruct::MPOLYGON *pp = (clsStruct::MPOLYGON *)malloc(sizeof(clsStruct::MPOLYGON)); | |
1348 | + if (pp == NULL) | |
1349 | + return false; | |
1350 | + int nPolygon = (int)(mp->m_vpPolygon.size()); | |
1351 | + clsStruct::POLYGON *pStPolygon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON) * nPolygon); | |
1352 | + if (pStPolygon == NULL) | |
1353 | + { | |
1354 | + free(pp); | |
1355 | + pp = 0; | |
1356 | + return false; | |
1357 | + } | |
1358 | + pp->nPolygon = nPolygon; | |
1359 | + pp->p = pStPolygon; | |
1360 | + | |
1361 | + for (int i = 0; i < nPolygon; i++) | |
1362 | + { | |
1363 | + Polygon *pPolygon = mp->m_vpPolygon[i]; | |
1364 | + | |
1365 | + int nRing = (int)(pPolygon->m_vR.size()); | |
1366 | + clsStruct::LINE *pStRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nRing); | |
1367 | + if (pStRing == NULL) | |
1368 | + { | |
1369 | + pStPolygon[i].nRing = 0; | |
1370 | + pStPolygon[i].p = 0; | |
1371 | + continue; | |
1372 | + } | |
1373 | + | |
1374 | + pStPolygon[i].nRing = nRing; | |
1375 | + pStPolygon[i].p = pStRing; | |
1376 | + for (int j = 0; j < nRing; j++) | |
1377 | + { | |
1378 | + Ring *pRing = pPolygon->m_vR[j]; | |
1379 | + | |
1380 | + int nPoint = (int)(pRing->m_vX.size()); | |
1381 | + clsStruct::POINT *pStPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint); | |
1382 | + if (pStPoint == NULL) | |
1383 | + { | |
1384 | + pStRing[j].nPoint = 0; | |
1385 | + pStRing[j].p = 0; | |
1386 | + continue; | |
1387 | + } | |
1388 | + pStRing[j].nPoint = nPoint; | |
1389 | + pStRing[j].p = pStPoint; | |
1390 | + | |
1391 | + for (int k = 0; k < nPoint; k++) | |
1392 | + { | |
1393 | + double x = pRing->m_vX[k]; | |
1394 | + double y = pRing->m_vY[k]; | |
1395 | + double x0 = 0, y0 = 0; | |
1396 | + this->ToScale(x, y, x0, y0); | |
1397 | + pStPoint[k].x = x0; | |
1398 | + pStPoint[k].y = y0; | |
1399 | + } | |
1400 | + } | |
1401 | + } | |
1402 | + m_pData = pp; | |
1403 | + return true; | |
1404 | + }*/ | |
1405 | + | |
1406 | + /* | |
1407 | + Free | |
1408 | + */ | |
1409 | + bool DataCollection::FreeForPOINT() | |
1410 | + { | |
1411 | + free(m_pData); | |
1412 | + m_pData = NULL; | |
1413 | + return true; | |
1414 | + } | |
1415 | + | |
1416 | + bool DataCollection::FreeForLINE() | |
1417 | + { | |
1418 | + clsStruct::LINE *pp = (clsStruct::LINE *)m_pData; | |
1419 | + for (int i = 0; i < m_iPartCount; i++) | |
1420 | + { | |
1421 | + free(pp[i].p); | |
1422 | + } | |
1423 | + free(m_pData); | |
1424 | + m_pData = NULL; | |
1425 | + return true; | |
1426 | + } | |
1427 | + | |
1428 | + bool DataCollection::FreeForMLINE() | |
1429 | + { | |
1430 | + clsStruct::MLINE *pp = (clsStruct::MLINE *)m_pData; | |
1431 | + | |
1432 | + for (int i = 0; i < m_iPartCount; i++) | |
1433 | + { | |
1434 | + int nLine = pp[i].nLine; | |
1435 | + clsStruct::LINE *pLine = pp[i].p; | |
1436 | + for (int j = 0; j < nLine; j++) | |
1437 | + free(pLine[j].p); | |
1438 | + free(pLine); | |
1439 | + } | |
1440 | + free(m_pData); | |
1441 | + m_pData = NULL; | |
1442 | + return true; | |
1443 | + } | |
1444 | + | |
1445 | + bool DataCollection::FreeForPOLYGON() | |
1446 | + { | |
1447 | + clsStruct::POLYGON *pp = (clsStruct::POLYGON *)m_pData; | |
1448 | + | |
1449 | + for (int i = 0; i < m_iPartCount; i++) | |
1450 | + { | |
1451 | + int nRing = pp[i].nRing; | |
1452 | + clsStruct::LINE *pRing = pp[i].p; | |
1453 | + for (int j = 0; j < nRing; j++) | |
1454 | + free(pRing[j].p); | |
1455 | + free(pRing); | |
1456 | + } | |
1457 | + free(m_pData); | |
1458 | + m_pData = NULL; | |
1459 | + return true; | |
1460 | + } | |
1461 | + bool DataCollection::FreeForMPOLYGON() | |
1462 | + { | |
1463 | + clsStruct::MPOLYGON *pp = (clsStruct::MPOLYGON *)m_pData; | |
1464 | + | |
1465 | + for (int i = 0; i < m_iPartCount; i++) | |
1466 | + { | |
1467 | + clsStruct::POLYGON *pPolygon = pp[i].p; | |
1468 | + int nPolygon = pp[i].nPolygon; | |
1469 | + | |
1470 | + for (int j = 0; j < nPolygon; j++) | |
1471 | + { | |
1472 | + int nRing = pPolygon[j].nRing; | |
1473 | + clsStruct::LINE *pRing = pPolygon[j].p; | |
1474 | + | |
1475 | + for (int k = 0; k < nRing; k++) | |
1476 | + free(pRing[k].p); | |
1477 | + | |
1478 | + free(pRing); | |
1479 | + } | |
1480 | + free(pPolygon); | |
1481 | + } | |
1482 | + free(m_pData); | |
1483 | + m_pData = NULL; | |
1484 | + return true; | |
1485 | + } | |
1486 | + | |
1487 | + void DataCollection::ToScale(double x, double y, double &x0, double &y0) | |
1488 | + { | |
1489 | + x0 = m_dR * x + m_dXdis; | |
1490 | + y0 = -m_dR * y + m_dYdis; | |
1491 | + //return true; | |
1492 | + } | |
1493 | + | |
1494 | + bool DataCollection::CollectAllField(PGresult *res) | |
1495 | + { | |
1496 | + //直接认为第一列是shape元素,跳过 | |
1497 | + int n_tuples = PQntuples(res); | |
1498 | + int n_fields = PQnfields(res); | |
1499 | + | |
1500 | + //创建预留空间 | |
1501 | + m_vAllField.resize(n_tuples); | |
1502 | + for (int i = 0; i < n_tuples; i++) | |
1503 | + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的 | |
1504 | + //开辟预留空间后, 可以直接赋值,不需要 pushback | |
1505 | + for (int i = 0; i < n_tuples; i++) | |
1506 | + { | |
1507 | + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始 | |
1508 | + { | |
1509 | + const char *ss = PQgetvalue(res, i, j + 1); | |
1510 | + m_vAllField[i][j] = PQgetvalue(res, i, j + 1); | |
1511 | + } | |
1512 | + } | |
1513 | + | |
1514 | + m_vFieldName.resize(n_fields - 1); | |
1515 | + for (int i = 0; i < n_fields - 1; i++) //从第二列开始 | |
1516 | + { | |
1517 | + m_vFieldName[i] = PQfname(res, i + 1); | |
1518 | + } | |
1519 | + return true; | |
1520 | + } | |
1521 | + | |
1522 | + bool DataCollection::CollectFieldName(PGresult *res) | |
1523 | + { | |
1524 | + //直接认为第一列是shape元素,跳过 | |
1525 | + int n_fields = PQnfields(res); | |
1526 | + if (n_fields < 2) | |
1527 | + return false; | |
1528 | + | |
1529 | + for (int i = 0; i < n_fields - 1; i++) //从第二列开始 | |
1530 | + { | |
1531 | + string fieldname = PQfname(res, i + 1); | |
1532 | + if (fieldname == "geodmap_area") | |
1533 | + { | |
1534 | + m_dmapAreaIndex = i; | |
1535 | + n_fields--; | |
1536 | + break; | |
1537 | + } | |
1538 | + } | |
1539 | + | |
1540 | + m_vFieldName.resize(n_fields - 1); | |
1541 | + for (int i = 0; i < n_fields - 1; i++) //从第二列开始 | |
1542 | + { | |
1543 | + m_vFieldName[i] = PQfname(res, i + 1); | |
1544 | + } | |
1545 | + return true; | |
1546 | + } | |
1547 | + | |
1548 | + shared_ptr<PointClass> DataCollection::GetDataPoint(unsigned char *vc) | |
1549 | + { | |
1550 | + unsigned char hasZorSrsid = ((unsigned char *)(vc + 4))[0] / 16; | |
1551 | + unsigned char hasZ = hasZorSrsid / 8; | |
1552 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
1553 | + | |
1554 | + int not_big = clsUtil::ReadByte(vc); | |
1555 | + int shapetype = clsUtil::ReadInt(vc, not_big); | |
1556 | + if (hasSrsid) | |
1557 | + vc += 4; | |
1558 | + | |
1559 | + double x = clsUtil::ReadDouble(vc, not_big); | |
1560 | + double y = clsUtil::ReadDouble(vc, not_big); | |
1561 | + | |
1562 | + shared_ptr<PointClass> point(new PointClass()); | |
1563 | + point->x = x; | |
1564 | + point->y = y; | |
1565 | + return point; | |
1566 | + } | |
1567 | + | |
1568 | + shared_ptr<PointClass> DataCollection::GetMDataPoint(unsigned char *vc) | |
1569 | + { | |
1570 | + unsigned char hasZorSrsid = ((unsigned char *)(vc + 4))[0] / 16; | |
1571 | + unsigned char hasZ = hasZorSrsid / 8; | |
1572 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
1573 | + | |
1574 | + int not_big = clsUtil::ReadByte(vc); | |
1575 | + int shapetype = clsUtil::ReadInt(vc, not_big); | |
1576 | + | |
1577 | + if (hasSrsid) | |
1578 | + { | |
1579 | + int srsid = clsUtil::ReadInt(vc, not_big); | |
1580 | + } | |
1581 | + | |
1582 | + unsigned char *here = vc; | |
1583 | + | |
1584 | + int nPointCount = clsUtil::ReadInt(vc, not_big); | |
1585 | + | |
1586 | + for (int j = 0; j < nPointCount; j++) | |
1587 | + { | |
1588 | + //clsStruct::LINE path; | |
1589 | + | |
1590 | + int not_big2 = clsUtil::ReadByte(vc); | |
1591 | + vc += 4; //跳过 shapetype 读取 | |
1592 | + double x = clsUtil::ReadDouble(vc, not_big); | |
1593 | + double y = clsUtil::ReadDouble(vc, not_big); | |
1594 | + | |
1595 | + shared_ptr<PointClass> point(new PointClass()); | |
1596 | + point->x = x; | |
1597 | + point->y = y; | |
1598 | + return point; | |
1599 | + } | |
1600 | + shared_ptr<PointClass> point(new PointClass()); | |
1601 | + return point; | |
1602 | + } | |
1603 | + | |
1604 | + shared_ptr<PolygonClass> DataCollection::GetDataLine(unsigned char *vc) | |
1605 | + { | |
1606 | + unsigned char hasZorSrsid = ((unsigned char *)(vc + 4))[0] / 16; | |
1607 | + unsigned char hasZ = hasZorSrsid / 8; | |
1608 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
1609 | + | |
1610 | + int not_big = clsUtil::ReadByte(vc); | |
1611 | + int shapetype = clsUtil::ReadInt(vc, not_big); | |
1612 | + if (hasSrsid) | |
1613 | + { | |
1614 | + int srsid = clsUtil::ReadInt(vc, not_big); | |
1615 | + } | |
1616 | + | |
1617 | + shared_ptr<PolygonClass> p_polygon(new PolygonClass()); | |
1618 | + p_polygon->polygonCount = 1; | |
1619 | + double pol_minx = 1000000000; | |
1620 | + double pol_miny = 1000000000; | |
1621 | + double pol_maxx = -100000000; | |
1622 | + double pol_maxy = -100000000; | |
1623 | + //pp[i].nLine = nLine; | |
1624 | + //pp[i].p = pPath; | |
1625 | + | |
1626 | + //for (int j = 0; j < nLine; j++) | |
1627 | + { | |
1628 | + //clsStruct::LINE path; | |
1629 | + | |
1630 | + //int not_big2 = clsUtil::ReadByte(vc); | |
1631 | + //vc += 4; //跳过 shapetype 读取 | |
1632 | + | |
1633 | + int nPoint = clsUtil::ReadInt(vc, not_big); | |
1634 | + p_polygon->vecParts.push_back(nPoint); | |
1635 | + for (int k = 0; k < nPoint; k++) | |
1636 | + { | |
1637 | + //clsStruct::POINT point; | |
1638 | + | |
1639 | + double x = clsUtil::ReadDouble(vc, not_big); | |
1640 | + double y = clsUtil::ReadDouble(vc, not_big); | |
1641 | + p_polygon->vec_X.push_back(x); | |
1642 | + p_polygon->vec_Y.push_back(y); | |
1643 | + if (hasZ) | |
1644 | + vc += 8; | |
1645 | + if (pol_minx > x) | |
1646 | + pol_minx = x; | |
1647 | + if (pol_miny > y) | |
1648 | + pol_miny = y; | |
1649 | + if (pol_maxx < x) | |
1650 | + pol_maxx = x; | |
1651 | + if (pol_maxy < y) | |
1652 | + pol_maxy = y; | |
1653 | + } | |
1654 | + } | |
1655 | + p_polygon->minx = pol_minx; | |
1656 | + p_polygon->miny = pol_miny; | |
1657 | + p_polygon->maxx = pol_maxx; | |
1658 | + p_polygon->maxy = pol_maxy; | |
1659 | + return p_polygon; | |
1660 | + } | |
1661 | + | |
1662 | + shared_ptr<PolygonClass> DataCollection::GetDataMLine(unsigned char *vc) | |
1663 | + { | |
1664 | + unsigned char hasZorSrsid = ((unsigned char *)(vc + 4))[0] / 16; | |
1665 | + unsigned char hasZ = hasZorSrsid / 8; | |
1666 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
1667 | + | |
1668 | + int not_big = clsUtil::ReadByte(vc); | |
1669 | + int shapetype = clsUtil::ReadInt(vc, not_big); | |
1670 | + | |
1671 | + if (hasSrsid) | |
1672 | + { | |
1673 | + int srsid = clsUtil::ReadInt(vc, not_big); | |
1674 | + } | |
1675 | + | |
1676 | + int nLine = clsUtil::ReadInt(vc, not_big); | |
1677 | + shared_ptr<PolygonClass> p_polygon(new PolygonClass()); | |
1678 | + p_polygon->polygonCount = nLine; | |
1679 | + double pol_minx = 1000000000; | |
1680 | + double pol_miny = 1000000000; | |
1681 | + double pol_maxx = -100000000; | |
1682 | + double pol_maxy = -100000000; | |
1683 | + //pp[i].nLine = nLine; | |
1684 | + //pp[i].p = pPath; | |
1685 | + | |
1686 | + for (int j = 0; j < nLine; j++) | |
1687 | + { | |
1688 | + //clsStruct::LINE path; | |
1689 | + | |
1690 | + int not_big2 = clsUtil::ReadByte(vc); | |
1691 | + vc += 4; //跳过 shapetype 读取 | |
1692 | + | |
1693 | + int nPoint = clsUtil::ReadInt(vc, not_big2); | |
1694 | + p_polygon->vecParts.push_back(nPoint); | |
1695 | + for (int k = 0; k < nPoint; k++) | |
1696 | + { | |
1697 | + //clsStruct::POINT point; | |
1698 | + | |
1699 | + double x = clsUtil::ReadDouble(vc, not_big2); | |
1700 | + double y = clsUtil::ReadDouble(vc, not_big2); | |
1701 | + p_polygon->vec_X.push_back(x); | |
1702 | + p_polygon->vec_Y.push_back(y); | |
1703 | + if (hasZ) | |
1704 | + vc += 8; | |
1705 | + if (pol_minx > x) | |
1706 | + pol_minx = x; | |
1707 | + if (pol_miny > y) | |
1708 | + pol_miny = y; | |
1709 | + if (pol_maxx < x) | |
1710 | + pol_maxx = x; | |
1711 | + if (pol_maxy < y) | |
1712 | + pol_maxy = y; | |
1713 | + } | |
1714 | + } | |
1715 | + p_polygon->minx = pol_minx; | |
1716 | + p_polygon->miny = pol_miny; | |
1717 | + p_polygon->maxx = pol_maxx; | |
1718 | + p_polygon->maxy = pol_maxy; | |
1719 | + return p_polygon; | |
1720 | + } | |
1721 | + | |
1722 | + shared_ptr<PolygonClass> DataCollection::GetDataPolygon(unsigned char *here) | |
1723 | + { | |
1724 | + shared_ptr<PolygonClass> p_polygon(new PolygonClass()); | |
1725 | + try | |
1726 | + { | |
1727 | + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16; | |
1728 | + unsigned char hasZ = hasZorSrsid / 8; | |
1729 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
1730 | + //bool hasZ = false; | |
1731 | + int not_big1, not_big2, shapetype1, nring, npoint; | |
1732 | + not_big1 = clsUtil::ReadByte(here); | |
1733 | + shapetype1 = clsUtil::ReadInt(here, not_big1); | |
1734 | + if (hasSrsid) | |
1735 | + { | |
1736 | + int srsid = clsUtil::ReadInt(here, not_big1); | |
1737 | + } | |
1738 | + | |
1739 | + double pol_minx = 1000000000; | |
1740 | + double pol_miny = 1000000000; | |
1741 | + double pol_maxx = -100000000; | |
1742 | + double pol_maxy = -100000000; | |
1743 | + | |
1744 | + p_polygon->polygonCount = 1; | |
1745 | + | |
1746 | + //for (int j = 0; j < 1; j++) | |
1747 | + //{ | |
1748 | + //not_big2 = clsUtil::ReadByte(here); | |
1749 | + //here += 4; //跳过 shapetype, 没意义, 必然是polygon | |
1750 | + | |
1751 | + nring = clsUtil::ReadInt(here, not_big1); | |
1752 | + p_polygon->vecParts.push_back(nring); | |
1753 | + | |
1754 | + for (int k = 0; k < nring; k++) | |
1755 | + { | |
1756 | + npoint = clsUtil::ReadInt(here, not_big1); | |
1757 | + p_polygon->vecParts.push_back(npoint); | |
1758 | + | |
1759 | + for (int m = 0; m < npoint; m++) | |
1760 | + { | |
1761 | + double x = clsUtil::ReadDouble(here, not_big1); | |
1762 | + double y = clsUtil::ReadDouble(here, not_big1); | |
1763 | + if (hasZ) | |
1764 | + here += 8; | |
1765 | + p_polygon->vec_X.push_back(x); | |
1766 | + p_polygon->vec_Y.push_back(y); | |
1767 | + | |
1768 | + if (pol_minx > x) | |
1769 | + pol_minx = x; | |
1770 | + if (pol_miny > y) | |
1771 | + pol_miny = y; | |
1772 | + if (pol_maxx < x) | |
1773 | + pol_maxx = x; | |
1774 | + if (pol_maxy < y) | |
1775 | + pol_maxy = y; | |
1776 | + } | |
1777 | + } | |
1778 | + //} | |
1779 | + | |
1780 | + p_polygon->minx = pol_minx; | |
1781 | + p_polygon->miny = pol_miny; | |
1782 | + p_polygon->maxx = pol_maxx; | |
1783 | + p_polygon->maxy = pol_maxy; | |
1784 | + | |
1785 | + if (p_polygon->vec_X.size() == 0) | |
1786 | + { | |
1787 | + //delete p_polygon; | |
1788 | + return NULL; | |
1789 | + } | |
1790 | + } | |
1791 | + catch (const std::exception &e) | |
1792 | + { | |
1793 | + //std::cerr << e.what() << '\n'; | |
1794 | + //delete p_polygon; | |
1795 | + return NULL; | |
1796 | + } | |
1797 | + | |
1798 | + return p_polygon; | |
1799 | + } | |
1800 | + | |
1801 | + shared_ptr<PolygonClass> DataCollection::GetDataMPolygon(unsigned char *here) | |
1802 | + { | |
1803 | + shared_ptr<PolygonClass> p_polygon(new PolygonClass()); | |
1804 | + try | |
1805 | + { | |
1806 | + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16; | |
1807 | + unsigned char hasZ = hasZorSrsid / 8; | |
1808 | + unsigned char hasSrsid = hasZorSrsid % 8; | |
1809 | + | |
1810 | + unsigned char geom_type = (here)[1]; | |
1811 | + | |
1812 | + if (geom_type == DCGeometryType::GeometryType_Point) | |
1813 | + { | |
1814 | + int not_big1 = clsUtil::ReadByte(here); | |
1815 | + int shapetype1 = clsUtil::ReadInt(here, not_big1); | |
1816 | + if (hasSrsid) | |
1817 | + here += 4; | |
1818 | + p_polygon->polygonCount = 1; | |
1819 | + double x = clsUtil::ReadDouble(here, not_big1); | |
1820 | + double y = clsUtil::ReadDouble(here, not_big1); | |
1821 | + | |
1822 | + p_polygon->minx = x; | |
1823 | + p_polygon->miny = y; | |
1824 | + p_polygon->maxx = x; | |
1825 | + p_polygon->maxy = y; | |
1826 | + | |
1827 | + p_polygon->vec_X.push_back(x); | |
1828 | + p_polygon->vec_Y.push_back(y); | |
1829 | + } | |
1830 | + else | |
1831 | + { | |
1832 | + int not_big1, not_big2, shapetype1, npolygon, nring, npoint; | |
1833 | + not_big1 = clsUtil::ReadByte(here); | |
1834 | + shapetype1 = clsUtil::ReadInt(here, not_big1); | |
1835 | + if (hasSrsid) | |
1836 | + here += 4; //跳过srid | |
1837 | + npolygon = clsUtil::ReadInt(here, not_big1); | |
1838 | + /*clsStruct::POLYGON* pPgon = (clsStruct::POLYGON*)malloc(sizeof(clsStruct::POLYGON)* npolygon);*/ | |
1839 | + //clsStruct::MPOLYGON mpgon; | |
1840 | + if (npolygon == 0) | |
1841 | + { | |
1842 | + return NULL; | |
1843 | + } | |
1844 | + double pol_minx = 1000000000; | |
1845 | + double pol_miny = 1000000000; | |
1846 | + double pol_maxx = -100000000; | |
1847 | + double pol_maxy = -100000000; | |
1848 | + | |
1849 | + p_polygon->polygonCount = npolygon; | |
1850 | + | |
1851 | + for (int j = 0; j < npolygon; j++) | |
1852 | + { | |
1853 | + not_big2 = clsUtil::ReadByte(here); | |
1854 | + here += 4; //跳过 shapetype, 没意义, 必然是polygon | |
1855 | + | |
1856 | + nring = clsUtil::ReadInt(here, not_big2); | |
1857 | + p_polygon->vecParts.push_back(nring); | |
1858 | + | |
1859 | + for (int k = 0; k < nring; k++) | |
1860 | + { | |
1861 | + npoint = clsUtil::ReadInt(here, not_big2); | |
1862 | + p_polygon->vecParts.push_back(npoint); | |
1863 | + | |
1864 | + for (int m = 0; m < npoint; m++) | |
1865 | + { | |
1866 | + double x = clsUtil::ReadDouble(here, not_big2); | |
1867 | + double y = clsUtil::ReadDouble(here, not_big2); | |
1868 | + if (hasZ) | |
1869 | + here += 8; | |
1870 | + p_polygon->vec_X.push_back(x); | |
1871 | + p_polygon->vec_Y.push_back(y); | |
1872 | + | |
1873 | + if (pol_minx > x) | |
1874 | + pol_minx = x; | |
1875 | + if (pol_miny > y) | |
1876 | + pol_miny = y; | |
1877 | + if (pol_maxx < x) | |
1878 | + pol_maxx = x; | |
1879 | + if (pol_maxy < y) | |
1880 | + pol_maxy = y; | |
1881 | + } | |
1882 | + } | |
1883 | + } | |
1884 | + | |
1885 | + p_polygon->minx = pol_minx; | |
1886 | + p_polygon->miny = pol_miny; | |
1887 | + p_polygon->maxx = pol_maxx; | |
1888 | + p_polygon->maxy = pol_maxy; | |
1889 | + | |
1890 | + if (p_polygon->vec_X.size() == 0) | |
1891 | + { | |
1892 | + //delete p_polygon; | |
1893 | + return NULL; | |
1894 | + } | |
1895 | + } | |
1896 | + } | |
1897 | + catch (const std::exception &e) | |
1898 | + { | |
1899 | + //std::cerr << e.what() << '\n'; | |
1900 | + //delete p_polygon; | |
1901 | + return NULL; | |
1902 | + } | |
1903 | + | |
1904 | + return p_polygon; | |
1905 | + } | |
1906 | + | |
1907 | +} | ... | ... |
src/core/renderer/DataCollection.h
0 → 100644
1 | +#pragma once | |
2 | +#ifndef _DataCollection_H_ | |
3 | +#define _DataCollection_H_ | |
4 | + | |
5 | +#include<vector> | |
6 | +#include<string> | |
7 | +#include "dmap_core.h" | |
8 | +#include<libpq-fe.h> | |
9 | +#include <map> | |
10 | +#include "memory" | |
11 | +using namespace std; | |
12 | + | |
13 | +namespace DmapCore_30 | |
14 | +{ | |
15 | + | |
16 | + | |
17 | + enum DMapFieldType | |
18 | +{ | |
19 | + dmapShort = 0, | |
20 | + dmapInt = 1, | |
21 | + dmapLong = 2, | |
22 | + dmapDouble = 3, | |
23 | + dmapBoolean = 4, | |
24 | + dmapChar = 5, | |
25 | + dmapString = 6, | |
26 | + dmapGeography = 7, | |
27 | + dmapData = 8, | |
28 | + dmapGeometry = 9, | |
29 | + shapePoint = 10, | |
30 | + shapeLineString = 11, | |
31 | + shapePolygon = 12, | |
32 | + shapeMultiPoint = 13, | |
33 | + shapeMultiLineString = 14, | |
34 | + shapeMultiPolygon = 15 | |
35 | +}; | |
36 | + | |
37 | + | |
38 | +/*static enum ZoomFlag | |
39 | +{ | |
40 | +dmapZoomReset = 0, | |
41 | +dmapZoomIn = 1, | |
42 | +dmapZoomOut = 2, | |
43 | +dmapZoomNoChange = 3 | |
44 | +};*/ | |
45 | + | |
46 | + enum PointType | |
47 | +{ | |
48 | + dmapPointTypeCircle = 0, //圆 | |
49 | + dmapPointTypeTriangle = 1, //三角形 | |
50 | + dmapPointTypeSquare = 2, //正方形 | |
51 | + dmapPointTypeCross = 3, //十字架 | |
52 | + dmapPointTypeStar = 4, //五角星 | |
53 | +}; | |
54 | + enum LineType | |
55 | +{ | |
56 | + dmapLineTypeSolid = 0, | |
57 | + dmapLineTypeDash = 1, | |
58 | + dmapLineTypeDot = 2, | |
59 | + dmapLineTypeDashDot = 3, | |
60 | + dmapLineTypeDashDotDot = 4, | |
61 | +}; | |
62 | + | |
63 | +enum DCGeometryType | |
64 | + { | |
65 | + GeometryType_Point = 1, | |
66 | + GeometryType_LineString = 2, | |
67 | + GeometryType_Polygon = 3, | |
68 | + GeometryType_MultiPoint = 4, | |
69 | + GeometryType_MultiLineString = 5, | |
70 | + GeometryType_MultiPolygon = 6, | |
71 | + }; | |
72 | + | |
73 | + enum GeometryType | |
74 | +{ | |
75 | + dmapGeometryPoint = 0, | |
76 | + dmapGeometryMultiPoint = 1, | |
77 | + dmapGeometryPath = 2, | |
78 | + dmapGeometryMultiLineString = 3, | |
79 | + dmapGeometryRing = 4, | |
80 | + dmapGeometryPolygon = 5, | |
81 | + dmapGeometryMultiPolygon = 6 | |
82 | +}; | |
83 | + | |
84 | + enum ImageType | |
85 | +{ | |
86 | + dmapImageTypePNG = 0, | |
87 | + dmapImageTypeJPG = 1 | |
88 | +}; | |
89 | + enum StorageType | |
90 | +{ | |
91 | + dmapStorageTypeExploded = 0, | |
92 | + dmapStorageTypeCompact = 1 | |
93 | +}; | |
94 | + | |
95 | +/* | |
96 | +range的[lower,upper]区间两个端点是否使用 | |
97 | +all表示两边使用 | |
98 | +upper表示使用大端点,不使用小端点 | |
99 | +*/ | |
100 | + enum EqulityType | |
101 | +{ | |
102 | + dmapEqualityAll = 0, | |
103 | + dmapEqualityUpper = 1, | |
104 | + dmapEqualityLower = 2, | |
105 | + dmapEqualityNone = 3 | |
106 | +}; | |
107 | + | |
108 | + | |
109 | + enum dmapAntialias | |
110 | +{ | |
111 | + dmapAntialiasingDefault=0, | |
112 | + dmapAntialiasingNone = 1, | |
113 | + dmapAntialiasingGray = 2, | |
114 | + dmapAntialiasingSubpixel = 3, | |
115 | + dmapAntialiasingFast = 4, | |
116 | + dmapAntialiasingGood = 5, | |
117 | + dmapAntialiasingBest = 6, | |
118 | + dmapAntialiasingTrue = 7, | |
119 | + dmapAntialiasingFalse = 8 | |
120 | +}; | |
121 | + | |
122 | + | |
123 | + enum dmapLineLabelPositionDirection | |
124 | +{ | |
125 | + dmapLineLabelPositionLevel = 0, | |
126 | + dmapLineLabelPositionParallel = 1, | |
127 | + dmapLineLabelPositionCurved = 2, | |
128 | + dmapLineLabelPositionVertical = 3, | |
129 | +}; | |
130 | + | |
131 | + enum dmapLineLabelPositionPlace //在线上方或下方 或左边或右边 或者线上 | |
132 | +{ | |
133 | + dmapLineLabelPositionLeft = 0, | |
134 | + dmapLineLabelPositionRight = 1, | |
135 | + dmapLineLabelPositionOnTop = 2, | |
136 | + dmapLineLabelPositionAbove = 3, | |
137 | + dmapLineLabelPositionBelow = 4, | |
138 | +}; | |
139 | + | |
140 | + enum dmapLineLabelPositionStartOrEnd | |
141 | +{ | |
142 | + dmapLineLabelPositionStart = 0, | |
143 | + dmapLineLabelPositionEnd = 1, | |
144 | + dmapLineLabelPositionCenter = 2, | |
145 | +}; | |
146 | + | |
147 | + enum dmapPolygonLabelPositionDirection | |
148 | +{ | |
149 | + dmapPolygonLabelPositionParallel = 0, | |
150 | + dmapPolygonLabelPositionStraight = 1, | |
151 | + dmapPolygonLabelPositionParallelAndStraight = 2, | |
152 | +}; | |
153 | + | |
154 | + | |
155 | + enum dmapRotateMethod | |
156 | +{ | |
157 | + dmapRotate_geographic = 0, | |
158 | + dmapRotate_Arithmetic = 1, | |
159 | + dmapRotate_Mod_arithmetic = 2 | |
160 | +}; | |
161 | + | |
162 | + class PGeomClass | |
163 | + { | |
164 | + public: | |
165 | + vector<char *> m_pdata; | |
166 | + ~PGeomClass() | |
167 | + { | |
168 | + for (size_t i = 0; i < m_pdata.size(); i++) | |
169 | + { | |
170 | + char *data = m_pdata.at(i); | |
171 | + if (data != 0) | |
172 | + { | |
173 | + free(data); | |
174 | + m_pdata[i] = 0; | |
175 | + } | |
176 | + } | |
177 | + m_pdata.clear(); | |
178 | + } | |
179 | + }; | |
180 | + | |
181 | + | |
182 | + class PointClass :public PGeomClass | |
183 | + { | |
184 | + public: | |
185 | + float x; | |
186 | + float y; | |
187 | + }; | |
188 | + | |
189 | + | |
190 | + | |
191 | + class PolygonClass :public PGeomClass | |
192 | + { | |
193 | + public: | |
194 | + unsigned int polygonCount; | |
195 | + vector<int> vecParts; | |
196 | + vector<float> vec_X; | |
197 | + vector<float> vec_Y; | |
198 | + | |
199 | + float minx; | |
200 | + float miny; | |
201 | + float maxx; | |
202 | + float maxy; | |
203 | + }; | |
204 | + | |
205 | + //class Point; | |
206 | + //class MultiPoint; | |
207 | +// class Path; | |
208 | +// class MultiLineString; | |
209 | + //class Ring; | |
210 | + //class Polygon; | |
211 | +// class MultiPolygon; | |
212 | + //class Geometry; | |
213 | + class CORE_EXPORT DataCollection | |
214 | + { | |
215 | + public: | |
216 | + | |
217 | + void InitDataCollection(PGresult* res, int shapeType,int imageWidth, int imageHeight, int subset, double r = 1, double dScaleDenominator=1,double x_dis = 0, double y_dis = 0); | |
218 | + //DataCollection(Recordsets* recss, int shapeType, double r = 1, double x_dis = 0, double y_dis = 0); | |
219 | + //void InitDataCollection(Geometry* geom, double r = 1, double dScaleDenominator=1, double x_dis = 0, double y_dis = 0); | |
220 | + | |
221 | + | |
222 | + void InitHeatCollection(PGresult* res,int shapeType,int imageWidth, int imageHeight, double layer_minx, double layer_maxx, double layer_miny, double layer_maxy, | |
223 | + int subset, double r = 1, double dScaleDenominator=1,double x_dis = 0, double y_dis = 0); | |
224 | + | |
225 | + | |
226 | + | |
227 | + | |
228 | + ~DataCollection(); | |
229 | + | |
230 | + DataCollection(); | |
231 | + | |
232 | + // void InitDataCollection(); | |
233 | + int m_iPartCount; | |
234 | + int m_iStructType; | |
235 | + void * m_pData; //此指针只能够是自定义的6种结构体类型 | |
236 | + | |
237 | + vector<vector<string> > m_vAllField; //这是结果集的所有除 shape 外的field, 数组中每个元素表示一行数据 | |
238 | + vector<string> m_vFieldName; // 这是所有字段的名字 | |
239 | + double m_dR; | |
240 | + double m_dXdis; | |
241 | + double m_dYdis; | |
242 | + double m_dScaleDenominator; | |
243 | + | |
244 | + int m_imageWidth =0; | |
245 | + int m_imageHeight =0; | |
246 | + | |
247 | + int m_subset; | |
248 | + | |
249 | + bool m_dmapAreaIndex = -1; | |
250 | + | |
251 | + //shared_ptr<DataHeatCollection> pHeatData; | |
252 | + | |
253 | + private: | |
254 | + int m_iN; | |
255 | + | |
256 | + | |
257 | + bool MallocForPoint(PGresult* res); | |
258 | + bool MallocForMultiLineString(PGresult* res); | |
259 | + bool MallocForPolygon(PGresult *res); | |
260 | + bool MallocForMultiPolygon(PGresult* res); | |
261 | + | |
262 | + bool MallocForPolygonForGeom(PGresult *res); | |
263 | + bool MallocForLineStringGeom(PGresult *res); | |
264 | + | |
265 | + //bool MallocForHeatCollectionGeom(PGresult *res,int dcigridColIndex); | |
266 | + | |
267 | + //bool MallocForPoint(Point* p); | |
268 | + //bool MallocForMultiPoint(MultiPoint* mp); | |
269 | + //bool MallocForPath(Path* path); | |
270 | + //bool MallocForMultiLineString(MultiLineString* ml); | |
271 | + //bool MallocForRing(Ring* ring); | |
272 | + //bool MallocForPolygon(Polygon* pPolygon); | |
273 | + //bool MallocForMultiPolygon(MultiPolygon* mp); | |
274 | + | |
275 | + bool PolygonIsLessThanOnePixel(unsigned char* here,int not_big1); | |
276 | + | |
277 | + /* | |
278 | + Struct_Point = 0, | |
279 | + Struct_Line = 1, | |
280 | + Struct_MLine = 2, | |
281 | + Struct_Polygon = 3, | |
282 | + Struct_MPolygon = 4 | |
283 | + */ | |
284 | + bool FreeForPOINT(); | |
285 | + bool FreeForLINE(); | |
286 | + bool FreeForMLINE(); | |
287 | + bool FreeForPOLYGON(); | |
288 | + bool FreeForMPOLYGON(); | |
289 | + | |
290 | + inline void ToScale(double x, double y, double&x0, double&y0); | |
291 | + bool CollectAllField(PGresult* res); | |
292 | + bool CollectFieldName(PGresult* res); | |
293 | + | |
294 | + | |
295 | + shared_ptr<PointClass> GetDataPoint(unsigned char *vc); | |
296 | + shared_ptr<PointClass> GetMDataPoint(unsigned char *vc); | |
297 | + shared_ptr<PolygonClass> GetDataLine(unsigned char *vc); | |
298 | + shared_ptr<PolygonClass> GetDataMLine(unsigned char *vc); | |
299 | + shared_ptr<PolygonClass> GetDataPolygon(unsigned char *vc); | |
300 | + shared_ptr<PolygonClass> GetDataMPolygon(unsigned char *vc); | |
301 | + }; | |
302 | + | |
303 | + | |
304 | + | |
305 | + | |
306 | +} | |
307 | +#endif | |
\ No newline at end of file | ... | ... |
src/core/renderer/GroupRenderer.cpp
0 → 100644
1 | + | |
2 | +#ifndef _GroupRenderer_H_ | |
3 | +#define _GroupRenderer_H_ | |
4 | + | |
5 | +#include "GroupRenderer.h" | |
6 | +#include"SimpleMarkerSymbol.h" | |
7 | +#include"SimpleLabelRenderer.h" | |
8 | +#include"SimpleLineSymbol.h" | |
9 | +#include"SimplePolygonSymbol.h" | |
10 | +#include"ValueMapRenderer.h" | |
11 | +//#include"RangeMapRenderer.h" | |
12 | +#include"SimpleRenderer.h" | |
13 | +#include"TrueTypeMarkerSymbol.h" | |
14 | +#include "clsUtil.h" | |
15 | +#include "clsXML.h" | |
16 | + | |
17 | +namespace DmapCore_30 | |
18 | +{ | |
19 | + GroupRenderer::GroupRenderer() | |
20 | + { | |
21 | + m_vSymbols = {}; | |
22 | + m_sTag = ""; | |
23 | + m_sXML = ""; | |
24 | + m_simpleRenderer = true; | |
25 | + } | |
26 | + GroupRenderer::~GroupRenderer() | |
27 | + { | |
28 | + this->Clear(); | |
29 | + } | |
30 | + bool GroupRenderer::Parse(boost::property_tree::ptree &pt, AppendBuffer *f) | |
31 | + { | |
32 | + | |
33 | + //遍历所有节点 | |
34 | + for (auto ptchild =pt.begin(); ptchild != pt.end(); ++ptchild) | |
35 | + { | |
36 | + //所有子节点都是样式 | |
37 | + Renderer* renderer = NULL; | |
38 | + if (clsXML::XMLParse(ptchild->first, ptchild->second, &renderer)) | |
39 | + { | |
40 | + if (renderer)m_vSymbols.push_back(renderer); | |
41 | + } | |
42 | + } | |
43 | + return true; | |
44 | + | |
45 | + | |
46 | + } | |
47 | + | |
48 | + void GroupRenderer::ToJson(AppendBuffer *ab) | |
49 | + { | |
50 | + | |
51 | + //strcat(resultbuff,R"("GROUPRENDERER":[)"); | |
52 | + ab->AppendString(R"("GROUPRENDERER":[)"); | |
53 | + int length = (int)m_vSymbols.size(); | |
54 | + for (int i = 0; i < length; i++) | |
55 | + { | |
56 | + if(i>0){ | |
57 | + ab->AppendString(","); | |
58 | + } | |
59 | + // strcat(resultbuff,","); | |
60 | + Renderer* renderer = m_vSymbols[i]; | |
61 | + renderer->ToJson(ab); | |
62 | + } | |
63 | + ab->AppendString("]"); | |
64 | + //strcat(resultbuff,"]"); | |
65 | + | |
66 | + | |
67 | + } | |
68 | + | |
69 | + | |
70 | + | |
71 | + GroupRenderer* GroupRenderer::CreateNew() | |
72 | + { | |
73 | + GroupRenderer* dest = new GroupRenderer(); | |
74 | + return dest; | |
75 | + } | |
76 | + int GroupRenderer::RendererType() | |
77 | + { | |
78 | + return dmapGroupRenderer; | |
79 | + } | |
80 | + | |
81 | + const char* GroupRenderer::GetTag() | |
82 | + { | |
83 | + return m_sTag.c_str(); | |
84 | + } | |
85 | + bool GroupRenderer::SetTag(const char* sTag) | |
86 | + { | |
87 | + if (!sTag) | |
88 | + return false; | |
89 | + m_sTag = sTag; | |
90 | + return true; | |
91 | + } | |
92 | + bool GroupRenderer::AddSymbol(int index, Renderer* pRenderer) | |
93 | + { | |
94 | + int length__ = m_vSymbols.size(); | |
95 | + if (index > length__)return false; | |
96 | + pRenderer->AddRef(); | |
97 | + if (index < 0 || index == length__) | |
98 | + m_vSymbols.push_back(pRenderer); | |
99 | + else | |
100 | + m_vSymbols.insert(m_vSymbols.begin() + index, pRenderer); | |
101 | + return true; | |
102 | + } | |
103 | + bool GroupRenderer::Remove(int index) | |
104 | + { | |
105 | + RemoveIndexP(index, m_vSymbols); | |
106 | + } | |
107 | + Renderer* GroupRenderer::GetItem(int index) | |
108 | + { | |
109 | + GetIndexP(index, m_vSymbols); | |
110 | + } | |
111 | + bool GroupRenderer::SetItem(int index, Renderer* pRenderer) | |
112 | + { | |
113 | + SetIndexP(index, pRenderer, m_vSymbols); | |
114 | + } | |
115 | + int GroupRenderer::GetSymbolCount() | |
116 | + { | |
117 | + int length = (int)m_vSymbols.size(); | |
118 | + return length; | |
119 | + | |
120 | + } | |
121 | + bool GroupRenderer::Clear() | |
122 | + { | |
123 | + ClearP(m_vSymbols); | |
124 | + } | |
125 | + | |
126 | + //bool GroupRenderer::DrawSimpleData(clsCrSurf* pClsCS, DataCollection* data, char* pFlag) | |
127 | + //{ | |
128 | + // int length = (int)(m_vSymbols.size()); | |
129 | + | |
130 | + // for (int i = 0; i < length; i++) | |
131 | + // { | |
132 | + // Renderer* renderer = m_vSymbols[i]; | |
133 | + // if (renderer->m_simpleRenderer) | |
134 | + // { | |
135 | + // int renType = renderer->RendererType(); | |
136 | + // renderer->DrawData(pClsCS, data, pFlag); | |
137 | + // } | |
138 | + // } | |
139 | + // return true; | |
140 | + //} | |
141 | + | |
142 | + | |
143 | + bool GroupRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag) | |
144 | + { | |
145 | + int length = (int)(m_vSymbols.size()); | |
146 | + | |
147 | + for (int i = 0; i < length; i++) | |
148 | + { | |
149 | + Renderer* renderer = m_vSymbols[i]; | |
150 | + //if (renderer->m_simpleRenderer == drawSimpleData) | |
151 | + { | |
152 | + int renType = renderer->RendererType(); | |
153 | + renderer->DrawData(pClsCS, data,true, pFlag); | |
154 | + } | |
155 | + } | |
156 | + return true; | |
157 | + } | |
158 | + bool GroupRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag) | |
159 | + { | |
160 | + int length = (int)(m_vSymbols.size()); | |
161 | + for (int i = 0; i < length; i++) | |
162 | + { | |
163 | + Renderer* renderer = m_vSymbols[i]; | |
164 | + int renType = renderer->RendererType(); | |
165 | + renderer->DrawData(pClsCS, data, dataIndex, pFlag); | |
166 | + } | |
167 | + return true; | |
168 | + } | |
169 | + | |
170 | + bool GroupRenderer::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater, int layerType,char* pFlag = NULL) | |
171 | + { | |
172 | + int length = (int)(m_vSymbols.size()); | |
173 | + for (int i = 0; i < length; i++) | |
174 | + { | |
175 | + Renderer* renderer = m_vSymbols[i]; | |
176 | + int renType = renderer->RendererType(); | |
177 | + renderer->DrawLegend(pClsCS, pLegendParamater,layerType, pFlag); | |
178 | + } | |
179 | + return true; | |
180 | + } | |
181 | + | |
182 | + | |
183 | + void GroupRenderer::TryAddField(vector<string>&pvField) | |
184 | + { | |
185 | + int length = (int)(m_vSymbols.size()); | |
186 | + for (int i = 0; i < length; i++) | |
187 | + { | |
188 | + if (m_vSymbols[i] == 0)continue; | |
189 | + m_vSymbols[i]->TryAddField(pvField); | |
190 | + } | |
191 | + } | |
192 | + | |
193 | + bool GroupRenderer::TryFindHeatRenderer() | |
194 | + { | |
195 | + int length = (int)(m_vSymbols.size()); | |
196 | + for (int i = 0; i < length; i++) | |
197 | + { | |
198 | + Renderer* renderer = m_vSymbols[i]; | |
199 | + if(renderer->TryFindHeatRenderer()) | |
200 | + { | |
201 | + return true; | |
202 | + } | |
203 | + } | |
204 | + return false; | |
205 | + } | |
206 | +} | |
207 | + | |
208 | +#endif | |
\ No newline at end of file | ... | ... |
src/core/renderer/GroupRenderer.h
0 → 100644
1 | +#pragma once | |
2 | +#include<vector> | |
3 | +using namespace std; | |
4 | +#include"Renderer.h" | |
5 | + | |
6 | +namespace DmapCore_30 | |
7 | +{ | |
8 | + class clsCrSurf; | |
9 | + class DataCollection; | |
10 | + class GroupRenderer :public Renderer | |
11 | + { | |
12 | + public: | |
13 | + GroupRenderer(); | |
14 | + ~GroupRenderer(); | |
15 | + static GroupRenderer* CreateNew(); | |
16 | + virtual int RendererType(); | |
17 | + virtual bool Parse(boost::property_tree::ptree &pt, AppendBuffer *f); | |
18 | + virtual void ToJson(AppendBuffer *ab); | |
19 | + // virtual bool DrawSimpleData(clsCrSurf* pClsCS, DataCollection* data, char* pFlag); | |
20 | + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag); | |
21 | + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag); | |
22 | + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater, int layerType, char* pFlag); | |
23 | + vector<Renderer*> m_vSymbols; | |
24 | + const char* GetTag(); | |
25 | + bool SetTag(const char* sTag); | |
26 | + bool AddSymbol(int index, Renderer*); | |
27 | + bool Remove(int index); | |
28 | + Renderer* GetItem(int index); | |
29 | + bool SetItem(int index, Renderer* pRenderer); | |
30 | + int GetSymbolCount(); | |
31 | + bool Clear(); | |
32 | + | |
33 | + void TryAddField(vector<string>&pvField); | |
34 | + bool TryFindHeatRenderer(); | |
35 | + private: | |
36 | + | |
37 | + string m_sTag; | |
38 | + }; | |
39 | + | |
40 | +} | |
\ No newline at end of file | ... | ... |
src/core/renderer/Renderer.cpp
0 → 100644
1 | + | |
2 | + | |
3 | +#include "Renderer.h" | |
4 | +#include"SimpleMarkerSymbol.h" | |
5 | +#include"SimplePolygonSymbol.h" | |
6 | +#include"ValueMapRenderer.h" | |
7 | +//#include"RangeMapRenderer.h" | |
8 | +#include"GroupRenderer.h" | |
9 | +#include"SimpleLineSymbol.h" | |
10 | + | |
11 | +#include"clsUtil.h" | |
12 | +#include"clsMalloc.h" | |
13 | +#include <unistd.h> | |
14 | +#include <algorithm> | |
15 | +namespace DmapCore_30 | |
16 | +{ | |
17 | + Renderer::Renderer() | |
18 | + { | |
19 | + m_iN = 1; | |
20 | + } | |
21 | + | |
22 | + | |
23 | + Renderer::~Renderer() | |
24 | + { | |
25 | + } | |
26 | + | |
27 | + bool Renderer::AddRef() | |
28 | + { | |
29 | + m_iN++; | |
30 | + return true; | |
31 | + } | |
32 | + bool Renderer::Release() | |
33 | + { | |
34 | + m_iN--; | |
35 | + if (m_iN < 0) | |
36 | + return false; | |
37 | + if (!m_iN) | |
38 | + { | |
39 | + switch (this->RendererType()) | |
40 | + { | |
41 | + case dmapSimpleMarkerSymbol:delete (SimpleMarkerSymbol*)this; break; | |
42 | + case dmapSimpleLineSymbol: | |
43 | + delete ((SimpleLineSymbol*)this); | |
44 | + break; | |
45 | + case dmapSimplePolygonSymbol: delete (SimplePolygonSymbol*)this; break; | |
46 | + case dmapValueMapRenderer: delete (ValueMapRenderer*)this; break; | |
47 | + //case dmapRangeMapRenderer: delete (RangeMapRenderer*)this; break; | |
48 | + case dmapGroupRenderer: delete (GroupRenderer*)this; break; | |
49 | + default: | |
50 | + delete this; | |
51 | + break; | |
52 | + } | |
53 | + } | |
54 | + return true; | |
55 | + } | |
56 | + | |
57 | + int Renderer::GetN() | |
58 | + { | |
59 | + return m_iN; | |
60 | + } | |
61 | +/* | |
62 | + bool Renderer::RendererXmlParse(Renderer**ppRen, const char* fileName) | |
63 | + { | |
64 | + if (!(*ppRen)) | |
65 | + { | |
66 | + rapidxml::xml_document<char> doc; | |
67 | + rapidxml::file<> fdoc(fileName); | |
68 | + try | |
69 | + { | |
70 | + doc.parse<0>(fdoc.data()); | |
71 | + } | |
72 | + catch (...) | |
73 | + { | |
74 | + return false; | |
75 | + } | |
76 | + | |
77 | + rapidxml::xml_node<char>* root = doc.first_node(); | |
78 | + bool flag = clsXML::XMLParse(root, NULL, ppRen); | |
79 | + return flag; | |
80 | + } | |
81 | + AppendBuffer ab(fileName); | |
82 | + clsXML::XMLHead(&ab); | |
83 | + clsXML::XMLParse(NULL, &ab, ppRen); | |
84 | + | |
85 | + return true; | |
86 | + } | |
87 | +*/ | |
88 | + void Renderer::TryAddField2(vector<string>&pvField, std::string field) | |
89 | + { | |
90 | + if (field.size() == 0)return; | |
91 | + vector<string>::iterator it = find(pvField.begin(), pvField.end(), field); | |
92 | + if (it == pvField.end()) | |
93 | + pvField.push_back(field); | |
94 | + }; | |
95 | + | |
96 | + string Renderer::GetFilePath(string path) | |
97 | + { | |
98 | + char sz[200] = {0}; | |
99 | + if(GetCurrentFolderPath(sz, sizeof(sz)) > 0) | |
100 | + { | |
101 | + std::string s; | |
102 | + s = sz; | |
103 | + size_t t = s.rfind('/'); | |
104 | + sz[t] = 0; | |
105 | + if(path[0]=='/') | |
106 | + { | |
107 | + return path; | |
108 | + } | |
109 | + int i=0; | |
110 | + if(path[0]=='.') | |
111 | + { | |
112 | + if(path[1]=='.') | |
113 | + { | |
114 | + i++; | |
115 | + s= sz; | |
116 | + t = s.rfind('/'); | |
117 | + sz[t] = 0; | |
118 | + } | |
119 | + i++; | |
120 | + } | |
121 | + if((sz[t]=='/' || sz[t]=='\\')&& (path[i]=='/' || path[i]=='\\')) | |
122 | + { | |
123 | + i++; | |
124 | + } | |
125 | + | |
126 | + int j= t; | |
127 | + for(j=t;i<path.length(); i++,j++) | |
128 | + { | |
129 | + if(path[i]=='\\') | |
130 | + { | |
131 | + sz[j] = '/'; | |
132 | + } | |
133 | + else | |
134 | + { | |
135 | + sz[j] = path[i]; | |
136 | + } | |
137 | + | |
138 | + } | |
139 | + sz[j] =0; | |
140 | + //strcat(sz, path.c_str()); | |
141 | + return sz; | |
142 | + } | |
143 | + else return 0; | |
144 | + | |
145 | + } | |
146 | + | |
147 | + | |
148 | + int Renderer::GetCurrentFolderPath(char* processdir, size_t len) | |
149 | + { | |
150 | + char* path_end; | |
151 | + if (readlink("/proc/self/exe", processdir, len) <= 0) | |
152 | + return -1; | |
153 | + path_end = strrchr(processdir, '/'); | |
154 | + if (path_end == NULL) | |
155 | + return -1; | |
156 | + ++path_end; | |
157 | + //strcpy(processname, path_end); | |
158 | + *path_end = '\0'; | |
159 | + return (size_t)(path_end - processdir); | |
160 | + } | |
161 | + | |
162 | + | |
163 | + void Renderer::TryAddField(vector<string>&pvField) | |
164 | + { | |
165 | + | |
166 | + }; | |
167 | +/* | |
168 | + bool Renderer::RenStr(Renderer** ppRen, const char** psXML) | |
169 | + { | |
170 | + using namespace rapidxml; | |
171 | + if (*ppRen == NULL) | |
172 | + { | |
173 | + if (psXML == 0 || *psXML == 0 || (*psXML)[0] == 0)return false; | |
174 | + char *xml = _strdup(*psXML); clsMalloc mcx(xml); | |
175 | + if (xml == 0 || xml[0] == 0)return false; | |
176 | + try{ | |
177 | + xml_document<> doc; // character type defaults to char | |
178 | + doc.parse<0>(xml); | |
179 | + xml_node<char> *n = doc.first_node(); | |
180 | + if (n == 0){ return false; } | |
181 | + bool flag = clsXML::XMLParse(n, NULL, ppRen); | |
182 | + return flag; | |
183 | + } | |
184 | + catch (parse_error e) | |
185 | + { | |
186 | + | |
187 | + return false; | |
188 | + } | |
189 | + catch (...) | |
190 | + { | |
191 | + return false; | |
192 | + } | |
193 | + } | |
194 | + AppendBuffer ab(0); | |
195 | + clsXML::XMLParse(NULL, &ab, ppRen); | |
196 | + clsMalloc clsM1(ab.GetString()); | |
197 | + (*ppRen)->m_sXML = clsM1.mem; | |
198 | + | |
199 | + *psXML = (*ppRen)->m_sXML.c_str(); | |
200 | + return true; | |
201 | + | |
202 | + }*/ | |
203 | +} | |
204 | + | ... | ... |
src/core/renderer/Renderer.h
0 → 100644
1 | + | |
2 | +#ifndef _Renderer_H_ | |
3 | +#define _Renderer_H_ | |
4 | +#pragma once | |
5 | +#include <boost/property_tree/ptree.hpp> | |
6 | +#include <boost/property_tree/xml_parser.hpp> | |
7 | +#include <boost/foreach.hpp> | |
8 | +#include <string> | |
9 | +#include "AppendBuffer.h" | |
10 | +#include "legendParamater.h" | |
11 | +#include <memory> | |
12 | +#include <cairo/cairo.h> | |
13 | +#include"clsXML.h" | |
14 | +#include "dmap_core.h" | |
15 | +using namespace std; | |
16 | +namespace DmapCore_30 | |
17 | +{ | |
18 | + | |
19 | + enum RendererType | |
20 | +{ | |
21 | + dmapSimpleMarkerSymbol = 1, | |
22 | + dmapSimpleLineSymbol = 2, | |
23 | + dmapSimplePolygonSymbol = 3, | |
24 | + dmapValueMapRenderer = 4, | |
25 | + dmapRangeMapRenderer = 5, | |
26 | + dmapGroupRenderer = 6, | |
27 | + dmapScaleDependentRenderer = 7, | |
28 | + dmapSimpleLabelRenderer = 8, | |
29 | + dmapTrueTypeMarkerSymbol = 9, | |
30 | + dmapSimpleRenderer = 10, | |
31 | + dmapTextSymbol = 11, | |
32 | + dmapHeatMapRenderer = 12 | |
33 | +}; | |
34 | + | |
35 | + class clsCrSurf; | |
36 | + class DataCollection; | |
37 | + class CORE_EXPORT Renderer | |
38 | + { | |
39 | + public: | |
40 | + Renderer(); | |
41 | + ~Renderer(); | |
42 | + bool AddRef(); | |
43 | + bool Release(); | |
44 | + virtual int RendererType() = 0; | |
45 | + virtual void ToJson(AppendBuffer *ab)=0; | |
46 | + | |
47 | + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag = NULL) = 0; | |
48 | + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag = NULL) =0; | |
49 | + virtual bool Parse( boost::property_tree::ptree &pt, AppendBuffer *f) = 0; | |
50 | + //static bool RendererXmlParse(Renderer**pRen, const char* fileName); | |
51 | + //static bool RenStr(Renderer** ppRen, const char** psXML); //纯粹作弊,什么都没干,直接调用现有接口 | |
52 | + | |
53 | + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater, int layerType, char* pFlag = NULL) = 0; | |
54 | + | |
55 | + virtual void TryAddField(vector<string>&pvField); | |
56 | + virtual bool TryFindHeatRenderer()=0; | |
57 | + void TryAddField2(vector<string>&pvField, std::string field); | |
58 | + | |
59 | + | |
60 | + string GetFilePath(string path); | |
61 | + int GetCurrentFolderPath(char* processdir, size_t len); | |
62 | + int GetN();//仅作调试使用 | |
63 | + string m_sXML; | |
64 | + | |
65 | + bool m_simpleRenderer; | |
66 | + private: | |
67 | + int m_iN; | |
68 | + | |
69 | + | |
70 | + }; | |
71 | + | |
72 | +} | |
73 | + | |
74 | +#endif | |
\ No newline at end of file | ... | ... |
src/core/renderer/ScaleDependentRenderer.cpp
0 → 100644
1 | + | |
2 | +#include "ScaleDependentRenderer.h" | |
3 | +#include"clsXML.h" | |
4 | +#include"DataCollection.h" | |
5 | +#include"SimpleMarkerSymbol.h" | |
6 | +#include"SimpleLabelRenderer.h" | |
7 | +#include"SimpleLineSymbol.h" | |
8 | +#include"SimplePolygonSymbol.h" | |
9 | +#include"ValueMapRenderer.h" | |
10 | +#include"RangeMapRenderer.h" | |
11 | +#include"GroupRenderer.h" | |
12 | +namespace DmapCore_30 | |
13 | +{ | |
14 | + ScaleDependentRenderer::ScaleDependentRenderer() | |
15 | + { | |
16 | + m_dLower = 0.0; | |
17 | + m_dUpper = 1e308; | |
18 | + m_pRenderer = NULL; | |
19 | + m_simpleRenderer = false; | |
20 | + } | |
21 | + | |
22 | + | |
23 | + ScaleDependentRenderer::~ScaleDependentRenderer() | |
24 | + { | |
25 | + if (m_pRenderer) | |
26 | + { | |
27 | + m_pRenderer->Release(); | |
28 | + m_pRenderer = NULL; //注意手工重置为 NULL | |
29 | + } | |
30 | + } | |
31 | + BOOL ScaleDependentRenderer::Parse(rapidxml::xml_node<char>* node, AppendBuffer *f) | |
32 | + { | |
33 | + if (!node&& !f)return false; | |
34 | + clsXML clsX(f, "SCALEDEPENDENTRENDERER"); | |
35 | + clsXML::XMLAttrParse(node, f, &m_dLower, "lower"); | |
36 | + clsXML::XMLAttrParse(node, f, &m_dUpper, "upper"); | |
37 | + clsX.closeProperties(); | |
38 | + if (node) | |
39 | + { | |
40 | + clsXML::XMLParse(node->first_node(), NULL, &m_pRenderer); | |
41 | + } | |
42 | + else | |
43 | + { | |
44 | + clsXML::XMLParse(NULL, f, &m_pRenderer); | |
45 | + } | |
46 | + return true; | |
47 | + } | |
48 | + | |
49 | + void ScaleDependentRenderer::ToJson(AppendBuffer *ab) | |
50 | + { | |
51 | + | |
52 | + } | |
53 | + | |
54 | + //BOOL ScaleDependentRenderer::RendererString(Renderer** ppRen, const char** psXML) | |
55 | + //{ | |
56 | + // return true; | |
57 | + //} | |
58 | + | |
59 | + int ScaleDependentRenderer::RendererType() | |
60 | + { | |
61 | + return dmapScaleDependentRenderer; | |
62 | + } | |
63 | + ScaleDependentRenderer* ScaleDependentRenderer::CreateNew() | |
64 | + { | |
65 | + ScaleDependentRenderer* sdr = new ScaleDependentRenderer(); | |
66 | + return sdr; | |
67 | + } | |
68 | + | |
69 | + double ScaleDependentRenderer::GetLower() | |
70 | + { | |
71 | + return m_dLower; | |
72 | + } | |
73 | + BOOL ScaleDependentRenderer::SetLower(double lower) | |
74 | + { | |
75 | + if (lower < 0) | |
76 | + return false; | |
77 | + m_dLower = lower; | |
78 | + return true; | |
79 | + } | |
80 | + double ScaleDependentRenderer::GetUpper() | |
81 | + { | |
82 | + return m_dUpper; | |
83 | + } | |
84 | + BOOL ScaleDependentRenderer::SetUpper(double upper) | |
85 | + { | |
86 | + if (upper < 0) | |
87 | + return false; | |
88 | + m_dUpper = upper; | |
89 | + return true; | |
90 | + } | |
91 | + | |
92 | + Renderer* ScaleDependentRenderer::GetRenderer() | |
93 | + { | |
94 | + if (m_pRenderer) | |
95 | + m_pRenderer->AddRef(); | |
96 | + return m_pRenderer; | |
97 | + } | |
98 | + BOOL ScaleDependentRenderer::SetRenderer(Renderer* renderer) | |
99 | + { | |
100 | + if (!renderer) | |
101 | + return false; | |
102 | + renderer->AddRef(); | |
103 | + if (m_pRenderer) | |
104 | + m_pRenderer->Release(); | |
105 | + m_pRenderer = renderer; | |
106 | + return true; | |
107 | + } | |
108 | + | |
109 | + BOOL ScaleDependentRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, | |
110 | + bool drawSimpleData, char* pFlag) | |
111 | + { | |
112 | + //DrawData是否要使用重载??现在弄进去有麻烦啊 | |
113 | + double r__ = data->m_dR; | |
114 | + double r = r__ / (96/0.0254); | |
115 | + if (r <m_dLower || r > m_dUpper) | |
116 | + return false; | |
117 | + int renType = m_pRenderer->RendererType(); | |
118 | + m_pRenderer->DrawData(pClsCS, data, pFlag); | |
119 | + /*switch (renType) | |
120 | + { | |
121 | + case dmapSimpleMarkerSymbol:((SimpleMarkerSymbol*)m_pRenderer)->DrawData(pClsCS, data); break; | |
122 | + case dmapSimpleLineSymbol:((SimpleLineSymbol*)m_pRenderer)->DrawData(pClsCS, data); break; | |
123 | + case dmapSimplePolygonSymbol:((SimplePolygonSymbol*)m_pRenderer)->DrawData(pClsCS, data); break; | |
124 | + case dmapValueMapRenderer:((ValueMapRenderer*)m_pRenderer)->DrawData(pClsCS, data); break; | |
125 | + case dmapRangeMapRenderer:((RangeMapRenderer*)m_pRenderer)->DrawData(pClsCS, data); break; | |
126 | + case dmapGroupRenderer:((GroupRenderer*)m_pRenderer)->DrawData(pClsCS, data, pFlag); break; | |
127 | + case dmapSimpleLabelRenderer:((SimpleLabelRenderer*)m_pRenderer)->DrawData(pClsCS, data, pFlag); break; | |
128 | + default: | |
129 | + break; | |
130 | + }*/ | |
131 | + return true; | |
132 | + } | |
133 | + | |
134 | + BOOL ScaleDependentRenderer::DrawData(clsCrSurf* pClsCS, | |
135 | + DataCollection* data, int dataIndex, char* pFlag) | |
136 | + { | |
137 | + //DrawData是否要使用重载??现在弄进去有麻烦啊 | |
138 | + double r__ = data->m_dR; | |
139 | + double r = r__ / (96/0.0254); | |
140 | + if (r <m_dLower || r > m_dUpper) | |
141 | + return false; | |
142 | + int renType = m_pRenderer->RendererType(); | |
143 | + // data->m_pData | |
144 | + m_pRenderer->DrawData(pClsCS, data, dataIndex, pFlag); | |
145 | + /*switch (renType) | |
146 | + { | |
147 | + case dmapSimpleMarkerSymbol:((SimpleMarkerSymbol*)m_pRenderer)->DrawData(pClsCS, data); break; | |
148 | + case dmapSimpleLineSymbol:((SimpleLineSymbol*)m_pRenderer)->DrawData(pClsCS, data); break; | |
149 | + case dmapSimplePolygonSymbol:((SimplePolygonSymbol*)m_pRenderer)->DrawData(pClsCS, data); break; | |
150 | + case dmapValueMapRenderer:((ValueMapRenderer*)m_pRenderer)->DrawData(pClsCS, data); break; | |
151 | + case dmapRangeMapRenderer:((RangeMapRenderer*)m_pRenderer)->DrawData(pClsCS, data); break; | |
152 | + case dmapGroupRenderer:((GroupRenderer*)m_pRenderer)->DrawData(pClsCS, data, pFlag); break; | |
153 | + case dmapSimpleLabelRenderer:((SimpleLabelRenderer*)m_pRenderer)->DrawData(pClsCS, data, pFlag); break; | |
154 | + default: | |
155 | + break; | |
156 | + }*/ | |
157 | + return true; | |
158 | + } | |
159 | + | |
160 | + BOOL ScaleDependentRenderer::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag) | |
161 | + { | |
162 | + | |
163 | + return true; | |
164 | + } | |
165 | + | |
166 | + | |
167 | + void ScaleDependentRenderer::TryAddField(vector<string>&pvField) | |
168 | + { | |
169 | + if (m_pRenderer)m_pRenderer->TryAddField(pvField); | |
170 | + } | |
171 | +} | |
\ No newline at end of file | ... | ... |
src/core/renderer/ScaleDependentRenderer.h
0 → 100644
1 | +#ifndef _ScaleDependentRenderer_H_ | |
2 | +#define _ScaleDependentRenderer_H_ | |
3 | +#include <boost/property_tree/ptree.hpp> | |
4 | +#include <boost/property_tree/xml_parser.hpp> | |
5 | +#include <boost/foreach.hpp> | |
6 | +#include"Renderer.h" | |
7 | +#include<vector> | |
8 | +#include "dmap_core.h" | |
9 | +using namespace std; | |
10 | +namespace DmapCore_30 | |
11 | +{ | |
12 | + class clsCrSurf; | |
13 | + class DataCollection; | |
14 | + class CORE_EXPORT ScaleDependentRenderer :public Renderer | |
15 | + { | |
16 | + public: | |
17 | + //scale中只有一个样式,通常为group | |
18 | + ScaleDependentRenderer(); | |
19 | + ~ScaleDependentRenderer(); | |
20 | + virtual BOOL Parse(rapidxml::xml_node<char>* node, AppendBuffer *f); | |
21 | + virtual void ToJson(AppendBuffer *ab); | |
22 | + //virtual BOOL RendererString(Renderer** ppRen, const char** psXML); | |
23 | + virtual BOOL DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag); | |
24 | + virtual BOOL DrawData(clsCrSurf* pClsCS, DataCollection* data, int drawSimpleData, char* pFlag); | |
25 | + virtual BOOL DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag); | |
26 | + virtual int RendererType(); | |
27 | + static ScaleDependentRenderer* CreateNew(); | |
28 | + | |
29 | + | |
30 | + double GetLower(); | |
31 | + BOOL SetLower(double lower); | |
32 | + double GetUpper(); | |
33 | + BOOL SetUpper(double upper); | |
34 | + Renderer* GetRenderer(); | |
35 | + BOOL SetRenderer(Renderer* renderer); | |
36 | + | |
37 | + virtual void TryAddField(vector<string>&pvField); | |
38 | + virtual bool TryFindHeatRenderer(){ return false; } | |
39 | + | |
40 | + double m_dLower; | |
41 | + double m_dUpper; | |
42 | + Renderer* m_pRenderer; | |
43 | + }; | |
44 | + | |
45 | +} | |
46 | +#endif | |
\ No newline at end of file | ... | ... |
请
注册
或
登录
后发表评论