archaeodav / felttegn

Public repository for FeltTegn, a Qgis Plugin for processing survey data from archaeological excavations conducted by Danish Museums
GNU General Public License v3.0
5 stars 1 forks source link

v1.00 Overwrite existing layer on windows #21

Open archaeodav opened 2 years ago

archaeodav commented 2 years ago

On Windows the plugin will intermittently refuse to overwrite an existing layer of the same name if it's loaded in the main qgis window. This i s a known issue with the underlying OSGEO library. To attempt to mitigate this I've added the following to remove the existing layers and reload all layers :

for lyr in QgsProject.instance().mapLayers().values():
    if lyr.name()==name:
        QgsProject.instance().removeMapLayers([lyr.id()])
         QgsProject.instance().reloadAllLayers()
QgsProject.instance().reloadAllLayers()

This helps, but doesn't work every time for some reason. I can't replicate this fault under Linux.

EDIT Should add that it doesn't care about the file existing already in the file system- only if it's loaded in QGIS