Skip to content

Commit 7ae8b35

Browse files

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed
 

‎src/plugins/grass/modules/v.in.ogr.loc.qgm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">
33

44
<qgisgrassmodule label=" v.in.ogr - Import OGR/PostGIS vector layer and create a fitted location" module="v.in.ogr">
5-
<ogr key="dsn" layeroption="layer" label="OGR vector layer" />
5+
<ogr key="dsn" layeroption="layer" whereoption="where" label="OGR vector layer" />
66
<option key="output" />
77
<option key="location" />
88
<flag key="e" answer="on" hidden="yes" />
9-
</qgisgrassmodule>
9+
</qgisgrassmodule>

‎src/plugins/grass/modules/v.in.ogr.qgm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">
33

44
<qgisgrassmodule label="v.in.ogr - Import OGR/PostGIS vector layer" module="v.in.ogr">
5-
<ogr key="dsn" layeroption="layer" label="OGR vector layer" />
5+
<ogr key="dsn" layeroption="layer" whereoption="where" label="OGR vector layer" />
66
<option key="output" />
77
<flag key="o" answer="on" hidden="yes" />
88
</qgisgrassmodule>

‎src/plugins/grass/qgsgrassmodule.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
extern "C" {
8080
#include <grass/gis.h>
8181
#include <grass/Vect.h>
82+
// #include <grass/version.h>
8283
}
8384

8485

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

2525+
// Read "whereoption" if defined
2526+
opt = qdesc.attribute("whereoption");
2527+
if( !opt.isNull() ) {
2528+
QDomNode optNode = QgsGrassModule::nodeByKey ( gdesc, opt );
2529+
if( optNode.isNull() ) {
2530+
QMessageBox::warning( 0, tr("Warning"), tr("Cannot find whereoption ") + opt );
2531+
} else {
2532+
mOgrWhereOption = opt;
2533+
}
2534+
}
2535+
25242536
mLayerComboBox = new QComboBox ( this );
25252537

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

25652577
QString uri;
25662578
QString ogrLayer;
2579+
QString ogrWhere;
25672580
if ( vector->providerType() == "postgres" )
25682581
{
25692582
// Construct OGR DSN
25702583
QgsDataSourceURI dsUri(provider->dataSourceUri());
25712584
uri = "PG:" + dsUri.connInfo();
2585+
// which OGR/GRASS combo actually supports schemas?
25722586
ogrLayer = dsUri.table();
2587+
ogrWhere = dsUri.sql();
25732588
}
25742589
else
25752590
{
@@ -2586,6 +2601,7 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
25862601
mUri.push_back ( uri );
25872602

25882603
mOgrLayers.push_back ( ogrLayer );
2604+
mOgrWheres.push_back ( ogrWhere );
25892605
}
25902606
else if ( mType == Gdal && layer->type() == QgsMapLayer::RASTER )
25912607
{
@@ -2617,7 +2633,8 @@ QStringList QgsGrassModuleGdalInput::options()
26172633
if ( !mOgrLayerOption.isNull() && mOgrLayers[current].length() > 0 )
26182634
{
26192635
opt = mOgrLayerOption + "=";
2620-
#if GDAL_VERSION_NUM >= 1400 //need to check for GRASS >= 6.2 here too...
2636+
// which OGR/GRASS version actually supports schemas?
2637+
#if 1 // GDAL_VERSION_NUM >= 1400 && (GRASS_VERSION_MAJOR>6 || (GRASS_VERSION_MAJOR==6 && GRASS_VERSION_MINOR>=2))
26212638
opt += mOgrLayers[current];
26222639
#else
26232640
// Handle older versions of gdal gracefully
@@ -2640,6 +2657,10 @@ QStringList QgsGrassModuleGdalInput::options()
26402657
}
26412658
#endif //GDAL_VERSION_NUM
26422659
list.push_back( opt );
2660+
2661+
if( !mOgrWhereOption.isNull() && mOgrWheres[current].length()>0 ) {
2662+
list.push_back( mOgrWhereOption + "=" + mOgrWheres[current] );
2663+
}
26432664
}
26442665

26452666
return list;

‎src/plugins/grass/qgsgrassmodule.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,9 @@ public slots:
620620

621621
//! Ogr layer option associated with this input
622622
QString mOgrLayerOption;
623+
624+
//! Ogr sql option associated with this input
625+
QString mOgrWhereOption;
623626

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

630633
//! Ogr layer options
631634
std::vector<QString> mOgrLayers;
635+
636+
//! Ogr where clauses
637+
std::vector<QString> mOgrWheres;
632638
};
633639

634640
/*********************** QgsGrassModuleField **********************/

0 commit comments

Comments
 (0)
Please sign in to comment.