Skip to content
Permalink
Browse files
Some modifications for portable WFS support: Moved QgsHttpTransaction…
… to the core library, moved GetCapabilities methods from the wfs provider to the plugin (to class QgsWFSSourceSelect)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5918 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Oct 6, 2006
1 parent 7e7985d commit 06f864fcb4170280d737e5c5406e92189eef3221
@@ -61,6 +61,7 @@ libqgis_coreHEADERS = \
qgsfield.h \
qgsgeometry.h \
qgsgeometryvertexindex.h \
qgshttptransaction.h \
qgslabelattributes.h \
qgsline.h \
qgslinesymbol.h \
@@ -95,6 +96,7 @@ libqgis_coreHEADERS = \
libqgis_core_la_MOC = \
qgscontexthelp.moc.cpp \
qgsdataprovider.moc.cpp \
qgshttptransaction.moc.cpp \
qgsrasterdataprovider.moc.cpp

libqgis_core_la_SOURCES =\
@@ -114,6 +116,7 @@ libqgis_core_la_SOURCES =\
qgsfield.cpp \
qgsgeometry.cpp \
qgsgeometryvertexindex.cpp \
qgshttptransaction.cpp \
qgslabelattributes.cpp \
qgsline.cpp \
qgslinesymbol.cpp \
File renamed without changes.
File renamed without changes.
@@ -59,8 +59,7 @@ BUILT_SOURCES = $(plugin_MOC) $(plugin_UI)
wfsplugin_la_LIBADD = $(QT_LDADD) \
$(GDAL_LDADD) \
../../core/libqgis_core.la \
../../gui/libqgis_gui.la \
../../providers/wfs/libwfsprovider.la
../../gui/libqgis_gui.la

wfsplugin_la_CFLAGS = $(CFLAGS) $(EXTRA_CFLAGS) $(DEBUG_QGIS)
wfsplugin_la_CXXFLAGS = $(CXXFLAGS) \
@@ -17,13 +17,16 @@

#include "qgisiface.h"
#include "qgswfssourceselect.h"
#include "../../providers/wfs/qgswfsprovider.h"
#include "qgsnewhttpconnection.h"
#include "qgslayerprojectionselector.h"
#include "qgshttptransaction.h"
#include <QDomDocument>
#include <QListWidgetItem>
#include <QMessageBox>
#include <QSettings>

static const QString WFS_NAMESPACE = "http://www.opengis.net/wfs";

QgsWFSSourceSelect::QgsWFSSourceSelect(QWidget* parent, QgisIface* iface): QDialog(parent), mIface(iface)
{
setupUi(this);
@@ -75,6 +78,91 @@ void QgsWFSSourceSelect::populateConnectionList()
}
}

int QgsWFSSourceSelect::getCapabilities(const QString& uri, QgsWFSSourceSelect::REQUEST_ENCODING e, std::list<QString>& typenames, std::list< std::list<QString> >& crs)
{
switch(e)
{
case QgsWFSSourceSelect::GET:
return getCapabilitiesGET(uri, typenames, crs);
case QgsWFSSourceSelect::POST:
return getCapabilitiesPOST(uri, typenames, crs);
case QgsWFSSourceSelect::SOAP:
return getCapabilitiesSOAP(uri, typenames, crs);
}
return 1;
}

int QgsWFSSourceSelect::getCapabilitiesGET(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs)
{
QString request = uri + "SERVICE=WFS&REQUEST=GetCapabilities&VERSION=1.1.1";
QByteArray result;
QgsHttpTransaction http(request);
http.getSynchronously(result);

QDomDocument capabilitiesDocument;
if(!capabilitiesDocument.setContent(result, true))
{
return 1; //error
}



//get the <FeatureType> elements
QDomNodeList featureTypeList = capabilitiesDocument.elementsByTagNameNS(WFS_NAMESPACE, "FeatureType");
for(unsigned int i = 0; i < featureTypeList.length(); ++i)
{
QDomElement featureTypeElem = featureTypeList.at(i).toElement();
std::list<QString> featureSRSList; //SRS list for this feature

//Name
QDomNodeList nameList = featureTypeElem.elementsByTagNameNS(WFS_NAMESPACE, "Name");
if(nameList.length() > 0)
{
typenames.push_back(nameList.at(0).toElement().text());
}

//DefaultSRS is always the first entry in the feature crs list
QDomNodeList defaultSRSList = featureTypeElem.elementsByTagNameNS(WFS_NAMESPACE, "DefaultSRS");
if(defaultSRSList.length() > 0)
{
featureSRSList.push_back(defaultSRSList.at(0).toElement().text());
}

//OtherSRS
QDomNodeList otherSRSList = featureTypeElem.elementsByTagNameNS(WFS_NAMESPACE, "OtherSRS");
for(unsigned int i = 0; i < otherSRSList.length(); ++i)
{
featureSRSList.push_back(otherSRSList.at(i).toElement().text());
}

//Support <SRS> for compatibility with older versions
QDomNodeList srsList = featureTypeElem.elementsByTagNameNS(WFS_NAMESPACE, "SRS");
for(unsigned int i = 0; i < srsList.length(); ++i)
{
featureSRSList.push_back(srsList.at(i).toElement().text());
}

crs.push_back(featureSRSList);
}


//print out result for a test
QString resultString(result);
qWarning(resultString);

return 0;
}

