|
...
|
...
|
@@ -7,8 +7,10 @@ |
|
7
|
7
|
* copyright: 广州城市信息研究所有限公司
|
|
8
|
8
|
***************************************************************************/
|
|
9
|
9
|
#include "dmpvectorlayer.h"
|
|
|
10
|
+#include "dmpxmlutils.h"
|
|
10
|
11
|
#include "dmpvectorlayerrenderer.h"
|
|
11
|
12
|
#include "dmpproviderregistry.h"
|
|
|
13
|
+#include "libpq-fe.h"
|
|
12
|
14
|
|
|
13
|
15
|
DmpVectorLayer::DmpVectorLayer(const std::string &path,
|
|
14
|
16
|
const std::string &baseName,
|
|
...
|
...
|
@@ -37,7 +39,34 @@ DmpMapLayerRenderer *DmpVectorLayer::createMapRenderer(DmpRenderContext &rendere |
|
37
|
39
|
|
|
38
|
40
|
bool DmpVectorLayer::readXml(const boost::property_tree::ptree &layerNode)
|
|
39
|
41
|
{
|
|
40
|
|
- return false;
|
|
|
42
|
+ //id="gzxxd_aabe200b_5b63_4b82_8546_af1fc99e4ec6" name="gzxxd" alias="中学" type="1"
|
|
|
43
|
+ // geometry="Point" alwaysShow="true" maxScale="0" maxScale="50000"
|
|
|
44
|
+ id_ = layerNode.get<std::string>("<xmlattr>.id");
|
|
|
45
|
+ name_ = layerNode.get<std::string>("<xmlattr>.name");
|
|
|
46
|
+ title_ = layerNode.get<std::string>("<xmlattr>.alias");
|
|
|
47
|
+ boost::property_tree::ptree pExtent = layerNode.get_child("extent");
|
|
|
48
|
+ extent_ = DmpXmlUtils::readRectangle(pExtent);
|
|
|
49
|
+ dataSource_ = layerNode.get<std::string>("datasource");
|
|
|
50
|
+
|
|
|
51
|
+ setDataProvider("postgres");
|
|
|
52
|
+
|
|
|
53
|
+ // boost::property_tree::ptree pResourceMetadata = layerNode.get_child("resourcemetadata");
|
|
|
54
|
+ // schema_ = layerNode.get<std::string>("schema");
|
|
|
55
|
+ // geom_ = layerNode.get<std::string>("geom");
|
|
|
56
|
+ // featurecount_ = layerNode.get<unsigned int>("featurecount");
|
|
|
57
|
+
|
|
|
58
|
+ boost::property_tree::ptree pRenderer = layerNode.get_child("renderer");
|
|
|
59
|
+ auto pIter = pRenderer.begin();
|
|
|
60
|
+ if(pIter == pRenderer.end())return false;
|
|
|
61
|
+ DmapCore_30::Renderer* renderer_30 = nullptr;
|
|
|
62
|
+ DmapCore_30::clsXML::XMLParse(pIter->first, pIter->second, &renderer_30);
|
|
|
63
|
+ renderer_30_ = shared_ptr<DmapCore_30::Renderer>(renderer_30);
|
|
|
64
|
+
|
|
|
65
|
+ // geom_ = "geom";
|
|
|
66
|
+ // schema_ = "public";
|
|
|
67
|
+ // wkbType_ = DmpWkbTypes::MultiLineString;
|
|
|
68
|
+
|
|
|
69
|
+ return true;
|
|
41
|
70
|
}
|
|
42
|
71
|
|
|
43
|
72
|
bool DmpVectorLayer::writeXml(boost::property_tree::ptree &layerNode)
|
|
...
|
...
|
@@ -47,12 +76,11 @@ bool DmpVectorLayer::writeXml(boost::property_tree::ptree &layerNode) |
|
47
|
76
|
|
|
48
|
77
|
void DmpVectorLayer::setRenderer(DmpFeatureRenderer *renderer)
|
|
49
|
78
|
{
|
|
50
|
|
-
|
|
|
79
|
+
|
|
51
|
80
|
}
|
|
52
|
81
|
|
|
53
|
82
|
void DmpVectorLayer::setDataSource(const std::string &dataSource, const std::string &baseName, const std::string &provider, bool loadDefaultStyleFlag)
|
|
54
|
83
|
{
|
|
55
|
|
-
|
|
56
|
84
|
DmpWkbTypes::GeometryType geomType = GeometryType();
|
|
57
|
85
|
}
|
|
58
|
86
|
|
|
...
|
...
|
@@ -63,21 +91,100 @@ DmpWkbTypes::GeometryType DmpVectorLayer::GeometryType() const |
|
63
|
91
|
|
|
64
|
92
|
bool DmpVectorLayer::setDataProvider(std::string const &provider)
|
|
65
|
93
|
{
|
|
|
94
|
+ //临时测试使用
|
|
|
95
|
+ PGconn* pPGconn = PQconnectdb(dataSource_.c_str());
|
|
|
96
|
+ ConnStatusType t = PQstatus(pPGconn);
|
|
|
97
|
+ if (t != CONNECTION_OK)
|
|
|
98
|
+ return false;
|
|
|
99
|
+ int re = PQsetClientEncoding(pPGconn, "UTF-8");
|
|
|
100
|
+
|
|
|
101
|
+ std::string sql = "select t.f_geometry_column, t.type ,f_table_schema,t.srid from public.geometry_columns t where lower( t.f_table_name) = lower('" + name_ + "');";
|
|
|
102
|
+ PGresult* pPGresult= PQexec(pPGconn, sql.c_str());
|
|
|
103
|
+ char *sz = PQerrorMessage(pPGconn);
|
|
|
104
|
+ if(sz != nullptr && strcmp(sz,"") !=0)
|
|
|
105
|
+ {
|
|
|
106
|
+ PQfinish(pPGconn); return false;
|
|
|
107
|
+ }
|
|
|
108
|
+
|
|
|
109
|
+ int rowCount = PQntuples(pPGresult);
|
|
|
110
|
+ if(rowCount<1)
|
|
|
111
|
+ {
|
|
|
112
|
+ PQfinish(pPGconn); return false;
|
|
|
113
|
+ }
|
|
|
114
|
+
|
|
|
115
|
+ geom_ = PQgetvalue(pPGresult, 0, 0);
|
|
|
116
|
+ const char* geomtype = PQgetvalue(pPGresult, 0, 1);
|
|
|
117
|
+ schema_ = PQgetvalue(pPGresult, 0, 2);
|
|
|
118
|
+ //std::string srid = PQgetvalue(pPGresult, 0, 3);
|
|
|
119
|
+
|
|
|
120
|
+ if (!geomtype)
|
|
|
121
|
+ return false;
|
|
|
122
|
+ if (!strcmp(geomtype, "POINT")) wkbType_ = DmpWkbTypes::Point;
|
|
|
123
|
+ else if (!strcmp(geomtype, "MULTIPOINT")) wkbType_ = DmpWkbTypes::MultiPoint;
|
|
|
124
|
+ else if (!strcmp(geomtype, "LINESTRING")) wkbType_ = DmpWkbTypes::LineString;
|
|
|
125
|
+ else if (!strcmp(geomtype, "MULTILINESTRING"))wkbType_ = DmpWkbTypes::MultiLineString;
|
|
|
126
|
+ else if (!strcmp(geomtype, "POLYGON")) wkbType_ = DmpWkbTypes::Polygon;
|
|
|
127
|
+ else if (!strcmp(geomtype, "MULTIPOLYGON")) wkbType_ = DmpWkbTypes::MultiPolygon;
|
|
|
128
|
+ else if (!strcmp(geomtype, "GEOMETRY")) wkbType_ = DmpWkbTypes::Unknown;
|
|
|
129
|
+ PQclear(pPGresult); pPGresult = NULL;
|
|
|
130
|
+ PQfinish(pPGconn);
|
|
|
131
|
+
|
|
|
132
|
+ return true;
|
|
|
133
|
+
|
|
|
134
|
+
|
|
66
|
135
|
providerKey_ = provider;
|
|
67
|
136
|
delete dataProvider_;
|
|
68
|
137
|
|
|
69
|
|
- dataProvider_ = dynamic_cast<DmpVectorDataProvider *>(DmpProviderRegistry::Instance()->CreateProvider(provider, dataSource_));
|
|
|
138
|
+ dataProvider_ = dynamic_cast<DmpVectorDataProvider *>(DmpProviderRegistry::Instance(provider)->CreateProvider(provider, dataSource_));
|
|
70
|
139
|
if (!dataProvider_)
|
|
71
|
140
|
{
|
|
72
|
141
|
isValid_ = false;
|
|
73
|
142
|
return false;
|
|
74
|
143
|
}
|
|
75
|
|
- isValid_ = dataProvider_->IsValid();
|
|
|
144
|
+ isValid_ = dataProvider_->IsValid()
|
|
|
145
|
+ ;
|
|
76
|
146
|
if (!isValid_)
|
|
77
|
147
|
{
|
|
78
|
148
|
return false;
|
|
79
|
149
|
}
|
|
80
|
150
|
wkbType_ = dataProvider_->WkbType();
|
|
81
|
|
-
|
|
82
|
151
|
return true;
|
|
83
|
|
-} |
|
|
\ No newline at end of file |
|
|
152
|
+}
|
|
|
153
|
+
|
|
|
154
|
+ shared_ptr<DmpVectorThinLayer> DmpVectorLayer::GetCurrentScaleTable(double dx)
|
|
|
155
|
+ {
|
|
|
156
|
+
|
|
|
157
|
+/*
|
|
|
158
|
+ int outTime = 600;
|
|
|
159
|
+ if(this->dataCount >500000 && this->m_pDataset->m_MapLayerThinning.size() ==0)
|
|
|
160
|
+ {
|
|
|
161
|
+ outTime = 20;
|
|
|
162
|
+ }
|
|
|
163
|
+
|
|
|
164
|
+ clsLockClass lock(_wlock);
|
|
|
165
|
+ time_t now = time(0);
|
|
|
166
|
+ //shared_ptr<WMSServer> wmsServer = this->m_mapWmsServer[servicename];
|
|
|
167
|
+ if(now - this->m_pDataset->m_loadMapLayerThinning > outTime)
|
|
|
168
|
+ {
|
|
|
169
|
+ this->m_pDataset->m_loadMapLayerThinning = now;
|
|
|
170
|
+ shared_ptr<Workspace> pWorkspaceDef = DataSourcePools::get_instance()->GetDefaultWorkspace();
|
|
|
171
|
+
|
|
|
172
|
+ this->m_pDataset->InitMapLayerThinning(pWorkspaceDef.get(),this->m_layerName, this->m_dbSource);
|
|
|
173
|
+ }
|
|
|
174
|
+ else
|
|
|
175
|
+ {
|
|
|
176
|
+ this->m_pDataset->m_loadMapLayerThinning = now;
|
|
|
177
|
+ }
|
|
|
178
|
+*/
|
|
|
179
|
+
|
|
|
180
|
+ for(int i =0; i< this->thinLayers_.size(); i++)
|
|
|
181
|
+ {
|
|
|
182
|
+ shared_ptr<DmpVectorThinLayer> mapLayerThinning = this->thinLayers_[i];
|
|
|
183
|
+
|
|
|
184
|
+ if(mapLayerThinning->IsCurrentLayer(dx))
|
|
|
185
|
+ {
|
|
|
186
|
+ return mapLayerThinning;
|
|
|
187
|
+ }
|
|
|
188
|
+ }
|
|
|
189
|
+ return nullptr;
|
|
|
190
|
+ } |
|
|
\ No newline at end of file |
...
|
...
|
|