Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add support for where option of v.in.ogr, fixes #836
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7705 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Dec 1, 2007
1 parent 9e7012d commit 7ae8b35
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/plugins/grass/modules/v.in.ogr.loc.qgm
Expand Up @@ -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 changes: 1 addition & 1 deletion src/plugins/grass/modules/v.in.ogr.qgm
Expand Up @@ -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>
25 changes: 23 additions & 2 deletions src/plugins/grass/qgsgrassmodule.cpp
Expand Up @@ -79,6 +79,7 @@
extern "C" {
#include <grass/gis.h>
#include <grass/Vect.h>
// #include <grass/version.h>
}


Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/grass/qgsgrassmodule.h
Expand Up @@ -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;
Expand All @@ -629,6 +632,9 @@ public slots:

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

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

/*********************** QgsGrassModuleField **********************/
Expand Down

0 comments on commit 7ae8b35

Please sign in to comment.