I fix the null geometries programmatically.
For example:
geom = feature.geometry()
if type(geom) == types.NoneType:
              <do something> like skip or delete.

To delete these geometries you can use this algorithm
featuresToDelete = []
for feature in layer.getFeatures():
              geom = feature.geometry()
              if type(geom) == types.NoneType:
                             featuresToDelete.append(feature.id())

if len(featuresToDelete) > 0:
              layer.startEditing()
              layer.setSelectedFeatures(featuresIds)
              layer.deleteSelectedFeatures()
              layer.commitChanges()

to delete you also can used 
layer.dataProvider().deleteFeatures(featuresToDelete)

I hope this will help.
Thanks,
Marian



From: Qgis-user <qgis-user-boun...@lists.osgeo.org> On Behalf Of Jésahel Benoist
Sent: Thursday, July 2, 2020 10:09 AM
To: qgis-user ML <Qgis-user@lists.osgeo.org>
Subject: [EXT] [Qgis-user] null geometries workaround

I had to deal with null geometries (points) in a geopackage. As it shows some 
QGIS strange behavior I decided to post this.

When the attributes table is by default on "filtered by view", switching to 
"show all" is filtering null geometries. No way to show them... By changing the 
default behaviour in the options to "show all", there's no more filter, but it 
isn't possible to find faulty lines ; all graphic tools are working as if 
everything was correct.

I've found that the "geometry attribute table" plugin by P. Whitten can help, 
however, I wondered if there was a standard tool to do the job.

With QGIS 3.10.7, the 'removenullgeometries', 'fixgeometries', 
'checkgeometries' processing tools doesn't work.
The checkgeometry tool finds them, but gives only the id without any option to 
fix.

I found with "DB browser with SQLite" that the geometry was there, but x and y 
were 0x0000 0000 0000 f87f. This is for 'not a number' (nan) value. But I 
didn't find any expression to check for this value...

Finally, I found two ways to find the faulty lines :
The first is to create a calculated field with $x as value. (nan) is clearly 
shown then.
The second is to make a filter with this simple formulae : if (to_int($x)=0, 
true, false). The to_int() converts the nan value to 0, et voila. Easy.

You're then free to add a part or delete the faulty lines.

Hope it helps some people...

Jésahel



________________________________

This electronic message, as well as any transmitted files included in the 
electronic message, may contain privileged or confidential information and is 
intended solely for the use of the individual(s) or entity to which it is 
addressed. If you have received this electronic message in error please notify 
the sender immediately and delete the electronic message. Any unauthorized 
copying, disclosure or distribution of the electronic message is strictly 
forbidden. NAV CANADA accepts no liability for any damage caused by any virus 
and/or other malicious code transmitted by this electronic communication.

Le présent message électronique et tout fichier qui peut y être joint peuvent 
contenir des renseignements privilégiés ou confidentiels destinés à l’usage 
exclusif des personnes ou des organismes à qui ils s’adressent. Si vous avez 
reçu ce message électronique par erreur, veuillez en informer l’expéditeur 
immédiatement et supprimez le. Toute reproduction, divulgation ou distribution 
du présent message électronique est strictement interdite. NAV CANADA n’assume 
aucune responsabilité en cas de dommage causé par tout virus ou autre programme 
malveillant transmis par ce message électronique.
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to