Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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@5918 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Oct 6, 2006
1 parent 0ea970d commit 5a7720f
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 108 deletions.
3 changes: 3 additions & 0 deletions src/core/Makefile.am
Expand Up @@ -61,6 +61,7 @@ libqgis_coreHEADERS = \
qgsfield.h \
qgsgeometry.h \
qgsgeometryvertexindex.h \
qgshttptransaction.h \
qgslabelattributes.h \
qgsline.h \
qgslinesymbol.h \
Expand Down Expand Up @@ -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 =\
Expand All @@ -114,6 +116,7 @@ libqgis_core_la_SOURCES =\
qgsfield.cpp \
qgsgeometry.cpp \
qgsgeometryvertexindex.cpp \
qgshttptransaction.cpp \
qgslabelattributes.cpp \
qgsline.cpp \
qgslinesymbol.cpp \
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions src/plugins/wfs/Makefile.am
Expand Up @@ -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) \
Expand Down
92 changes: 90 additions & 2 deletions src/plugins/wfs/qgswfssourceselect.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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/");
Expand Down Expand Up @@ -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");
}
Expand Down
19 changes: 19 additions & 0 deletions src/plugins/wfs/qgswfssourceselect.h
Expand Up @@ -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();

Expand All @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions src/providers/wfs/Makefile.am
Expand Up @@ -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)

Expand Down
85 changes: 0 additions & 85 deletions src/providers/wfs/qgswfsprovider.cpp
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/providers/wfs/qgswfsprovider.h
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions src/providers/wms/Makefile.am
Expand Up @@ -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)

Expand Down

0 comments on commit 5a7720f

Please sign in to comment.