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

QgsProject.addmaplayer adds layer at whrong position #60167

Open
2 tasks
Kohlroulade opened this issue Jan 16, 2025 · 0 comments
Open
2 tasks

QgsProject.addmaplayer adds layer at whrong position #60167

Kohlroulade opened this issue Jan 16, 2025 · 0 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! PyQGIS Related to the PyQGIS API

Comments

@Kohlroulade
Copy link

Kohlroulade commented Jan 16, 2025

What is the bug or the crash?

I have created a new layer from a json-file and added it to my project like this:

layer = QgsVectorLayer('/path/to/my/layer.json', 'myLayer')
myProject.addmapLayer(layer)

Initially my project only has an empty group-layer. When I run the above, mLayer is placed beside that group-layer - OK. However once I delete myLayer and execute the code again, the new layer is added into the group-layer.

I was able to circumvent this by setting the addToLegend-pparameter to False and call QgsProject.instance().layerTreeRoot().insertChildNode(-1, QgsLayerTreeLayer(layer)) myself, which seems to fix it. However it seems counter-intuitive to me, wha addmaplayer should behave that way.

Steps to reproduce the issue

  1. Create an empty project
  2. add emtpy group layer
  3. create some geojson-file, e.g from my attached one (streckensuche_response.json)
  4. with python-console execute this:
layer = QgsVectorLayer('streckensuche_response.json', 'mylayer')
QgsProject.instance().addMapLayer(layer)
  1. delete the layer
  2. execute the above 2 lines of code again
  3. the layer is added to the group-layer

Versions

QGIS-Version
3.34.11-Prizren
QGIS-Codeversion
2904bce
Qt-Version
5.15.13
Python-Version
3.12.6
GDAL-Version
3.9.2
PROJ-Version
9.4.0
EPSG-Registraturdatenbankversion
v11.004 (2024-02-24)
GEOS-Version
3.12.2-CAPI-1.18.2
SQLite-Version
3.45.1
PDAL-Version
2.6.3
PostgreSQL-Client-Version
16.2
SpatiaLite-Version
5.1.0
QWT-Version
6.2.0
QScintilla2-Version
2.14.1
BS-Version
Windows 10 Version 2009

Aktive Python-Erweiterungen
pluginbuilder3
3.2.1
plugin_reloader
0.17
db_manager
0.1.20
grassprovider
2.12.99
MetaSearch
0.3.6
processing
2.12.99
streckenlocator
1.2

Supported QGIS version

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

New profile

Additional context

No response

@Kohlroulade Kohlroulade added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jan 16, 2025
@agiudiceandrea agiudiceandrea added the PyQGIS Related to the PyQGIS API label Jan 17, 2025
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! PyQGIS Related to the PyQGIS API
Projects
None yet
Development

No branches or pull requests

2 participants