@@ -2646,7 +2646,7 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput(
2646
2646
}
2647
2647
2648
2648
// Read "whereoption" if defined
2649
- opt = qdesc.attribute ( " where " );
2649
+ opt = qdesc.attribute ( " whereoption " );
2650
2650
if ( !opt.isNull () )
2651
2651
{
2652
2652
QDomNode optNode = QgsGrassModule::nodeByKey ( gdesc, opt );
@@ -2697,6 +2697,7 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
2697
2697
{
2698
2698
mUri .push_back ( QString () );
2699
2699
mOgrLayers .push_back ( QString () );
2700
+ mOgrWheres .push_back ( QString () );
2700
2701
mLayerComboBox ->addItem ( tr ( " Select a layer" ), QVariant () );
2701
2702
}
2702
2703
@@ -2709,9 +2710,11 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
2709
2710
2710
2711
if ( mType == Ogr && layer->type () == QgsMapLayer::VectorLayer )
2711
2712
{
2712
- QgsVectorLayer *vector = ( QgsVectorLayer* )layer;
2713
- if ( vector->providerType () != " ogr"
2714
- && vector->providerType () != " postgres" ) continue ;
2713
+ QgsVectorLayer *vector = dynamic_cast <QgsVectorLayer*>( layer );
2714
+ if ( !vector ||
2715
+ ( vector->providerType () != " ogr" && vector->providerType () != " postgres" )
2716
+ )
2717
+ continue ;
2715
2718
2716
2719
QgsDataProvider *provider = vector->dataProvider ();
2717
2720
@@ -2732,10 +2735,45 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
2732
2735
ogrLayer += dsUri.table ();
2733
2736
ogrWhere = dsUri.sql ();
2734
2737
}
2735
- else
2738
+ else if ( vector-> providerType () == " ogr " )
2736
2739
{
2737
- uri = provider->dataSourceUri ();
2738
- ogrLayer = " " ;
2740
+ QStringList items = provider->dataSourceUri ().split ( " |" );
2741
+
2742
+ if ( items.size () > 1 )
2743
+ {
2744
+ uri = items[0 ];
2745
+
2746
+ ogrLayer = " " ;
2747
+ ogrWhere = " " ;
2748
+
2749
+ for ( int i = 1 ; i < items.size (); i++ )
2750
+ {
2751
+ QStringList args = items[i].split ( " =" );
2752
+
2753
+ if ( args.size () != 2 )
2754
+ continue ;
2755
+
2756
+ if ( args[0 ] == " layername" && args[0 ] == " layerid" )
2757
+ {
2758
+ ogrLayer = args[1 ];
2759
+ }
2760
+ else if ( args[0 ] == " subset" )
2761
+ {
2762
+ ogrWhere = args[1 ];
2763
+ }
2764
+ }
2765
+
2766
+ if ( uri.endsWith ( " .shp" , Qt::CaseInsensitive ) )
2767
+ {
2768
+ ogrLayer = " " ;
2769
+ }
2770
+ }
2771
+ else
2772
+ {
2773
+ uri = items[0 ];
2774
+ ogrLayer = " " ;
2775
+ ogrWhere = " " ;
2776
+ }
2739
2777
}
2740
2778
2741
2779
QgsDebugMsg ( " uri = " + uri );
@@ -2804,11 +2842,11 @@ QStringList QgsGrassModuleGdalInput::options()
2804
2842
}
2805
2843
#endif // GDAL_VERSION_NUM
2806
2844
list.push_back ( opt );
2845
+ }
2807
2846
2808
- if ( !mOgrWhereOption .isNull () && mOgrWheres [current].length () > 0 )
2809
- {
2810
- list.push_back ( mOgrWhereOption + " =" + mOgrWheres [current] );
2811
- }
2847
+ if ( !mOgrWhereOption .isNull () && mOgrWheres [current].length () > 0 )
2848
+ {
2849
+ list.push_back ( mOgrWhereOption + " =" + mOgrWheres [current] );
2812
2850
}
2813
2851
2814
2852
return list;
0 commit comments