Skip to content

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed
 

‎src/providers/wfs/qgswfsprovider.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgslogger.h"
2323
#include <QDomDocument>
2424
#include <QDomNodeList>
25+
#include <cfloat>
2526

2627
#ifdef WIN32
2728
#define QGISEXTERN extern "C" __declspec( dllexport )
@@ -151,12 +152,59 @@ void QgsWFSProvider::reset()
151152

152153
QString QgsWFSProvider::minValue(int position)
153154
{
154-
return "0";
155+
if(mMinMaxCash.size() == 0)
156+
{
157+
fillMinMaxCash();
158+
}
159+
return mMinMaxCash[position].first;
155160
}
156161

157162
QString QgsWFSProvider::maxValue(int position)
158163
{
159-
return "0";
164+
if(mMinMaxCash.size() == 0)
165+
{
166+
fillMinMaxCash();
167+
}
168+
return mMinMaxCash[position].second;
169+
}
170+
171+
void QgsWFSProvider::fillMinMaxCash()
172+
{
173+
QgsFeature* theFeature = 0;
174+
int fieldCount = fields().size();
175+
int i;
176+
double currentValue;
177+
178+
std::vector<std::pair<double, double> > tempMinMax;
179+
tempMinMax.resize(fieldCount);
180+
for(i = 0; i < fieldCount; ++i)
181+
{
182+
tempMinMax[i] = std::make_pair(DBL_MAX, -DBL_MAX);
183+
}
184+
185+
reset();
186+
while(theFeature = getNextFeature(true))
187+
{
188+
for(i = 0; i < fieldCount; ++i)
189+
{
190+
currentValue = (theFeature->attributeMap())[i].fieldValue().toDouble();
191+
if(currentValue < tempMinMax[i].first)
192+
{
193+
tempMinMax[i].first = currentValue;
194+
}
195+
if(currentValue > tempMinMax[i].second)
196+
{
197+
tempMinMax[i].second = currentValue;
198+
}
199+
}
200+
}
201+
202+
mMinMaxCash.clear();
203+
mMinMaxCash.resize(fieldCount);
204+
for(i = 0; i < fieldCount; ++i)
205+
{
206+
mMinMaxCash[i] = std::make_pair(QString::number(tempMinMax[i].first), QString::number(tempMinMax[i].second));
207+
}
160208
}
161209

162210
std::vector<QgsFeature>& QgsWFSProvider::identify(QgsRect *rect) /*legacy*/

‎src/providers/wfs/qgswfsprovider.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class QgsWFSProvider: public QgsVectorDataProvider
9797
mutable QGis::WKBTYPE mWKBType;
9898
/**Source SRS*/
9999
QgsSpatialRefSys* mSourceSRS;
100+
/**Stores the minimum/maximum values for each attribute
101+
The position in the vector is equal to the position of an attribute in the layers attribute vector*/
102+
std::vector< std::pair<QString, QString> > mMinMaxCash;
100103

101104
/**Collects information about the field types. Is called internally from QgsWFSProvider::getFeature*/
102105
int describeFeatureType(const QString& uri, std::vector<QgsField>& fields);
@@ -141,6 +144,9 @@ class QgsWFSProvider: public QgsVectorDataProvider
141144

142145
/**Tries to create a QgsSpatialRefSys object and assign it to mSourceSRS. Returns 0 in case of success*/
143146
int setSRSFromGML(const QDomElement& wfsCollectionElement);
147+
148+
/***/
149+
void fillMinMaxCash();
144150
};
145151

146152
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.