2

I am working with a shapefile in QGIS (point layer),and I am trying to loop over all the points, however some are apparently not having a valid geometry.
When I type layer.getFeature(1).geometry() I get <QgsGeometry: null> And therefore I cant use the .asPoint() function However when I loop through all features, then it dosen't show those with null geometry:

for feature in layer.getFeatures():
    print(feature.geometry().asPoint())

So how come that there is not shown any null geometry when looping through all layers, but one of the first (actually all features show null geometry when using the single feature layer.getFeature(x) command). Is there any way to solve this problem?

Frodon
  • 3,684
  • 1
  • 16
  • 33
Pawel
  • 39
  • 1

1 Answers1

1

According the docs, if you pass the getFeature method an feature id that doesn't exist it will return an invalid feature. So, it's likely that you don't have any features on that layer with a feature id of 1.

timothyh
  • 169
  • 2
  • 8