<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-CA">I fix the null geometries programmatically.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">For example:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">geom = feature.geometry()<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">if type(geom) == types.NoneType:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">              <do something> like skip or delete.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">To delete these geometries you can use this algorithm<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">featuresToDelete = []<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">for feature in layer.getFeatures():<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">              geom = feature.geometry()<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">              if type(geom) == types.NoneType:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">                             featuresToDelete.append(feature.id())<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">if len(featuresToDelete) > 0:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">              layer.startEditing()<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">              layer.setSelectedFeatures(featuresIds)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">              layer.deleteSelectedFeatures()<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">              layer.commitChanges()<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">to delete you also can used layer.dataProvider().deleteFeatures(featuresToDelete)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">I hope this will help.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">Marian<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><b>From:</b> Qgis-user <qgis-user-bounces@lists.osgeo.org> <b>
On Behalf Of </b>Jésahel Benoist<br>
<b>Sent:</b> Thursday, July 2, 2020 10:09 AM<br>
<b>To:</b> qgis-user ML <Qgis-user@lists.osgeo.org><br>
<b>Subject:</b> [EXT] [Qgis-user] null geometries workaround<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">I had to deal with null geometries (points) in a geopackage. As it shows some QGIS strange behavior I decided to post this.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">With QGIS 3.10.7, the 'removenullgeometries', 'fixgeometries', 'checkgeometries' processing tools doesn't work. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">The checkgeometry tool finds them, but gives only the id without any option to fix.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Finally, I found two ways to find the faulty lines :<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">The first is to create a calculated field with $x as value. (nan) is clearly shown then.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">You're then free to add a part or delete the faulty lines.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Hope it helps some people...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Jésahel<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
<br>
<hr>
<font face="Arial" color="Gray" size="1"><br>
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.<br>
<br>
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.<br>
</font>
</body>
</html>