Skip to content

Commit

Permalink
Enable minimum/maximum classification for wfs provider
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@5876 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Sep 27, 2006
1 parent 749f822 commit 00ed4f8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
52 changes: 50 additions & 2 deletions src/providers/wfs/qgswfsprovider.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgslogger.h"
#include <QDomDocument>
#include <QDomNodeList>
#include <cfloat>

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

QString QgsWFSProvider::minValue(int position)
{
return "0";
if(mMinMaxCash.size() == 0)
{
fillMinMaxCash();
}
return mMinMaxCash[position].first;
}

QString QgsWFSProvider::maxValue(int position)
{
return "0";
if(mMinMaxCash.size() == 0)
{
fillMinMaxCash();
}
return mMinMaxCash[position].second;
}

void QgsWFSProvider::fillMinMaxCash()
{
QgsFeature* theFeature = 0;
int fieldCount = fields().size();
int i;
double currentValue;

std::vector<std::pair<double, double> > tempMinMax;
tempMinMax.resize(fieldCount);
for(i = 0; i < fieldCount; ++i)
{
tempMinMax[i] = std::make_pair(DBL_MAX, -DBL_MAX);
}

reset();
while(theFeature = getNextFeature(true))
{
for(i = 0; i < fieldCount; ++i)
{
currentValue = (theFeature->attributeMap())[i].fieldValue().toDouble();
if(currentValue < tempMinMax[i].first)
{
tempMinMax[i].first = currentValue;
}
if(currentValue > tempMinMax[i].second)
{
tempMinMax[i].second = currentValue;
}
}
}

mMinMaxCash.clear();
mMinMaxCash.resize(fieldCount);
for(i = 0; i < fieldCount; ++i)
{
mMinMaxCash[i] = std::make_pair(QString::number(tempMinMax[i].first), QString::number(tempMinMax[i].second));
}
}

std::vector<QgsFeature>& QgsWFSProvider::identify(QgsRect *rect) /*legacy*/
Expand Down
6 changes: 6 additions & 0 deletions src/providers/wfs/qgswfsprovider.h
Expand Up @@ -97,6 +97,9 @@ class QgsWFSProvider: public QgsVectorDataProvider
mutable QGis::WKBTYPE mWKBType;
/**Source SRS*/
QgsSpatialRefSys* mSourceSRS;
/**Stores the minimum/maximum values for each attribute
The position in the vector is equal to the position of an attribute in the layers attribute vector*/
std::vector< std::pair<QString, QString> > mMinMaxCash;

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

/**Tries to create a QgsSpatialRefSys object and assign it to mSourceSRS. Returns 0 in case of success*/
int setSRSFromGML(const QDomElement& wfsCollectionElement);

/***/
void fillMinMaxCash();
};

#endif

0 comments on commit 00ed4f8

Please sign in to comment.