@@ -149,6 +149,7 @@ bool QgsGrassFeatureIterator::nextFeature( QgsFeature& feature )
149
149
150
150
feature.setValid ( false );
151
151
int cat = -1 , type = -1 , id = -1 ;
152
+ QgsFeatureId featureId = -1 ;
152
153
153
154
QgsDebugMsgLevel ( " entered." , 3 );
154
155
@@ -172,13 +173,19 @@ bool QgsGrassFeatureIterator::nextFeature( QgsFeature& feature )
172
173
{
173
174
Vect_cidx_get_cat_by_index ( P->mMap , P->mCidxFieldIndex , mNextCidx ++, &cat, &type, &id );
174
175
// Warning: selection array is only of type line/area of current layer -> check type first
175
-
176
- if ( filterById && id != mRequest .filterFid () )
176
+ if ( !( type & P->mGrassType ) )
177
177
continue ;
178
178
179
- if ( !( type & P->mGrassType ) )
179
+ // The 'id' is a unique id of a GRASS geometry object (point, line, area)
180
+ // but it cannot be used as QgsFeatureId because one geometry object may
181
+ // represent more features because it may have more categories.
182
+ featureId = makeFeatureId ( id, cat );
183
+
184
+ if ( filterById && featureId != mRequest .filterFid () )
180
185
continue ;
181
186
187
+ // it is correct to use id with mSelection because mSelection is only used
188
+ // for geometry selection
182
189
if ( !mSelection [id] )
183
190
continue ;
184
191
@@ -190,11 +197,9 @@ bool QgsGrassFeatureIterator::nextFeature( QgsFeature& feature )
190
197
close ();
191
198
return false ; // No more features
192
199
}
193
- #if QGISDEBUG > 3
194
- QgsDebugMsg ( QString ( " cat = %1 type = %2 id = %3" ).arg ( cat ).arg ( type ).arg ( id ) );
195
- #endif
200
+ QgsDebugMsgLevel ( QString ( " cat = %1 type = %2 id = %3 fatureId = %4" ).arg ( cat ).arg ( type ).arg ( id ).arg ( featureId ), 3 );
196
201
197
- feature.setFeatureId ( id );
202
+ feature.setFeatureId ( featureId );
198
203
feature.initAttributes ( P->fields ().count () );
199
204
feature.setFields ( &P->fields () ); // allow name-based attribute lookups
200
205
@@ -395,3 +400,10 @@ void QgsGrassFeatureIterator::setFeatureGeometry( QgsFeature& feature, int id, i
395
400
396
401
feature.setGeometryAndOwnership ( wkb, wkbsize );
397
402
}
403
+
404
+ QgsFeatureId QgsGrassFeatureIterator::makeFeatureId ( int grassId, int cat )
405
+ {
406
+ // Because GRASS object id and category are both int and QgsFeatureId is qint64
407
+ // we can create unique QgsFeatureId from GRASS id and cat
408
+ return ( QgsFeatureId )grassId * 1000000000 + cat;
409
+ }
0 commit comments