<div dir="ltr">Buongiorno a tutti,<div><br></div><div>noto un comportamento strano in pyqgis nell'usare la funzione</div><div>QgsVectorFileWriter.deleteShapeFile(file_path)</div><div><br></div><div>di seguito il codice molto semplice che uso:</div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"JetBrains Mono",monospace"><span style="color:rgb(204,120,50)">def </span><span style="color:rgb(255,198,109)">removeLayer</span>(path_layer):<br>    <span style="color:rgb(128,128,128)"># remove layer from TOC if already loaded<br></span><span style="color:rgb(128,128,128)">    </span>basefile = os.path.basename(path_layer)<br>    diff_layer = os.path.splitext(basefile)[<span style="color:rgb(104,151,187)">0</span>]<br>    <span style="color:rgb(114,115,122)">directory </span>= os.path.dirname(path_layer)<br>    <span style="color:rgb(114,115,122)">extensions </span>= [<span style="color:rgb(106,135,89)">"shp"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"shx"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"dbf"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"prj"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"sbn"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"sbx"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"fbn"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"fbx"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"ain"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"aih"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"ixs"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"mxs"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"atx"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"xml"</span><span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">                  </span><span style="color:rgb(106,135,89)">"cpg"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"qix"</span>]<br>    output_path=path_layer<br>    <span style="color:rgb(204,120,50)">if </span>os.path.exists(path_layer):<br>        <span style="color:rgb(204,120,50)">if </span><span style="color:rgb(136,136,198)">len</span>(QgsProject.instance().mapLayersByName(diff_layer)) > <span style="color:rgb(104,151,187)">0</span>:<br>            lyr = QgsProject.instance().mapLayersByName(diff_layer)[<span style="color:rgb(104,151,187)">0</span>]<br>            <span style="color:rgb(136,136,198)">print</span>(<span style="color:rgb(106,135,89)">'renaming layer1: '</span><span style="color:rgb(204,120,50)">, </span><a href="http://lyr.id">lyr.id</a>())<br>            QgsProject.instance().removeMapLayer(<a href="http://lyr.id">lyr.id</a>())<br><br>        QgsVectorFileWriter.deleteShapeFile(path_layer)</pre><div>In sostanze se mando l'ultima riga dalla console python di QGIS cancello correttamente lo shapefile. Internamente al mio codice rimane in cartella il file .shp e .dbf che non vengono cancellati generandomi errori nella parte seguente.</div><div><br></div><div>Qualcuno saprebbe dirmi dove sto sbagliando?</div><div>Grazie</div><div>P</div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Ing. Pierluigi De Rosa (PhD in Earth Science)</div><div dir="ltr">Contract Professor of Geographic Information System at University of Perugia<br>cel: 349755826<span><span dir="ltr">8</span></span> / fax: 075 7823038<br>skype: pierluigi.derosa </div></div></div></div></div></div></div></div>