Skip to content

Commit 4f26c9f

Browse files
author
rblazek
committedMar 24, 2006
PostGIS import
git-svn-id: http://svn.osgeo.org/qgis/trunk@5088 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent dac4f3b commit 4f26c9f

File tree

2 files changed

+77
-11
lines changed

2 files changed

+77
-11
lines changed
 

‎src/plugins/grass/qgsgrassmodule.cpp

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include "qgsmaplayer.h"
7878
#include "qgsvectorlayer.h"
7979
#include <qgsrasterlayer.h>
80+
#include "qgsdatasourceuri.h"
8081
#include "qgsdataprovider.h"
8182
#include "qgsfield.h"
8283
#include "qgsfeature.h"
@@ -2122,7 +2123,7 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput (
21222123
QString tit;
21232124
if ( mDescription.isEmpty() )
21242125
{
2125-
tit = "OGR/GDAL Input";
2126+
tit = "OGR/PostGIS/GDAL Input";
21262127
}
21272128
else
21282129
{
@@ -2189,14 +2190,46 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
21892190
if ( mType == Ogr && layer->type() == QgsMapLayer::VECTOR )
21902191
{
21912192
QgsVectorLayer *vector = (QgsVectorLayer*)layer;
2192-
if ( vector->providerType() != "ogr" ) continue;
2193+
if ( vector->providerType() != "ogr"
2194+
&& vector->providerType() != "postgres" ) continue;
21932195

21942196
QgsDataProvider *provider = vector->getDataProvider();
2195-
QString uri = provider->getDataSourceUri();
2197+
2198+
QString uri;
2199+
QString ogrLayer;
2200+
if ( vector->providerType() == "postgres" )
2201+
{
2202+
// Construct OGR DSN
2203+
QgsDataSourceURI *dsUri = provider->getURI();
2204+
uri = "PG:host=" + dsUri->host
2205+
+ " dbname=" + dsUri->database;
2206+
2207+
if ( dsUri->port.length() > 0 )
2208+
uri += " port=" + dsUri->port;
2209+
2210+
if ( dsUri->username.length() > 0 )
2211+
uri += " user=" + dsUri->username;
2212+
2213+
if ( dsUri->password.length() > 0 )
2214+
uri += " password=" + dsUri->password;
2215+
2216+
ogrLayer = dsUri->schema + "." + dsUri->table;
2217+
}
2218+
else
2219+
{
2220+
uri = provider->getDataSourceUri();
2221+
ogrLayer = "";
2222+
}
2223+
2224+
std::cerr << "uri = " << uri.ascii() << std::endl;
2225+
std::cerr << "ogrLayer = " << ogrLayer.ascii() << std::endl;
21962226

21972227
mLayerComboBox->insertItem( layer->name() );
21982228
if ( layer->name() == current ) mLayerComboBox->setCurrentText ( current );
2229+
21992230
mUri.push_back ( uri );
2231+
2232+
mOgrLayers.push_back ( ogrLayer );
22002233
}
22012234
else if ( mType == Gdal && layer->type() == QgsMapLayer::RASTER )
22022235
{
@@ -2216,22 +2249,54 @@ QStringList QgsGrassModuleGdalInput::options()
22162249

22172250
QString opt(mKey + "=");
22182251

2219-
if ( current < mUri.size() ) {
2252+
if ( current >=0 && current < mUri.size() ) {
22202253
opt.append ( mUri[current] );
22212254
}
22222255
list.push_back( opt );
22232256

2224-
// TODO
2225-
/*
2226-
if ( !mOgrLayerOption.isNull() )
2257+
if ( !mOgrLayerOption.isNull() && mOgrLayers[current].length() > 0 )
22272258
{
2228-
opt = mOgrLayerOption + "=" ;
2259+
opt = mOgrLayerOption + "=";
2260+
2261+
// OGR does not support schemas !!!
2262+
if ( current >=0 && current < mUri.size() ) {
2263+
QStringList l = mOgrLayers[current].split(".");
2264+
opt += l.at(1);
2265+
2266+
// Currently only PostGIS is using layer
2267+
// -> layer -> PostGIS -> warning
2268+
if ( mOgrLayers[current].length() > 0 )
2269+
{
2270+
QMessageBox::warning( 0, "Warning",
2271+
"PostGIS driver in OGR does not support schemas!<br>"
2272+
"Only the table name will be used.<br>"
2273+
"It can result in wrong input if more tables of the same name<br>"
2274+
"are present in the database." );
2275+
}
2276+
}
2277+
22292278
list.push_back( opt );
22302279
}
2231-
*/
2280+
22322281
return list;
22332282
}
22342283

2284+
QString QgsGrassModuleGdalInput::ready()
2285+
{
2286+
#ifdef QGISDEBUG
2287+
std::cerr << "QgsGrassModuleGdalInput::ready()" << std::endl;
2288+
#endif
2289+
2290+
QString error;
2291+
2292+
std::cerr << "count = " << mLayerComboBox->count() << std::endl;
2293+
if ( mLayerComboBox->count() == 0 )
2294+
{
2295+
error.append ( title() + ":&nbsp;no input" );
2296+
}
2297+
return error;
2298+
}
2299+
22352300
QgsGrassModuleGdalInput::~QgsGrassModuleGdalInput()
22362301
{
22372302
}

‎src/plugins/grass/qgsgrassmodule.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,9 @@ class QgsGrassModuleGdalInput: public Q3GroupBox, public QgsGrassModuleItem
572572

573573
enum Type { Gdal, Ogr };
574574

575-
//! Retruns list of options which will be passed to module
576-
virtual QStringList options();
575+
//! Reimplemented
576+
QStringList options();
577+
QString ready();
577578

578579
public slots:
579580
//! Fill combobox with currently available maps in QGIS canvas

0 commit comments

Comments
 (0)
Please sign in to comment.