Skip to main content
Post Closed as "Needs more focus" by PolyGeo
deleted 76 characters in body; edited tags; edited title; added 5 characters in body; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

How to get the Getting file paths of the loaded layers in a QGIS plugin?

I am very new to GIS, QGIS and Python so please bear with me. I am using QGIS 2.0 and I would like to develop a QGIS plugin that would display the raster layers of the main window in order to allow for some specific interaction. I have a very hard time getting this to work! I generated the skeleton of my plugin through plugin builder, and changed the [moduleName]2dialog.py file to try to display the main window layers.

So I have two questions : 1/ Is it possible to get the layers? 2/ Can I draw it inside a GqsMapCanvas inside my plugin GUI, or do I need another object?

  1. Is it possible to get the layers?
  2. Can I draw it inside a GqsMapCanvas inside my plugin GUI, or do I need another object?

This is the code I have for now, which generates an error :

from PyQt4 import QtCore, QtGui
from qgis import core, gui, utils
from qgis.gui import QgsMapCanvasLayer

mc = iface.mapCanvas()
layers = mc.mapRenderer().layerSet()
if not layers:
    self.ui.displayFileNameTextEdit.setText("No layer to display.")
else:
    for layer in layers: #layer is one id
        self.ui.qgsMapCanvas.setExtent(layer.extent())
        self.ui.qgsMapCanvas.setLayerSet( [ QgsMapCanvasLayer(layer) ] )
        self.ui.qgsMapCanvas.refresh()

Thank you very much! I'll appreciate any idea.

How to get the file paths of the loaded layers in a QGIS plugin?

I am very new to GIS, QGIS and Python so please bear with me. I am using QGIS 2.0 and I would like to develop a QGIS plugin that would display the raster layers of the main window in order to allow for some specific interaction. I have a very hard time getting this to work! I generated the skeleton of my plugin through plugin builder, and changed the [moduleName]2dialog.py file to try to display the main window layers.

So I have two questions : 1/ Is it possible to get the layers? 2/ Can I draw it inside a GqsMapCanvas inside my plugin GUI, or do I need another object?

This is the code I have for now, which generates an error :

from PyQt4 import QtCore, QtGui
from qgis import core, gui, utils
from qgis.gui import QgsMapCanvasLayer

mc = iface.mapCanvas()
layers = mc.mapRenderer().layerSet()
if not layers:
    self.ui.displayFileNameTextEdit.setText("No layer to display.")
else:
    for layer in layers: #layer is one id
        self.ui.qgsMapCanvas.setExtent(layer.extent())
        self.ui.qgsMapCanvas.setLayerSet( [ QgsMapCanvasLayer(layer) ] )
        self.ui.qgsMapCanvas.refresh()

Thank you very much! I'll appreciate any idea.

Getting file paths of loaded layers in QGIS plugin?

I am very new to GIS, QGIS and Python. I am using QGIS 2.0 and I would like to develop a QGIS plugin that would display the raster layers of the main window in order to allow for some specific interaction. I have a very hard time getting this to work! I generated the skeleton of my plugin through plugin builder, and changed the [moduleName]2dialog.py file to try to display the main window layers.

I have two questions :

  1. Is it possible to get the layers?
  2. Can I draw it inside a GqsMapCanvas inside my plugin GUI, or do I need another object?

This is the code I have for now, which generates an error :

from PyQt4 import QtCore, QtGui
from qgis import core, gui, utils
from qgis.gui import QgsMapCanvasLayer

mc = iface.mapCanvas()
layers = mc.mapRenderer().layerSet()
if not layers:
    self.ui.displayFileNameTextEdit.setText("No layer to display.")
else:
    for layer in layers: #layer is one id
        self.ui.qgsMapCanvas.setExtent(layer.extent())
        self.ui.qgsMapCanvas.setLayerSet( [ QgsMapCanvasLayer(layer) ] )
        self.ui.qgsMapCanvas.refresh()
