本文整理匯總了Python中qgis.core.QgsProject.instance方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsProject.instance方法的具體用法?Python QgsProject.instance怎麽用?Python QgsProject.instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qgis.core.QgsProject
的用法示例。
在下文中一共展示了QgsProject.instance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cargar_mapa_raster
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def cargar_mapa_raster (self,pathMapaRaster):
retornoCargaLayerMapaRaster = False
pathMapaRaster = pathMapaRaster.strip ()
if (os.path.exists (pathMapaRaster)):
baseNameMapaRaster = os.path.basename (pathMapaRaster)
baseNameMapaRaster = os.path.splitext(baseNameMapaRaster)[0]
layerMapaRaster = QgsRasterLayer (pathMapaRaster, baseNameMapaRaster)
QgsProject.instance ().addMapLayer (layerMapaRaster)
retornoCargaLayerMapaRaster = layerMapaRaster.isValid()
return retornoCargaLayerMapaRaster
示例2: __init__
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def __init__(self, canvas):
"""Constructor
:param canvas:
"""
QObject.__init__(self)
self.canvas = canvas
# Set up slots so we can mimic the behaviour of QGIS when layers
# are added.
LOGGER.debug('Initialising canvas...')
# noinspection PyArgumentList
QgsProject.instance().layersAdded.connect(self.addLayers)
# noinspection PyArgumentList
QgsProject.instance().layerWasAdded.connect(self.addLayer)
# noinspection PyArgumentList
QgsProject.instance().removeAll.connect(self.removeAllLayers)
# For processing module
self.destCrs = None
示例3: __init__
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def __init__(self, layer, canvas, parent):
super(MapLayerConfigWidget, self).__init__(layer, canvas, parent)
self.setupUi(self)
self.layer_source = LayerSource(layer)
self.project = QgsProject.instance()
set_available_actions(self.layerActionComboBox, self.layer_source)
self.isGeometryLockedCheckBox.setEnabled(self.layer_source.can_lock_geometry)
self.isGeometryLockedCheckBox.setChecked(self.layer_source.is_geometry_locked)
self.photoNamingTable = PhotoNamingTableWidget()
self.photoNamingTable.addLayerFields(self.layer_source)
self.photoNamingTable.setLayerColumnHidden(True)
# insert the table as a second row only for vector layers
if Qgis.QGIS_VERSION_INT >= 31300 and layer.type() == QgsMapLayer.VectorLayer:
self.layout().insertRow(1, self.tr('Photo Naming'), self.photoNamingTable)
self.photoNamingTable.setEnabled(self.photoNamingTable.rowCount() > 0)
示例4: __init__
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def __init__(self, canvas: QgsMapCanvas):
"""Constructor
:param canvas:
"""
QObject.__init__(self)
self.canvas = canvas
# Set up slots so we can mimic the behaviour of QGIS when layers
# are added.
LOGGER.debug('Initialising canvas...')
# noinspection PyArgumentList
QgsProject.instance().layersAdded.connect(self.addLayers)
# noinspection PyArgumentList
QgsProject.instance().layerWasAdded.connect(self.addLayer)
# noinspection PyArgumentList
QgsProject.instance().removeAll.connect(self.removeAllLayers)
# For processing module
self.destCrs = None
self.message_bar = QgsMessageBar()
示例5: __init__
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def __init__(self, iface, parent):
'''Initialize the LayerSearch dialog box'''
super(LayerSearchDialog, self).__init__(parent)
self.setupUi(self)
self.iface = iface
self.canvas = iface.mapCanvas()
# Notify us when vector items ared added and removed in QGIS
QgsProject.instance().layersAdded.connect(self.updateLayers)
QgsProject.instance().layersRemoved.connect(self.updateLayers)
self.doneButton.clicked.connect(self.closeDialog)
self.stopButton.clicked.connect(self.killWorker)
self.searchButton.clicked.connect(self.runSearch)
self.clearButton.clicked.connect(self.clearResults)
self.layerListComboBox.activated.connect(self.layerSelected)
self.searchFieldComboBox.addItems(['<All Fields>'])
self.maxResults = 1500
self.resultsTable.setColumnCount(4)
self.resultsTable.setSortingEnabled(False)
self.resultsTable.setHorizontalHeaderLabels(['Value','Layer','Field','Feature Id'])
self.resultsTable.setSelectionBehavior(QAbstractItemView.SelectRows)
self.comparisonComboBox.addItems(['=','contains','begins with'])
self.resultsTable.itemSelectionChanged.connect(self.select_feature)
self.worker = None
示例6: select_feature
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def select_feature(self):
'''A feature has been selected from the list so we need to select
and zoom to it'''
if self.noSelection:
# We do not want this event while data is being changed
return
# Deselect all selections
layers = QgsProject.instance().mapLayers().values()
for layer in layers:
if layer.type() == QgsMapLayer.VectorLayer:
layer.removeSelection()
# Find the layer that was selected and select the feature in the layer
selectedRow = self.resultsTable.currentRow()
selectedLayer = self.results[selectedRow][0]
selectedFeature = self.results[selectedRow][1]
selectedLayer.select(selectedFeature.id())
# Zoom to the selected feature
self.canvas.zoomToSelected(selectedLayer)
示例7: populateLayerListComboBox
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def populateLayerListComboBox(self):
'''Find all the vector layers and add them to the layer list
that the user can select. In addition the user can search on all
layers or all selected layers.'''
layerlist = ['<All Layers>','<Selected Layers>']
self.searchLayers = [None, None] # This is same size as layerlist
layers = QgsProject.instance().mapLayers().values()
for layer in layers:
if layer.type() == QgsMapLayer.VectorLayer:
layerlist.append(layer.name())
self.searchLayers.append(layer)
self.layerListComboBox.clear()
self.layerListComboBox.addItems(layerlist)
self.initFieldList()
示例8: update_ee_image_layer
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def update_ee_image_layer(image, layer, shown=True, opacity=1.0):
check_version()
url = "type=xyz&url=" + get_ee_image_url(image)
provider = layer.dataProvider()
msg = 'Updating layer with provider %s' % (type(provider).__name__, )
QgsMessageLog.logMessage(msg, 'Earth Engine')
provider.setDataSourceUri(url)
provider.reloadData()
layer.triggerRepaint()
layer.reload()
iface.mapCanvas().refresh()
item = QgsProject.instance().layerTreeRoot().findLayer(layer.id())
if not (shown is None):
item.setItemVisibilityChecked(shown)
示例9: updateLayers
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def updateLayers(self):
layers = QgsProject.instance().mapLayers().values()
for l in filter(lambda layer: layer.customProperty('ee-layer'), layers):
ee_object = l.customProperty('ee-object')
ee_object_vis = l.customProperty('ee-object-vis')
ee_object = ee.deserializer.fromJSON(ee_object)
ee_object_vis = json.loads(ee_object_vis)
# update loaded EE layer
# get existing values for name, visibility, and opacity
# TODO: this should not be needed, refactor add_or_update_ee_layer to update_ee_layer
name = l.name()
shown = QgsProject.instance().layerTreeRoot().findLayer(l.id()).itemVisibilityChecked()
opacity = l.renderer().opacity()
utils.add_or_update_ee_layer(ee_object, ee_object_vis, name, shown, opacity)
示例10: canvasPressEvent
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def canvasPressEvent(self, event):
"""Capture the coordinate when the mouse button has been released."""
pt = self.snappoint(event.originalPixelPoint())
self.removeVertexMarker()
if self.azDigitizerDialog is None:
from .azDigitizer import AzDigitizerWidget
self.azDigitizerDialog = AzDigitizerWidget(self.iface, self.iface.mainWindow())
layer = self.iface.activeLayer()
if layer is None or layer.wkbType() != QgsWkbTypes.Point:
self.azDigitizerDialog.includeStartLabel.setEnabled(False)
self.azDigitizerDialog.checkBox.setEnabled(False)
else:
self.azDigitizerDialog.includeStartLabel.setEnabled(True)
self.azDigitizerDialog.checkBox.setEnabled(True)
try:
canvasCRS = self.canvas.mapSettings().destinationCrs()
transform = QgsCoordinateTransform(canvasCRS, epsg4326, QgsProject.instance())
pt4326 = transform.transform(pt.x(), pt.y())
self.azDigitizerDialog.setPoint(pt4326)
self.azDigitizerDialog.show()
except Exception:
self.iface.messageBar().pushMessage("", tr("Clicked location is invalid"), level=Qgis.Warning, duration=4)
示例11: canvasPressEvent
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def canvasPressEvent(self, event):
'''Capture the coordinate when the mouse button has been released.'''
pt = self.snappoint(event.originalPixelPoint())
self.removeVertexMarker()
layer = self.iface.activeLayer()
if layer is None:
return
if self.lineDigitizerDialog is None:
from .lineDigitizer import LineDigitizerWidget
self.lineDigitizerDialog = LineDigitizerWidget(self.iface, self.iface.mainWindow())
if layer.geometryType() == QgsWkbTypes.LineGeometry:
self.lineDigitizerDialog.closeLineCheckBox.setEnabled(True)
else:
self.lineDigitizerDialog.closeLineCheckBox.setEnabled(False)
try:
canvasCRS = self.canvas.mapSettings().destinationCrs()
transform = QgsCoordinateTransform(canvasCRS, epsg4326, QgsProject.instance())
pt4326 = transform.transform(pt.x(), pt.y())
self.lineDigitizerDialog.setPoint(pt4326)
self.lineDigitizerDialog.valuesTextEdit.clear()
self.lineDigitizerDialog.show()
except Exception:
self.iface.messageBar().pushMessage("", tr("Clicked location is invalid"), level=Qgis.Warning, duration=4)
示例12: __init__
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def __init__(self, parameterDict={}, blackList=None, parent=None):
"""Constructor."""
super(SnapWithLayerChooserWidget, self).__init__(parent=parent)
self.parent = parent
self.setupUi(self)
self.project = QgsProject.instance()
self.validKeys = ['layer', 'layerName', 'snap']
self.snapDoubleSpinBox.setDecimals(20)
self.snapDoubleSpinBox.setMaximum(1000000)
self.snapDoubleSpinBox.setMinimum(0.00000000000000001)
self.layerComboBox.setFilters(
QgsMapLayerProxyModel.HasGeometry |
QgsMapLayerProxyModel.VectorLayer
)
if blackList is not None:
self.layerComboBox.setExceptedLayerList(blackList)
if parameterDict != {}:
self.populateInterface(parameterDict)
示例13: zoomToLayer
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def zoomToLayer(self, layer, zoom = None):
box = layer.boundingBoxOfSelected()
if zoom is not None:
box.grow(100-zoom)
# Defining the crs from src and destiny
epsg = self.iface.mapCanvas().mapSettings().destinationCrs().authid()
crsDest = QgsCoordinateReferenceSystem(epsg)
#getting srid from something like 'EPSG:31983'
if not layer:
layer = self.iface.mapCanvas().currentLayer()
srid = layer.crs().authid()
crsSrc = QgsCoordinateReferenceSystem(srid) #here we have to put authid, not srid
# Creating a transformer
coordinateTransformer = QgsCoordinateTransform(crsSrc, crsDest, QgsProject.instance())
newBox = coordinateTransformer.transform(box)
self.iface.mapCanvas().setExtent(newBox)
self.iface.mapCanvas().refresh()
示例14: source_fields_update
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def source_fields_update(self):
source_layer = QgsProject.instance().mapLayersByName(self.layer_name)[0]
source_layer_fields = list(source_layer.dataProvider().fields())
source_layer_fields_labels = [""]
for f in source_layer_fields:
# if f.type() == QVariant.Int or f.type() == QVariant.Double:
source_layer_fields_labels.append(str(f.name()))
for comboBox in self.all_emission_comboBoxes:
comboBox.clear()
comboBox.setEnabled(False)
comboBox.setLayer(source_layer)
comboBox.setFilters(QgsFieldProxyModel.Double | QgsFieldProxyModel.Int | QgsFieldProxyModel.Numeric)
# for label in source_layer_fields_labels:
# comboBox.addItem(label)
示例15: source_fields_update
# 需要導入模塊: from qgis.core import QgsProject [as 別名]
# 或者: from qgis.core.QgsProject import instance [as 別名]
def source_fields_update(self):
source_layer = QgsProject.instance().mapLayersByName(self.layer_name)[0]
source_layer_fields = list(source_layer.dataProvider().fields())
source_layer_fields_labels = [""]
for f in source_layer_fields:
# if f.type() == QVariant.Int or f.type() == QVariant.Double:
source_layer_fields_labels.append(str(f.name()))
for comboBox in self.all_emission_comboBoxes:
comboBox.clear()
comboBox.setEnabled(False)
comboBox.setLayer(source_layer)
#load only fields type according to the required input
for comboBox in self.decimal_comboBoxes:
comboBox.setFilters(QgsFieldProxyModel.Numeric | QgsFieldProxyModel.Double | QgsFieldProxyModel.Int)
for comboBox in self.int_comboBoxes:
comboBox.setFilters(QgsFieldProxyModel.Numeric | QgsFieldProxyModel.Double | QgsFieldProxyModel.Int)
for comboBox in self.string_comboBoxes:
comboBox.setFilters(QgsFieldProxyModel.String)