diff --git a/plugins/geoprocessing/qgspggeoprocessing.cpp b/plugins/geoprocessing/qgspggeoprocessing.cpp index 85821a3e455..c8cbf52403e 100644 --- a/plugins/geoprocessing/qgspggeoprocessing.cpp +++ b/plugins/geoprocessing/qgspggeoprocessing.cpp @@ -39,10 +39,7 @@ #include #include "qgsdlgpgbuffer.h" #include "qgspggeoprocessing.h" -extern "C" -{ -#include -} + // xpm for creating the toolbar icon #include "icon_buffer.xpm" @@ -131,6 +128,13 @@ void QgsPgGeoprocessing::buffer() // create the connection string QString connInfo = dataSource.left(dataSource.find("table=")); std::cerr << "Data source = " << QString("Datasource:%1\n\nConnectionInfo:%2").arg(dataSource).arg(connInfo) << std::endl; + // connect to the database and check the capabilities + PGconn *capTest = PQconnectdb((const char *) connInfo); + if (PQstatus(capTest) == CONNECTION_OK) { + postgisVersion(capTest); + } + PQfinish(capTest); + if(geosAvailable){ // get the table name QStringList connStrings = QStringList::split(" ", dataSource); QStringList tables = connStrings.grep("table="); @@ -321,7 +325,9 @@ void QgsPgGeoprocessing::buffer() QString err = tr("Error connecting to the database"); QMessageBox::critical(0, err, PQerrorMessage(conn)); } - + }else{ + QMessageBox::critical(0,"No GEOS support","Buffer function required GEOS support in PostGIS"); + } } else { QMessageBox::critical(0, "Not a PostgreSQL/PosGIS Layer", QString @@ -332,6 +338,49 @@ void QgsPgGeoprocessing::buffer() QMessageBox::warning(0, "No Active Layer", "You must select a layer in the legend to buffer"); } } +/* Functions for determining available features in postGIS */ +QString QgsPgGeoprocessing::postgisVersion(PGconn *connection){ + PGresult *result = PQexec(connection, "select postgis_version()"); + postgisVersionInfo = PQgetvalue(result,0,0); + std::cerr << "PostGIS version info: " << postgisVersionInfo << std::endl; + // assume no capabilities + geosAvailable = false; + gistAvailable = false; + projAvailable = false; + // parse out the capabilities and store them + QStringList postgisParts = QStringList::split(" ", postgisVersionInfo); + QStringList geos = postgisParts.grep("GEOS"); + if(geos.size() == 1){ + geosAvailable = (geos[0].find("=1")); + } + QStringList gist = postgisParts.grep("STATS"); + if(gist.size() == 1){ + gistAvailable = (geos[0].find("=1")); + } + QStringList proj = postgisParts.grep("PROJ"); + if(proj.size() == 1){ + projAvailable = (proj[0].find("=1")); + } + return postgisVersionInfo; +} +bool QgsPgGeoprocessing::hasGEOS(PGconn *connection){ + // make sure info is up to date for the current connection + postgisVersion(connection); + // get geos capability + return geosAvailable; +} +bool QgsPgGeoprocessing::hasGIST(PGconn *connection){ + // make sure info is up to date for the current connection + postgisVersion(connection); + // get gist capability + return gistAvailable; +} +bool QgsPgGeoprocessing::hasPROJ(PGconn *connection){ + // make sure info is up to date for the current connection + postgisVersion(connection); + // get proj4 capability + return projAvailable; +} // Unload the plugin by cleaning up the GUI void QgsPgGeoprocessing::unload() diff --git a/plugins/geoprocessing/qgspggeoprocessing.h b/plugins/geoprocessing/qgspggeoprocessing.h index 32566e052d4..def471153e9 100644 --- a/plugins/geoprocessing/qgspggeoprocessing.h +++ b/plugins/geoprocessing/qgspggeoprocessing.h @@ -24,11 +24,15 @@ #include "../qgisplugin.h" #include #include - +extern "C" +{ +#include +} class QMessageBox; class QToolBar; class QMenuBar; class QPopupMenu; + //#include "qgsworkerclass.h" #include "../../src/qgisapp.h" @@ -74,6 +78,19 @@ class QgsPgGeoprocessing:public QObject, public QgisPlugin //! unload the plugin void unload(); private: + //! get postgis version string + QString postgisVersion(PGconn *); + //! get status of GEOS capability + bool hasGEOS(PGconn *); + //! get status of GIST capability + bool hasGIST(PGconn *); + //! get status of PROJ4 capability + bool hasPROJ(PGconn *); + QString postgisVersionInfo; + bool geosAvailable; + bool gistAvailable; + bool projAvailable; + //! Name of the plugin QString pName; //! Version