I have been working with classes, and I have fixed several mistakes related to indentation, but in this case I have been checking all the possible errors. It might be a concept error. If someone can tell me what is my mistake, it will be very helpful.
From this code, I get the error "NameError": global name 'vector' is not defined
import qgis
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface
class Varias_Funciones:
vector = QgsVectorLayer("ROUTE","Municipios","ogr")
#LA CLASE TENDRA LA CAPACIDAD DE ENTRAR EN EL INTERFAZ DE QGIS
def __init__(self, iface):
self.iface = iface
#CARGA DE LA CAPA DE MUNICIPIOS (CAPA VECTORIAL)
def capa_vectorial(self):
QgsMapLayerRegistry.instance().addMapLayer(vector)
#CARGA DE LA CAPA DE RASTER MTN50
def capa_raster(self):
raster = QgsRasterLayer("ROUTE", "MTN50")
QgsMapLayerRegistry.instance().addMapLayers([raster])
#CARGA DE SISTEMAS DE COORDEANDAS
def coordenadas(self):
crs = QgsCoordinateReferenceSystem(4258, QgsCoordinateReferenceSystem.EpsgCrsId)
vector.setCrs(crs)
#ABRIR LAS PROPIEDADES
def abrir_propiedades(self):
self.iface.showLayerProperties(vector)
comprobar_funciones = Varias_Funciones(qgis.utils.iface)
comprobar_funciones.capa_vectorial()
comprobar_funciones.capa_raster()
comprobar_funciones.coordenadas()
comprobar_funciones.abrir_propiedades()
self.vector
instead ofvector
in coordenadas() ...? – Steven Kay Apr 8 '16 at 11:50