Skip to content
Permalink
Browse files

add support for where option of v.in.ogr, fixes #836

git-svn-id: http://svn.osgeo.org/qgis/trunk@7705 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Dec 1, 2007
1 parent 4be22d5 commit 569d12dba21e1310816a416ff2112067803d8e27
@@ -2,8 +2,8 @@
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">

<qgisgrassmodule label=" v.in.ogr - Import OGR/PostGIS vector layer and create a fitted location" module="v.in.ogr">
<ogr key="dsn" layeroption="layer" label="OGR vector layer" />
<ogr key="dsn" layeroption="layer" whereoption="where" label="OGR vector layer" />
<option key="output" />
<option key="location" />
<flag key="e" answer="on" hidden="yes" />
</qgisgrassmodule>
</qgisgrassmodule>
@@ -2,7 +2,7 @@
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">

<qgisgrassmodule label="v.in.ogr - Import OGR/PostGIS vector layer" module="v.in.ogr">
<ogr key="dsn" layeroption="layer" label="OGR vector layer" />
<ogr key="dsn" layeroption="layer" whereoption="where" label="OGR vector layer" />
<option key="output" />
<flag key="o" answer="on" hidden="yes" />
</qgisgrassmodule>
@@ -79,6 +79,7 @@
extern "C" {
#include <grass/gis.h>
#include <grass/Vect.h>
// #include <grass/version.h>
}


@@ -2483,7 +2484,7 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput (
QDomElement &gdesc, QDomNode &gnode, QWidget * parent)
: Q3GroupBox ( 1, Qt::Vertical, parent ),
QgsGrassModuleItem ( module, key, qdesc, gdesc, gnode ),
mType(type), mOgrLayerOption(0)
mType(type), mOgrLayerOption(0), mOgrWhereOption(0)
{
QString tit;
if ( mDescription.isEmpty() )
@@ -2521,6 +2522,17 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput (
}
}

// Read "whereoption" if defined
opt = qdesc.attribute("whereoption");
if( !opt.isNull() ) {
QDomNode optNode = QgsGrassModule::nodeByKey ( gdesc, opt );
if( optNode.isNull() ) {
QMessageBox::warning( 0, tr("Warning"), tr("Cannot find whereoption ") + opt );
} else {
mOgrWhereOption = opt;
}
}

mLayerComboBox = new QComboBox ( this );

// Of course, activated(int) is not enough, but there is no signal
@@ -2564,12 +2576,15 @@ void QgsGrassModuleGdalInput::updateQgisLayers()

QString uri;
QString ogrLayer;
QString ogrWhere;
if ( vector->providerType() == "postgres" )
{
// Construct OGR DSN
QgsDataSourceURI dsUri(provider->dataSourceUri());
uri = "PG:" + dsUri.connInfo();
// which OGR/GRASS combo actually supports schemas?
ogrLayer = dsUri.table();
ogrWhere = dsUri.sql();
}
else
{
@@ -2586,6 +2601,7 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
mUri.push_back ( uri );

mOgrLayers.push_back ( ogrLayer );
mOgrWheres.push_back ( ogrWhere );
}
else if ( mType == Gdal && layer->type() == QgsMapLayer::RASTER )
{
@@ -2617,7 +2633,8 @@ QStringList QgsGrassModuleGdalInput::options()
if ( !mOgrLayerOption.isNull() && mOgrLayers[current].length() > 0 )
{
opt = mOgrLayerOption + "=";
#if GDAL_VERSION_NUM >= 1400 //need to check for GRASS >= 6.2 here too...
// which OGR/GRASS version actually supports schemas?
#if 1 // GDAL_VERSION_NUM >= 1400 && (GRASS_VERSION_MAJOR>6 || (GRASS_VERSION_MAJOR==6 && GRASS_VERSION_MINOR>=2))
opt += mOgrLayers[current];
#else
// Handle older versions of gdal gracefully
@@ -2640,6 +2657,10 @@ QStringList QgsGrassModuleGdalInput::options()
}
#endif //GDAL_VERSION_NUM
list.push_back( opt );

if( !mOgrWhereOption.isNull() && mOgrWheres[current].length()>0 ) {
list.push_back( mOgrWhereOption + "=" + mOgrWheres[current] );
}
}

return list;
@@ -620,6 +620,9 @@ public slots:

//! Ogr layer option associated with this input
QString mOgrLayerOption;

//! Ogr sql option associated with this input
QString mOgrWhereOption;

//! Combobox for QGIS layers
QComboBox *mLayerComboBox;
@@ -629,6 +632,9 @@ public slots:

//! Ogr layer options
std::vector<QString> mOgrLayers;

//! Ogr where clauses
std::vector<QString> mOgrWheres;
};

/*********************** QgsGrassModuleField **********************/

0 comments on commit 569d12d

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