Skip to content
Permalink
Browse files

PostGIS import

git-svn-id: http://svn.osgeo.org/qgis/trunk@5088 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Mar 24, 2006
1 parent dac4f3b commit 4f26c9faa78445d785d595a0e71e05cee8422edf
Showing with 77 additions and 11 deletions.
  1. +74 −9 src/plugins/grass/qgsgrassmodule.cpp
  2. +3 −2 src/plugins/grass/qgsgrassmodule.h
@@ -77,6 +77,7 @@
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"
#include <qgsrasterlayer.h>
#include "qgsdatasourceuri.h"
#include "qgsdataprovider.h"
#include "qgsfield.h"
#include "qgsfeature.h"
@@ -2122,7 +2123,7 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput (
QString tit;
if ( mDescription.isEmpty() )
{
tit = "OGR/GDAL Input";
tit = "OGR/PostGIS/GDAL Input";
}
else
{
@@ -2189,14 +2190,46 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
if ( mType == Ogr && layer->type() == QgsMapLayer::VECTOR )
{
QgsVectorLayer *vector = (QgsVectorLayer*)layer;
if ( vector->providerType() != "ogr" ) continue;
if ( vector->providerType() != "ogr"
&& vector->providerType() != "postgres" ) continue;

QgsDataProvider *provider = vector->getDataProvider();
QString uri = provider->getDataSourceUri();

QString uri;
QString ogrLayer;
if ( vector->providerType() == "postgres" )
{
// Construct OGR DSN
QgsDataSourceURI *dsUri = provider->getURI();
uri = "PG:host=" + dsUri->host
+ " dbname=" + dsUri->database;

if ( dsUri->port.length() > 0 )
uri += " port=" + dsUri->port;

if ( dsUri->username.length() > 0 )
uri += " user=" + dsUri->username;

if ( dsUri->password.length() > 0 )
uri += " password=" + dsUri->password;

ogrLayer = dsUri->schema + "." + dsUri->table;
}
else
{
uri = provider->getDataSourceUri();
ogrLayer = "";
}

std::cerr << "uri = " << uri.ascii() << std::endl;
std::cerr << "ogrLayer = " << ogrLayer.ascii() << std::endl;

mLayerComboBox->insertItem( layer->name() );
if ( layer->name() == current ) mLayerComboBox->setCurrentText ( current );

mUri.push_back ( uri );

mOgrLayers.push_back ( ogrLayer );
}
else if ( mType == Gdal && layer->type() == QgsMapLayer::RASTER )
{
@@ -2216,22 +2249,54 @@ QStringList QgsGrassModuleGdalInput::options()

QString opt(mKey + "=");

if ( current < mUri.size() ) {
if ( current >=0 && current < mUri.size() ) {
opt.append ( mUri[current] );
}
list.push_back( opt );

// TODO
/*
if ( !mOgrLayerOption.isNull() )
if ( !mOgrLayerOption.isNull() && mOgrLayers[current].length() > 0 )
{
opt = mOgrLayerOption + "=" ;
opt = mOgrLayerOption + "=";

// OGR does not support schemas !!!
if ( current >=0 && current < mUri.size() ) {
QStringList l = mOgrLayers[current].split(".");
opt += l.at(1);

// Currently only PostGIS is using layer
// -> layer -> PostGIS -> warning
if ( mOgrLayers[current].length() > 0 )
{
QMessageBox::warning( 0, "Warning",
"PostGIS driver in OGR does not support schemas!<br>"
"Only the table name will be used.<br>"
"It can result in wrong input if more tables of the same name<br>"
"are present in the database." );
}
}

list.push_back( opt );
}
*/

return list;
}

QString QgsGrassModuleGdalInput::ready()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassModuleGdalInput::ready()" << std::endl;
#endif

QString error;

std::cerr << "count = " << mLayerComboBox->count() << std::endl;
if ( mLayerComboBox->count() == 0 )
{
error.append ( title() + ":&nbsp;no input" );
}
return error;
}

QgsGrassModuleGdalInput::~QgsGrassModuleGdalInput()
{
}
@@ -572,8 +572,9 @@ class QgsGrassModuleGdalInput: public Q3GroupBox, public QgsGrassModuleItem

enum Type { Gdal, Ogr };

//! Retruns list of options which will be passed to module
virtual QStringList options();
//! Reimplemented
QStringList options();
QString ready();

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

0 comments on commit 4f26c9f

Please sign in to comment.
You can’t perform that action at this time.