[QGIS-Developer] saving a layer with the world_map.shp

Raymond Nijssen r.nijssen at terglobo.nl
Mon May 27 06:58:35 PDT 2019


I know it was introduced as an easter egg, but I'm very happy with the 
built in world map in qgis. I'm using it in a plugin to automatically 
add a layer for the overview map in my layout. This layer points to a 
shapefile in my qgis install directory:

/home/raymond/programs/qgis-master/share/qgis/resources/data/world_map.shp

Now, when saving my project and somebody else opening it, the layer is 
invalid (of course). Is there a way to make the project point to the 
right file, using some kind of variable pointing to the qgis 
installation path?

like this:
{QGIS_RESOURCE_PATH}/data/world_map.shp

or I could copy the world.shp into my plugin and do this:

{QGIS_PLUGIN_PATH}/my-plugin/data/world_map.shp

These paths should then be saved including the variable in the project file.



Another option would be to save the shp-file in the .qgz somehow but I'm 
not too sure if that is the way to go..



This is the way I create the path now:

worldShp = os.path.join(QgsApplication.pkgDataPath(), 'resources', 
'data', 'world_map.shp')



To make the question more general, is it possible to add resources to a 
plugin in a way that projects point to these resources and make that 
work for other users too?


Hope anyone can help!

Kind regards,
Raymond




More information about the QGIS-Developer mailing list