1

We can easily add the map from map canvas to print composer but is there any possible way to add vector layer directly to the print composer in QGIS either by PyQGIS script or by using some plugin or by any default feature.

  • Thanks Bera . Yes we can add layer in QGIS and later we can add in print composer.But What i am wanted is to add shape file direclty to the print composer so that we can load directly from external source not through the canvas. – Devenepali Jul 31 at 5:56
  • If I add a layer in QGIS it automatically shows up in print Composer. – BERA Jul 31 at 6:05
  • Thank again Bera. What if we wanted to add layer to the composer which is loaded in QGIS but currently not enabled(in canvas).Is there any way so that we can programatically add layer to composer even if it is not currently active. – Devenepali Jul 31 at 6:10
  • 2
    Please read up on map themes. – Erik Jul 31 at 6:39
  • 1
    Like Erik says use map themes (the eye icon of the TOC panel). It is very common to have a canvas map theme setup only for print. If the layer is available for print, it is also available for the canvas. In the print composer map item properties you can follow a map theme, even if the theme is not active in the canvas. – Jakob Jul 31 at 6:46
2

If you import your shapefile as a QgsVectorLayer through the python console, rather than an iface vector layer it will not display on the canvas. You should then be able to add the layer to the print composer.

| improve this answer | |
1

I was working on something similar last night, like Stew says if you use QgsVectorLayer rather than iface, and set the last parameter to 'False' you can add 'hidden' layers i.e. they don't appear in the TOC or mapcanvas - but they're there :

layer = QgsVectorLayer(shapepath, lyr_name, "ogr")
QgsProject.instance().addMapLayer(layer, False) # if set to true it'll appear on the mapcanvas

After if you want to check they exist:

lyr_list = QgsProject.instance().mapLayers() 
print(lyr_list)

But that only solves half your question... In map composer you can add these layers to your legend (simply by turning off the auto-update and manually adding a layer) - however I don't think that you can add a layer to the layout-map that isn't visible on the map canvas...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.