本文整理汇总了Python中qgis.core.QgsMapLayerRegistry.instance方法的典型用法代码示例。如果您正苦于以下问题:Python QgsMapLayerRegistry.instance方法的具体用法?Python QgsMapLayerRegistry.instance怎么用?Python QgsMapLayerRegistry.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsMapLayerRegistry
的用法示例。
在下文中一共展示了QgsMapLayerRegistry.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addRefTables
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def addRefTables(self, uri, table, attr_name, tableGroup):
"""Create a datasource for a referenced layer and add it to the map layer registry."""
foreign_uri = QgsDataSourceURI()
foreign_uri.setConnection(uri.host(), uri.port(), uri.database(), uri.username(), uri.password())
foreign_uri.setDataSource(uri.schema(), table, None, "", attr_name)
new_layer = QgsVectorLayer(foreign_uri.uri(), table, "postgres")
if new_layer.isValid():
layer_exists = False
for layers in QgsMapLayerRegistry.instance().mapLayers().values():
layer_data = layers.dataProvider()
if foreign_uri.uri() == layer_data.dataSourceUri():
layer_exists = True
if not layer_exists:
QgsMapLayerRegistry.instance().addMapLayer(new_layer, False)
tableGroup.addLayer(new_layer)
return new_layer
else:
return False
示例2: testRoundTripPoints
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def testRoundTripPoints():
projectFile = os.path.join(os.path.dirname(__file__), "data", "testpoints.qgs")
iface.addProject(projectFile)
layerA = processing.getObject("points")
folder = tempfile.mkdtemp()
styles = mapboxgl.projectToMapbox(folder)
layerA2 =dataobjects.load(layerA.source(), "points2")
mapboxgl.setLayerSymbologyFromMapboxStyle(layerA2, styles["layers"][0])
mapboxgl.setLayerLabelingFromMapboxStyle(layerA2, styles["layers"][1])
layerB2 =dataobjects.load(layerA.source(), "pointsb2")
mapboxgl.setLayerSymbologyFromMapboxStyle(layerB2, styles["layers"][2])
shutil.rmtree(folder, ignore_errors=True)
'''
QgsMapLayerRegistry.instance().removeMapLayer(layerA)
layerB = processing.getObject("pointsb")
QgsMapLayerRegistry.instance().removeMapLayer(layerB)
stylesB = mapboxgl.projectToMapbox("d:\\mapbox")
self.assertEqual(styles, stylesB)
'''
示例3: __init__
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = abc_main_ui.Ui_Dialog()
self.ui.setupUi(self)
# Button's handlers
self.connect(self.ui.runButton, QtCore.SIGNAL("clicked()"), self.run)
self.connect(self.ui.cancelButton, QtCore.SIGNAL("clicked()"), self.cancel)
self.connect(self.ui.addFieldButton, QtCore.SIGNAL("clicked()"), self.addField)
self.connect(self.ui.deleteSelectedButton, QtCore.SIGNAL("clicked()"), self.deleteSelectedFields)
self.connect(self.ui.deleteAllButton, QtCore.SIGNAL("clicked()"), self.deleteAllFields)
self.connect(self.ui.vectorLayerComboBox, QtCore.SIGNAL("currentIndexChanged(const QString&)"), self.layerChanged)
self.activateInterface()
# Fill vector layers combobox
vectorLayers = [layer.name() for layer in QgsMapLayerRegistry.instance().mapLayers().values() if
(layer.type() == QgsMapLayer.VectorLayer)]
self.ui.vectorLayerComboBox.addItems(vectorLayers)
### INTERFACE MANIPULATIONS
示例4: __init__
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def __init__(self, iface):
"""Constructor.
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'GeometryWrapper_{}.qm'.format(locale))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&Geometry Wrapper')
# TODO: We are going to let the user set this up in a future iteration
self.toolbar = self.iface.addToolBar(u'GeometryWrapper')
self.toolbar.setObjectName(u'GeometryWrapper')
# listen for browse button
self.dlg = GeometryWrapperDialog()
self.dlg.inButton.clicked.connect(self.setInDataset)
# noinspection PyMethodMayBeStatic
示例5: __init__
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry 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
QgsMapLayerRegistry.instance().layersAdded.connect(self.addLayers)
# noinspection PyArgumentList
QgsMapLayerRegistry.instance().layerWasAdded.connect(self.addLayer)
# noinspection PyArgumentList
QgsMapLayerRegistry.instance().removeAll.connect(self.removeAllLayers)
# For processing module
self.destCrs = None
示例6: __init__
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def __init__(self, canvas):
"""
Constructor.
:param canvas: Map canvas.
:type canvas: QgsMapCanvas
"""
QObject.__init__(self)
self.canvas = canvas
# set up slots to mimic the behaviour of QGIS
QgsMapLayerRegistry.instance().layersAdded.connect(self.addLayers)
QgsMapLayerRegistry.instance().layerWasAdded.connect(self.addLayer)
QgsMapLayerRegistry.instance().removeAll.connect(self.removeAllLayers)
# for processing module
self.destCrs = None
示例7: addAutoFieldToAutoFieldsTable
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def addAutoFieldToAutoFieldsTable( self, autoFieldId, autoField ):
""" Add a whole row to the AutoFields table """
row = self.tblAutoFields.rowCount()
self.tblAutoFields.insertRow( row )
name = autoField['layer']
if 'layerId' in autoField:
lyr = QgsMapLayerRegistry.instance().mapLayer( autoField['layerId'] )
name = lyr.name()
item = QTableWidgetItem( name )
item.setData( Qt.UserRole, autoFieldId )
item.setData( Qt.ToolTipRole, autoField['layer'] )
self.tblAutoFields.setItem( row, 0, item )
item = QTableWidgetItem( autoField['field'] )
self.tblAutoFields.setItem( row, 1, item )
item = QTableWidgetItem( autoField['expression'] )
self.tblAutoFields.setItem( row, 2, item )
item = QTableWidgetItem( QApplication.translate( "ExportAutoFields",
"Enabled" ) if autoField['enabled'] else QApplication.translate( "ExportAutoFields", "Disabled" ) )
self.tblAutoFields.setItem( row, 3, item )
示例8: __init__
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def __init__( self, parent, autoFieldManager, messageManager, listAutoFields, filePath, bCalculateOnExisting ):
QDialog.__init__( self, parent )
self.setupUi( self )
self.setModal( True )
self.parent = parent
self.autoFieldManager = autoFieldManager
self.messageManager = messageManager
self.listAutoFields = listAutoFields
self.filePath = filePath
self.bCalculateOnExisting = bCalculateOnExisting
self.listCandidates = self.getCandidates( listAutoFields )
self.layers = []
layers = QgsMapLayerRegistry.instance().mapLayers().values()
for layer in layers:
if layer.type() == QgsMapLayer.VectorLayer:
if layer.dataProvider().capabilities() & QgsVectorDataProvider.AddFeatures:
self.layers.append( layer )
self.tblAutoFields.setColumnWidth( 0, 120 )
self.tblAutoFields.setColumnWidth( 3, 80 )
self.tblAutoFields.setColumnWidth( 4, 150 )
self.tblAutoFields.setColumnWidth( 5, 120 )
self.populateAutoFieldsTable()
示例9: removeAutoField
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def removeAutoField( self, autoFieldId ):
""" Get rid of AutoField from both QSettings and dictAutoFields """
if not autoFieldId in self.dictAutoFields:
self.msg.show( QApplication.translate( "AutoFieldManager",
"[Warning] AutoField with Id " ) + autoFieldId + \
QApplication.translate( "AutoFieldManager",
" was not found, so it couldn't be removed." ), 'warning' )
return False
self.settings.beginGroup( self.settingsPrefix + "/data" )
self.settings.remove( autoFieldId )
self.settings.endGroup()
self.settings.sync()
# Disconnect SIGNAL/SLOTS for this AutoField
if 'layerId' in self.dictAutoFields[autoFieldId]:
if self.dictAutoFields[autoFieldId]['enabled']:
layer = QgsMapLayerRegistry.instance().mapLayer( self.dictAutoFields[autoFieldId]['layerId'] )
self.eventManager.removeEventsForAutoField( autoFieldId, layer, self.dictAutoFields[autoFieldId]['expression'] )
del self.dictAutoFields[autoFieldId]
self.autoFieldRemoved.emit( autoFieldId )
示例10: validateAutoField
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def validateAutoField( self, dictProperties ):
""" Check whether this AutoField is ready or if there is something missing """
if not 'layerId' in dictProperties:
self.msg.show( "[Warning] A layer that is part of an AutoField was not found in QGIS registry.", 'warning', True )
return False
layer = QgsMapLayerRegistry.instance().mapLayer( dictProperties['layerId'] )
if not layer:
self.msg.show( "[Warning] Layer id " + dictProperties['layerId'] + " was not found in QGIS registry.", 'warning', True )
return False
if layer.fieldNameIndex( dictProperties['field'] ) == -1:
self.msg.show( "[Warning] Field was not found in layer "+layer.name()+".", 'warning', True )
return False
# TODO add checks for layer2 and field2
return True
示例11: checkAndDisableAutoFieldsForLayer
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def checkAndDisableAutoFieldsForLayer( self, layerId ):
""" After a notification on fields being removed, check and disable AutoFields if needed.
1. Check if any field is missing in AutoFields set for this layer.
2. Disable it in Dict
3. Disable it in QSettings
4. Disconnect its SIGNAL / SLOTS
"""
for autoFieldId in self.dictAutoFields:
if self.dictAutoFields[autoFieldId]['enabled'] == True: # Don't check disabled AutoFields
if layerId == self.dictAutoFields[autoFieldId]['layerId']:
layer = QgsMapLayerRegistry.instance().mapLayer( layerId )
if layer.fieldNameIndex( self.dictAutoFields[autoFieldId]['field'] ) == -1: #1
self.dictAutoFields[autoFieldId]['enabled'] = False #2
self.writeAutoField( autoFieldId, self.dictAutoFields[autoFieldId] ) #3
self.eventManager.removeEventsForAutoField( autoFieldId, layer, self.dictAutoFields[autoFieldId]['expression'] ) #4
self.autoFieldDisabled.emit( autoFieldId )
示例12: from_file
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def from_file(cls, filename, canvas, relative_base=None):
"""
Load a project file from a path.
:param filename: The path to the project file.
:param canvas: (optional) Passing a canvas will auto add layers to the canvas when the load is
loaded.
:param relative_base_path: (optional) Relative base path for the project file to load layers from
:return: A Project object which wraps QgsProject.instance()
"""
QgsProject.instance().clear()
bridge = None
if canvas:
bridge = QgsLayerTreeMapCanvasBridge(QgsProject.instance().layerTreeRoot(), canvas)
if relative_base is None:
relative_base = os.path.dirname(filename)
QDir.setCurrent(relative_base)
QgsProject.instance().read(QFileInfo(filename))
if bridge:
bridge.setCanvasLayers()
return cls(bridge)
示例13: __init__
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def __init__(self, iface):
self.iface = iface
config.iface = iface
readSettings()
config.initConfigParams()
layers = list(QgsMapLayerRegistry.instance().mapLayers().values())
for layer in layers:
trackLayer(layer)
try:
from qgistester.tests import addTestModule
from geogig.tests import testplugin
addTestModule(testplugin, "GeoGig Light")
except Exception as e:
pass
QSettings().setValue("/qgis/walForSqlite3", False)
示例14: newProject
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def newProject(self):
"""Creates a new project."""
QgsMapLayerRegistry.instance().removeAllMapLayers()
# ---------------- API Mock for QgsInterface follows -------------------
示例15: functionalTests
# 需要导入模块: from qgis.core import QgsMapLayerRegistry [as 别名]
# 或者: from qgis.core.QgsMapLayerRegistry import instance [as 别名]
def functionalTests():
try:
from qgistester.test import Test
except:
return []
def _loadLayer():
layerfile = os.path.join(os.path.dirname(__file__), "w3w.shp")
layer = loadLayer(layerfile, provider="ogr")
QgsMapLayerRegistry.instance().addMapLayer(layer)
def _setTool():
plugins["what3words"].setTool()
def _zoomTo():
plugins["what3words"].zoomTo()
w3wTest = Test("Test w3w")
w3wTest.addStep("Load layer", _loadLayer)
w3wTest.addStep("Select map tool", _setTool)
w3wTest.addStep("Click within the layer polygon and verify that the computed 3 coords are 'healings.distorting.harsher'", isVerifyStep=True)
w3wTest.addStep("Move map canvas", lambda: iface.mapCanvas().setCenter(QgsPoint(0, 0)))
w3wTest.addStep("Open panel", _zoomTo)
w3wTest.addStep("Enter 'healings.distorting.harsher' and click on 'zoom to'. Verify it zooms to the polygon layer")
w3wTest.addStep("Click on 'remove marker' and verify it removes the marker")
return [w3wTest]