@@ -233,6 +233,41 @@ QString QgsOgrProvider::storageType() const
233
233
}
234
234
235
235
236
+
237
+ bool QgsOgrProvider::getFeatureAtId (int featureId,
238
+ QgsFeature& feature,
239
+ bool fetchGeometry,
240
+ QgsAttributeList fetchAttributes)
241
+ {
242
+ OGRFeature *fet = ogrLayer->GetFeature (featureId);
243
+ if (fet == NULL )
244
+ return false ;
245
+
246
+ feature.setFeatureId (fet->GetFID ());
247
+
248
+ /* fetch geometry */
249
+ if (fetchGeometry)
250
+ {
251
+ OGRGeometry *geom = fet->GetGeometryRef ();
252
+
253
+ // get the wkb representation
254
+ unsigned char *wkb = new unsigned char [geom->WkbSize ()];
255
+ geom->exportToWkb ((OGRwkbByteOrder) QgsApplication::endian (), wkb);
256
+
257
+ feature.setGeometryAndOwnership (wkb, geom->WkbSize ());
258
+ }
259
+
260
+ /* fetch attributes */
261
+ for (QgsAttributeList::iterator it = fetchAttributes.begin (); it != fetchAttributes.end (); ++it)
262
+ {
263
+ getFeatureAttribute (fet,feature,*it);
264
+ }
265
+
266
+ return true ;
267
+ }
268
+
269
+
270
+
236
271
bool QgsOgrProvider::getNextFeature (QgsFeature& feature,
237
272
bool fetchGeometry,
238
273
QgsAttributeList fetchAttributes,
@@ -251,49 +286,57 @@ bool QgsOgrProvider::getNextFeature(QgsFeature& feature,
251
286
while ((fet = ogrLayer->GetNextFeature ()) != NULL )
252
287
{
253
288
// skip features without geometry
254
- if (fet->GetGeometryRef () != NULL || mFetchFeaturesWithoutGeom )
289
+ if (fet->GetGeometryRef () == NULL && ! mFetchFeaturesWithoutGeom )
255
290
{
256
- OGRFeatureDefn * featureDefinition = fet->GetDefnRef ();
257
- QString featureTypeName = featureDefinition ? QString (featureDefinition->GetName ()) : QString (" " );
258
- feature.setFeatureId (fet->GetFID ());
259
- feature.setTypeName (featureTypeName);
260
-
261
- if (fetchGeometry)
262
- {
263
- OGRGeometry *geom = fet->GetGeometryRef ();
291
+ delete fet;
292
+ continue ;
293
+ }
264
294
265
- // get the wkb representation
266
- unsigned char *wkb = new unsigned char [geom->WkbSize ()];
267
- geom->exportToWkb ((OGRwkbByteOrder) QgsApplication::endian (), wkb);
268
-
269
- feature.setGeometryAndOwnership (wkb, geom->WkbSize ());
295
+ OGRFeatureDefn * featureDefinition = fet->GetDefnRef ();
296
+ QString featureTypeName = featureDefinition ? QString (featureDefinition->GetName ()) : QString (" " );
297
+ feature.setFeatureId (fet->GetFID ());
298
+ feature.setTypeName (featureTypeName);
270
299
271
- if (mUseIntersect )
272
- {
273
- // precise test for intersection with search rectangle
274
- // first make QgsRect from OGRPolygon
275
- OGREnvelope env;
276
- mSelectionRectangle ->getEnvelope (&env);
277
- if (env.IsInit ()) // if envelope is invalid, skip the precise intersection test
278
- {
279
- selectionRect.set (env.MinX , env.MinY , env.MaxX , env.MaxY );
280
- if (!feature.geometry ()->fast_intersects (selectionRect))
281
- {
282
- delete fet;
283
- continue ;
284
- }
285
- }
286
- }
287
- }
300
+ /* fetch geometry */
301
+ if (fetchGeometry)
302
+ {
303
+ OGRGeometry *geom = fet->GetGeometryRef ();
304
+
305
+ // get the wkb representation
306
+ unsigned char *wkb = new unsigned char [geom->WkbSize ()];
307
+ geom->exportToWkb ((OGRwkbByteOrder) QgsApplication::endian (), wkb);
308
+
309
+ feature.setGeometryAndOwnership (wkb, geom->WkbSize ());
310
+
311
+ if (mUseIntersect )
312
+ {
313
+ // precise test for intersection with search rectangle
314
+ // first make QgsRect from OGRPolygon
315
+ OGREnvelope env;
316
+ mSelectionRectangle ->getEnvelope (&env);
317
+ if (env.IsInit ()) // if envelope is invalid, skip the precise intersection test
318
+ {
319
+ selectionRect.set (env.MinX , env.MinY , env.MaxX , env.MaxY );
320
+ if (!feature.geometry ()->fast_intersects (selectionRect))
321
+ {
322
+ delete fet;
323
+ continue ;
324
+ }
325
+ }
326
+
327
+ }
328
+ }
288
329
289
- for (QgsAttributeList::iterator it = fetchAttributes.begin (); it != fetchAttributes.end (); ++it)
290
- {
291
- getFeatureAttribute (fet,feature,*it);
292
- }
293
-
294
- break ;
330
+ /* fetch attributes */
331
+ for (QgsAttributeList::iterator it = fetchAttributes.begin (); it != fetchAttributes.end (); ++it)
332
+ {
333
+ getFeatureAttribute (fet,feature,*it);
295
334
}
296
- }
335
+
336
+ /* we have a feature, end this cycle */
337
+ break ;
338
+
339
+ } /* while */
297
340
298
341
if (fet)
299
342
{
0 commit comments