Skip to content
Permalink
Browse files
WFS provider: Don't forget to set port to QHttp, better handling for …
…coordinate and tuple separators

git-svn-id: http://svn.osgeo.org/qgis/trunk@6948 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 21, 2007
1 parent 60fdc6d commit be639d1e47a39a5e19c5192be090e1277d7430c5
Showing with 54 additions and 13 deletions.
  1. +38 −11 src/providers/wfs/qgswfsdata.cpp
  2. +16 −2 src/providers/wfs/qgswfsdata.h
@@ -52,7 +52,7 @@ int QgsWFSData::getWFSData()

//separate host from query string
QUrl requestUrl(mUri);
mHttp.setHost(requestUrl.host());
mHttp.setHost(requestUrl.host(), requestUrl.port());
mHttp.get(mUri);

//just for a test
@@ -105,6 +105,8 @@ void QgsWFSData::startElement(const XML_Char* el, const XML_Char** attr)
{
mParseModeStack.push(QgsWFSData::coordinate);
mStringCash.clear();
mCoordinateSeparator = readCsFromAttribute(attr);
mTupleSeparator = readTsFromAttribute(attr);
}
else if(localName == mGeometryAttribute)
{
@@ -222,7 +224,7 @@ void QgsWFSData::endElement(const XML_Char* el)
else if(elementName == GML_NAMESPACE + NS_SEPARATOR + "Point")
{
std::list<QgsPoint> pointList;
if(pointsFromCoordinateString(pointList, mStringCash) != 0)
if(pointsFromCoordinateString(pointList, mStringCash, mCoordinateSeparator, mTupleSeparator) != 0)
{
//error
}
@@ -259,7 +261,7 @@ void QgsWFSData::endElement(const XML_Char* el)
//add WKB point to the feature

std::list<QgsPoint> pointList;
if(pointsFromCoordinateString(pointList, mStringCash) != 0)
if(pointsFromCoordinateString(pointList, mStringCash, mCoordinateSeparator, mTupleSeparator) != 0)
{
//error
}
@@ -292,7 +294,7 @@ void QgsWFSData::endElement(const XML_Char* el)
else if(elementName == GML_NAMESPACE + NS_SEPARATOR + "LinearRing")
{
std::list<QgsPoint> pointList;
if(pointsFromCoordinateString(pointList, mStringCash) != 0)
if(pointsFromCoordinateString(pointList, mStringCash, mCoordinateSeparator, mTupleSeparator) != 0)
{
//error
}
@@ -377,6 +379,34 @@ int QgsWFSData::readEpsgFromAttribute(int& epsgNr, const XML_Char** attr) const
return 2;
}

QString QgsWFSData::readCsFromAttribute(const XML_Char** attr) const
{
int i = 0;
while(attr[i] != NULL)
{
if(strcmp(attr[i], "cs") == 0)
{
return QString(attr[i+1]);
}
++i;
}
return ",";
}

QString QgsWFSData::readTsFromAttribute(const XML_Char** attr) const
{
int i = 0;
while(attr[i] != NULL)
{
if(strcmp(attr[i], "ts") == 0)
{
return QString(attr[i+1]);
}
++i;
}
return " ";
}

int QgsWFSData::createBBoxFromCoordinateString(QgsRect* bb, const QString& coordString) const
{
if(!bb)
@@ -387,7 +417,7 @@ int QgsWFSData::createBBoxFromCoordinateString(QgsRect* bb, const QString& coord
std::list<QgsPoint> points;
//qWarning("string is: ");
//qWarning(coordString.toLocal8Bit().data());
if(pointsFromCoordinateString(points, coordString) != 0)
if(pointsFromCoordinateString(points, coordString, mCoordinateSeparator, mTupleSeparator) != 0)
{
return 2;
}
@@ -403,18 +433,18 @@ int QgsWFSData::createBBoxFromCoordinateString(QgsRect* bb, const QString& coord
return 0;
}

int QgsWFSData::pointsFromCoordinateString(std::list<QgsPoint>& points, const QString& coordString) const
int QgsWFSData::pointsFromCoordinateString(std::list<QgsPoint>& points, const QString& coordString, const QString& cs, const QString& ts) const
{
//tuples are separated by space, x/y by ','
QStringList tuples = coordString.split(" ", QString::SkipEmptyParts);
QStringList tuples = coordString.split(ts, QString::SkipEmptyParts);
QStringList tuples_coordinates;
double x, y;
bool conversionSuccess;

QStringList::const_iterator tupleIterator;
for(tupleIterator = tuples.constBegin(); tupleIterator != tuples.constEnd(); ++tupleIterator)
{
tuples_coordinates = tupleIterator->split(",", QString::SkipEmptyParts);
tuples_coordinates = tupleIterator->split(cs, QString::SkipEmptyParts);
if(tuples_coordinates.size() < 2)
{
continue;
@@ -429,9 +459,6 @@ int QgsWFSData::pointsFromCoordinateString(std::list<QgsPoint>& points, const QS
{
continue;
}
//qWarning("adding point");
//qWarning(QString::number(x).toLocal8Bit().data());
//qWarning(QString::number(y).toLocal8Bit().data());
points.push_back(QgsPoint(x, y));
}
return 0;
@@ -76,12 +76,22 @@ class QgsWFSData: public QObject
@param attr attribute strings
@return 0 in case of success*/
int readEpsgFromAttribute(int& epsgNr, const XML_Char** attr) const;
/**Reads the 'cs' (coordinate separator) attribute.
@return the cs attribute value or the default value ","*/
QString readCsFromAttribute(const XML_Char** attr) const;
/**Reads the 'ts' (tuple separator) attribute.
@return the ts attribute value or the devault value " "*/
QString readTsFromAttribute(const XML_Char** attr) const;
/**Creates a rectangle from a coordinate string.
@return 0 in case of success*/
int createBBoxFromCoordinateString(QgsRect* bb, const QString& coordString) const;
/**Creates a set of points from a coordinate string.
@return 0 in case of success*/
int pointsFromCoordinateString(std::list<QgsPoint>& points, const QString& coordString) const;
@param points list that will contain the created points
@param coordString the text containing the coordinates
@param cs coortinate separator
@param ts tuple separator
@return 0 in case of success*/
int pointsFromCoordinateString(std::list<QgsPoint>& points, const QString& coordString, const QString& cs, const QString& ts) const;
int getPointWKB(unsigned char** wkb, int* size, const QgsPoint&) const;
int getLineWKB(unsigned char** wkb, int* size, const std::list<QgsPoint>& lineCoordinates) const;
int getRingWKB(unsigned char** wkb, int* size, const std::list<QgsPoint>& ringCoordinates) const;
@@ -128,6 +138,10 @@ class QgsWFSData: public QObject
int mAttributeIndex;
QString mTypeName;
QgsApplication::endian_t mEndian;
/**Coordinate separator for coordinate strings. Usually "," */
QString mCoordinateSeparator;
/**Tuple separator for coordinate strings. Usually " " */
QString mTupleSeparator;
};

#endif

0 comments on commit be639d1

Please sign in to comment.