int QgsWFSSourceSelect::getCapabilitiesPOST(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs)
{
return 1; //soon...
}

int QgsWFSSourceSelect::getCapabilitiesSOAP(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs)
{
return 1; //soon...
}

void QgsWFSSourceSelect::addEntryToServerList()
{
QgsNewHttpConnection *nc = new QgsNewHttpConnection(this, "/Qgis/connections-wfs/");
@@ -121,7 +209,7 @@ void QgsWFSSourceSelect::connectToServer()
//make a GetCapabilities request
std::list<QString> typenames;
std::list< std::list<QString> > crsList;
if(QgsWFSProvider::getCapabilities(mUri, QgsWFSProvider::GET, typenames, crsList) != 0)
if(getCapabilities(mUri, QgsWFSSourceSelect::GET, typenames, crsList) != 0)
{
qWarning("error during GetCapabilities request");
}
@@ -27,6 +27,14 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
{
Q_OBJECT
public:

enum REQUEST_ENCODING
{
GET,
POST,
SOAP /*Note that this goes also through HTTP POST but additionally uses soap envelope and friends*/
};

QgsWFSSourceSelect(QWidget* parent, QgisIface* iface);
~QgsWFSSourceSelect();

@@ -41,6 +49,17 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
std::map<QString, std::list<QString> > mAvailableCRS;
void populateConnectionList();

/**Makes a GetCapabilities and returns the typenamse and crs supported by the server.
@param typenames a list of layers provided by the server
@param a list of crs supported by the server. The place in the list corresponds to the \
typenames list (means that the crs list at position 0 is a crs for typename at position 0 etc.)
@return 0 in case of success*/
int getCapabilities(const QString& uri, QgsWFSSourceSelect::REQUEST_ENCODING e, std::list<QString>& typenames, std::list< std::list<QString> >& crs);
//encoding specific methods of getCapabilities
int getCapabilitiesGET(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs);
int getCapabilitiesPOST(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs);
int getCapabilitiesSOAP(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs);

private slots:
void addEntryToServerList();
void modifyEntryOfServerList();
@@ -3,12 +3,10 @@ INCLUDES = -I../../core/ -I../../gui/ -I../../ui
%.moc.cpp: %.h
$(MOC) -o $@ $<

libwfsprovider_MOC = qgshttptransaction.moc.cpp

plugindir = ${pkglibdir}
plugin_LTLIBRARIES = libwfsprovider.la

libwfsprovider_la_SOURCES = qgswfsprovider.cpp qgshttptransaction.cpp $(libwfsprovider_MOC)
libwfsprovider_la_SOURCES = qgswfsprovider.cpp $(libwfsprovider_MOC)

BUILT_SOURCES = $(wfsprovider_MOC)

@@ -246,20 +246,6 @@ void QgsWFSProvider::select(QgsRect *mbr, bool useIntersect)
mFeatureIterator = mSelectedFeatures->begin();
}

int QgsWFSProvider::getCapabilities(const QString& uri, QgsWFSProvider::REQUEST_ENCODING e, std::list<QString>& typenames, std::list< std::list<QString> >& crs)
{
switch(e)
{
case QgsWFSProvider::GET:
return getCapabilitiesGET(uri, typenames, crs);
case QgsWFSProvider::POST:
return getCapabilitiesPOST(uri, typenames, crs);
case QgsWFSProvider::SOAP:
return getCapabilitiesSOAP(uri, typenames, crs);
}
return 1;
}

int QgsWFSProvider::getFeature(const QString& uri)
{
//GET or SOAP?
@@ -319,77 +305,6 @@ int QgsWFSProvider::describeFeatureType(const QString& uri, std::vector<QgsField
return 1;
}

int QgsWFSProvider::getCapabilitiesGET(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs)
{
QString request = uri + "SERVICE=WFS&REQUEST=GetCapabilities&VERSION=1.1.1";
QByteArray result;
QgsHttpTransaction http(request);
http.getSynchronously(result);

QDomDocument capabilitiesDocument;
if(!capabilitiesDocument.setContent(result, true))
{
return 1; //error
}



//get the <FeatureType> elements
QDomNodeList featureTypeList = capabilitiesDocument.elementsByTagNameNS(WFS_NAMESPACE, "FeatureType");
for(unsigned int i = 0; i < featureTypeList.length(); ++i)
{
QDomElement featureTypeElem = featureTypeList.at(i).toElement();
std::list<QString> featureSRSList; //SRS list for this feature

//Name
QDomNodeList nameList = featureTypeElem.elementsByTagNameNS(WFS_NAMESPACE, "Name");
if(nameList.length() > 0)
{
typenames.push_back(nameList.at(0).toElement().text());
}

//DefaultSRS is always the first entry in the feature crs list
QDomNodeList defaultSRSList = featureTypeElem.elementsByTagNameNS(WFS_NAMESPACE, "DefaultSRS");
if(defaultSRSList.length() > 0)
{
featureSRSList.push_back(defaultSRSList.at(0).toElement().text());
}

//OtherSRS
QDomNodeList otherSRSList = featureTypeElem.elementsByTagNameNS(WFS_NAMESPACE, "OtherSRS");
for(unsigned int i = 0; i < otherSRSList.length(); ++i)
{
featureSRSList.push_back(otherSRSList.at(i).toElement().text());
}

//Support <SRS> for compatibility with older versions
QDomNodeList srsList = featureTypeElem.elementsByTagNameNS(WFS_NAMESPACE, "SRS");
for(unsigned int i = 0; i < srsList.length(); ++i)
{
featureSRSList.push_back(srsList.at(i).toElement().text());
}

crs.push_back(featureSRSList);
}


//print out result for a test
QString resultString(result);
qWarning(resultString);

return 0;
}

int QgsWFSProvider::getCapabilitiesPOST(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs)
{
return 1; //soon...
}

int QgsWFSProvider::getCapabilitiesSOAP(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs)
{
return 1; //soon...
}

int QgsWFSProvider::getFeatureGET(const QString& uri, const QString& geometryAttribute)
{
//assemble request string
@@ -65,13 +65,6 @@ class QgsWFSProvider: public QgsVectorDataProvider
results. Posibilities are GET, POST, SOAP*/
void setEncoding(QgsWFSProvider::REQUEST_ENCODING e) {mEncoding = e;}

/**Makes a GetCapabilities and returns the typenamse and crs supported by the server. This function is static because it is usually used from dialogs when no WFS provider object yet exists.
@param typenames a list of layers provided by the server
@param a list of crs supported by the server. The place in the list corresponds to the \
typenames list (means that the crs list at position 0 is a crs for typename at position 0 etc.)
@return 0 in case of success*/
static int getCapabilities(const QString& uri, QgsWFSProvider::REQUEST_ENCODING e, std::list<QString>& typenames, std::list< std::list<QString> >& crs);

/**Makes a GetFeatures, receives the features from the wfs server (as GML), converts them to QgsFeature and \
stores them in a vector*/
int getFeature(const QString& uri);
@@ -113,10 +106,6 @@ class QgsWFSProvider: public QgsVectorDataProvider
/**Collects information about the field types. Is called internally from QgsWFSProvider::getFeature*/
int describeFeatureType(const QString& uri, std::vector<QgsField>& fields);

//encoding specific methods of getCapabilities
static int getCapabilitiesGET(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs);
static int getCapabilitiesPOST(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs);
static int getCapabilitiesSOAP(const QString& uri, std::list<QString>& typenames, std::list< std::list<QString> >& crs);
//encoding specific methods of getFeature
int getFeatureGET(const QString& uri, const QString& geometryAttribute);
int getFeaturePOST(const QString& uri, const QString& geometryAttribute);
@@ -10,17 +10,13 @@ plugin_LTLIBRARIES = wmsprovider.la
## non-uic files generated from MOC

wmsprovider_MOC = qgswmsprovider.moc.cpp \
qgshttptransaction.moc.cpp \
../../core/qgsdataprovider.moc.cpp \
../../core/qgsrasterdataprovider.moc.cpp

wmsprovider_la_SOURCES = \
qgswmsprovider.cpp \
qgswmsprovider.moc.cpp \
qgswmsprovider.h \
qgshttptransaction.cpp \
qgshttptransaction.moc.cpp \
qgshttptransaction.h
qgswmsprovider.h

BUILT_SOURCES = $(wmsprovider_MOC)

0 comments on commit 06f864f

Please sign in to comment.