added 6 characters in body
Source Link
Rinita
  • 159
  • 1
  • 11

I am very new to GIS, QGIS and Python so please bear with me. I am using QGIS 2.0 and I would like to develop a QGIS plugin that would display the raster layers of the main window in order to allow for some specific interaction. I have a very hard time getting this to work! I generated the skeleton of my plugin through plugin builder, and changed the [moduleName]2dialog.py file to try to display the main window layers.

So I have two questions : 1/ Is it possible to get the layers? 2/ Can I draw it inside a GqsMapCanvas inside my plugin GUI, or do I need another object?

This is the code I have for now (generates, which generates an error)  :

from PyQt4 import QtCore, QtGui
from qgis import core, gui, utils
from qgis.gui import QgsMapCanvasLayer

mc = iface.mapCanvas()
layers = mc.mapRenderer().layerSet()
if not layers:
    self.ui.displayFileNameTextEdit.setText("No layer to display.")
else:
    for layer in layers: #layer is one id
        self.ui.qgsMapCanvas.setExtent(layer.extent())
        self.ui.qgsMapCanvas.setLayerSet( [ QgsMapCanvasLayer(layer) ] )
        self.ui.qgsMapCanvas.refresh()

Thank you very much! I'll appreciate any idea.

I am very new to GIS, QGIS and Python so please bear with me. I am using QGIS 2.0 and I would like to develop a QGIS plugin that would display the raster layers of the main window in order to allow for some specific interaction. I have a very hard time getting this to work! I generated the skeleton of my plugin through plugin builder, and changed the [moduleName]2dialog.py file to try to display the main window layers.

So I have two questions : 1/ Is it possible to get the layers? 2/ Can I draw it inside a GqsMapCanvas inside my plugin GUI, or do I need another object?

This is the code I have for now (generates an error):

from PyQt4 import QtCore, QtGui
from qgis import core, gui, utils
from qgis.gui import QgsMapCanvasLayer

mc = iface.mapCanvas()
layers = mc.mapRenderer().layerSet()
if not layers:
    self.ui.displayFileNameTextEdit.setText("No layer to display.")
else:
    for layer in layers: #layer is one id
        self.ui.qgsMapCanvas.setExtent(layer.extent())
        self.ui.qgsMapCanvas.setLayerSet( [ QgsMapCanvasLayer(layer) ] )
        self.ui.qgsMapCanvas.refresh()

Thank you very much! I'll appreciate any idea.

I am very new to GIS, QGIS and Python so please bear with me. I am using QGIS 2.0 and I would like to develop a QGIS plugin that would display the raster layers of the main window in order to allow for some specific interaction. I have a very hard time getting this to work! I generated the skeleton of my plugin through plugin builder, and changed the [moduleName]2dialog.py file to try to display the main window layers.

So I have two questions : 1/ Is it possible to get the layers? 2/ Can I draw it inside a GqsMapCanvas inside my plugin GUI, or do I need another object?

This is the code I have for now, which generates an error  :

from PyQt4 import QtCore, QtGui
from qgis import core, gui, utils
from qgis.gui import QgsMapCanvasLayer

mc = iface.mapCanvas()
layers = mc.mapRenderer().layerSet()
if not layers:
    self.ui.displayFileNameTextEdit.setText("No layer to display.")
else:
    for layer in layers: #layer is one id
        self.ui.qgsMapCanvas.setExtent(layer.extent())
        self.ui.qgsMapCanvas.setLayerSet( [ QgsMapCanvasLayer(layer) ] )
        self.ui.qgsMapCanvas.refresh()

Thank you very much! I'll appreciate any idea.

edited title
Link
underdark
  • 84.5k
  • 22
  • 233
  • 415

It is possible How to displayget the layersfile paths of the main windowloaded layers in a QGIS plugin?

Source Link
Rinita
  • 159
  • 1
  • 11
Loading