Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layer with same name as in previous project get path from the previous layer in the qgs-file #59050

Open
1 of 2 tasks
norrasverige opened this issue Oct 11, 2024 · 3 comments
Open
1 of 2 tasks
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!

Comments

@norrasverige
Copy link

norrasverige commented Oct 11, 2024

What is the bug or the crash?

If I open a qqz-file with a shape file layer named for example "test". If I then click "New project" and add another shape file layer called "test" from another map, it will look ok as long as I have the project opened. When I save and close QGIS and open the project again, it will be the layer from the first qgz-file that is shown. I digged a bit deeper and found that in the qgs-file, the path in the source is correct under "layer-tree-layer", but has the path from the other layer in "datasource" under "MapLayer".

Steps to reproduce the issue

open QGIS
Create a shape file (polygon) named test.shp in folder test1
draw a square.
save the layer

Create a second shape file (polygon) named test.shp in folder test2
draw a triangle
save the layer

close QGIS
Open QGIS
import test.shp from test1 folder.
Save the QGIS project in test1 folder, name it test1.qgz
close QGIS

Open test1.qgz from File Explorer by double clicking it.
Create a new project in QGIS (Project --> New)
Add test.shp from test2 folder
Save the QGIS project in test2 folder, name it test2.qgz
close QGIS

Open test2.qgz from File Explorer by double clicking it.
Now you will see test.shp from test1 folder instead of the test.shp layer in test2 folder...

Versions

same problem in both 3.34.0 and 3.38.3-1

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

Tested on 3 different computers, but same issue on all.

@norrasverige norrasverige added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Oct 11, 2024
@damat46
Copy link

damat46 commented Oct 12, 2024

I have the same bug on my projects for a few weeks now. Was on 3.38.1, tried to update on 3.38.3 with same results. I was going to try on 3.34 when I saw you post.

@damat46
Copy link

damat46 commented Oct 13, 2024

Here is the workaround that I use.
I reload the local shape file on every project opening with the macro:

from qgis.core import QgsProject

def openProject():
project = QgsProject.instance()
layer = project.mapLayersByName(layerName)[0]
shpFileName = os.path.basename(layer.source())
new_source = os.path.join(projet.homePath(), shpFileName)
layer.setDataSource(new_source, layerName, 'ogr')
layer.triggerRepaint()

@norrasverige
Copy link
Author

norrasverige commented Oct 15, 2024

Here is the workaround that I use. I reload the local shape file on every project opening with the macro:

from qgis.core import QgsProject

def openProject(): project = QgsProject.instance() layer = project.mapLayersByName(layerName)[0] shpFileName = os.path.basename(layer.source()) new_source = os.path.join(projet.homePath(), shpFileName) layer.setDataSource(new_source, layerName, 'ogr') layer.triggerRepaint()

Thanks a lot! That worked 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!
Projects
None yet
Development

No branches or pull requests

2 participants