当前位置: 首页>>代码示例>>Python>>正文


Python gui.QgsMapCanvas类代码示例

本文整理汇总了Python中qgis.gui.QgsMapCanvas的典型用法代码示例。如果您正苦于以下问题:Python QgsMapCanvas类的具体用法?Python QgsMapCanvas怎么用?Python QgsMapCanvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QgsMapCanvas类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: qgis_app

def qgis_app():
    """
    Start QGIS application to test against. Based on code from Inasafe plugin.
    :return: Reference to QGIS application, canvas and parent widget.
    :rtype:(QgsApplication, QWidget, QgsMapCanvas)
    """
    global QGIS_APP

    if QGIS_APP is None:
        gui_flag = True

        QCoreApplication.setOrganizationName('QGIS')
        QCoreApplication.setOrganizationDomain('qgis.org')
        QCoreApplication.setApplicationName('STDM_Testing')

        QGIS_APP = QgsApplication(sys.argv, gui_flag)
        QGIS_APP.initQgis()

    global PARENT
    if PARENT is None:
        PARENT = QWidget()

    global CANVAS
    if CANVAS is None:
        CANVAS = QgsMapCanvas(PARENT)
        CANVAS.resize(QSize(400, 400))

    return QGIS_APP, CANVAS, PARENT
开发者ID:gltn,项目名称:stdm,代码行数:28,代码来源:utils.py

示例2: getTestApp

def getTestApp():
    """
    Start one QGis application to test agaist.
    If QGis is already running the handle to that app will be returned
    """

    global QGISAPP  # pylint: disable=W0603

    if QGISAPP is None:
        myGuiFlag = True  # All test will run qgis in safe_qgis mode
        QGISAPP = QgsApplication(sys.argv, myGuiFlag)
        QGISAPP.initQgis()
        # print QGISAPP.showSettings()

    global PARENT  # pylint: disable=W0603
    if PARENT is None:
        PARENT = QtGui.QWidget()

    global CANVAS  # pylint: disable=W0603
    if CANVAS is None:
        CANVAS = QgsMapCanvas(PARENT)
        CANVAS.resize(QtCore.QSize(400, 400))

    global IFACE  # pylint: disable=W0603
    if IFACE is None:
        # QgisInterface is a stub implementation of the QGIS plugin interface
        IFACE = QgisInterface(CANVAS)

    return QGISAPP, CANVAS, IFACE, PARENT
开发者ID:gem,项目名称:oq-eqcatalogue-tool,代码行数:29,代码来源:app.py

示例3: get_iface

def get_iface():
    """
    Will return a mock QgisInterface object with some methods implemented in a generic way.

    You can further control its behavior
    by using the mock infrastructure. Refer to https://docs.python.org/3/library/unittest.mock.html
    for more details.

        Returns
        -------
        QgisInterface

        A mock QgisInterface
    """

    start_app()

    my_iface = mock.Mock(spec=QgisInterface)

    my_iface.mainWindow.return_value = QMainWindow()

    canvas = QgsMapCanvas(my_iface.mainWindow())
    canvas.resize(QSize(400, 400))

    my_iface.mapCanvas.return_value = canvas

    return my_iface
开发者ID:HeatherHillers,项目名称:QGIS,代码行数:27,代码来源:mocked.py

示例4: testGettersSetters

    def testGettersSetters(self):
        canvas = QgsMapCanvas()

        # should be disabled by default
        self.assertFalse(canvas.previewJobsEnabled())
        canvas.setPreviewJobsEnabled(True)
        self.assertTrue(canvas.previewJobsEnabled())
开发者ID:dmarteau,项目名称:QGIS,代码行数:7,代码来源:test_qgsmapcanvas.py

示例5: get_qgis_app

def get_qgis_app():
    """ Start one QGIS application to test against.

    :returns: Handle to QGIS app, canvas, iface and parent. If there are any
        errors the tuple members will be returned as None.
    :rtype: (QgsApplication, CANVAS, IFACE, PARENT)

    If QGIS is already running the handle to that app will be returned.
    """
    global QGIS_APP, PARENT, IFACE, CANVAS  # pylint: disable=W0603

    if iface:
        from qgis.core import QgsApplication
        QGIS_APP = QgsApplication
        CANVAS = iface.mapCanvas()
        PARENT = iface.mainWindow()
        IFACE = iface
        return QGIS_APP, CANVAS, IFACE, PARENT

    try:
        from PyQt4 import QtGui, QtCore
        from qgis.core import QgsApplication
        from qgis.gui import QgsMapCanvas

    except ImportError:
        return None, None, None, None

    global QGIS_APP  # pylint: disable=W0603

    if QGIS_APP is None:
        gui_flag = True  # All test will run qgis in gui mode
        # noinspection PyPep8Naming
        QGIS_APP = QgsApplication(sys.argv, gui_flag)
        # Make sure QGIS_PREFIX_PATH is set in your env if needed!
        QGIS_APP.initQgis()
        s = QGIS_APP.showSettings()
        LOGGER.debug(s)

    global PARENT  # pylint: disable=W0603
    if PARENT is None:
        # noinspection PyPep8Naming
        PARENT = QtGui.QWidget()

    global CANVAS  # pylint: disable=W0603
    if CANVAS is None:
        # noinspection PyPep8Naming
        CANVAS = QgsMapCanvas(PARENT)
        CANVAS.resize(QtCore.QSize(400, 400))

    global IFACE  # pylint: disable=W0603
    if IFACE is None:
        # QgisInterface is a stub implementation of the QGIS plugin interface
        # noinspection PyPep8Naming
        # IFACE = QgisInterface(CANVAS)
        IFACE = None

    return QGIS_APP, CANVAS, IFACE, PARENT
开发者ID:Samweli,项目名称:isochrones,代码行数:57,代码来源:utilities.py

示例6: getQgisTestApp

def getQgisTestApp():
    """ Start one QGis application to test agaist

    Input
        NIL

    Output
        handle to qgis app


    If QGis is already running the handle to that app will be returned
    """

    global QGISAPP  # pylint: disable=W0603

    if QGISAPP is None:
        myGuiFlag = True  # All test will run qgis in gui mode
        QGISAPP = QgsApplication(sys.argv, myGuiFlag)
        if 'QGIS_PREFIX_PATH' in os.environ:
            myPath = os.environ['QGIS_PREFIX_PATH']
            myUseDefaultPathFlag = True
            QGISAPP.setPrefixPath(myPath, myUseDefaultPathFlag)

        if sys.platform.startswith('darwin'):
            # override resource paths, otherwise looks for Resources in app
            if 'QGIS_MAC_PKGDATA_DIR' in os.environ:
                myPkgPath = os.environ['QGIS_MAC_PKGDATA_DIR']
                QGISAPP.setPkgDataPath(myPkgPath)
            if 'QGIS_MAC_SVG_DIR'  in os.environ:
                mySVGPath = os.environ['QGIS_MAC_SVG_DIR']
                mySVGPaths = QGISAPP.svgPaths()
                # doesn't get rid of incorrect path, just adds correct one
                mySVGPaths.prepend(mySVGPath)
                QGISAPP.setDefaultSvgPaths(mySVGPaths)

        QGISAPP.initQgis()
        s = QGISAPP.showSettings()
        print s

    global PARENT  # pylint: disable=W0603
    if PARENT is None:
        PARENT = QtGui.QWidget()

    global CANVAS  # pylint: disable=W0603
    if CANVAS is None:
        CANVAS = QgsMapCanvas(PARENT)
        CANVAS.resize(QtCore.QSize(400, 400))

    global IFACE  # pylint: disable=W0603
    if IFACE is None:
        # QgisInterface is a stub implementation of the QGIS plugin interface
        IFACE = QgisInterface(CANVAS)

    return QGISAPP, CANVAS, IFACE, PARENT
开发者ID:namhh,项目名称:Quantum-GIS,代码行数:54,代码来源:utilities.py

示例7: __init__

	def __init__(self, parent=None):
		QgsMapCanvas.__init__(self, parent)
		self.setCanvasColor(QColor(255,255,255))

		# reuse settings from QGIS
		settings = QSettings()
		self.enableAntiAliasing( settings.value( "/qgis/enable_anti_aliasing", QVariant(False) ).toBool() )
		self.useImageToRender( settings.value( "/qgis/use_qimage_to_render", QVariant(False) ).toBool() )
		action = settings.value( "/qgis/wheel_action", QVariant(0) ).toInt()[0]
		zoomFactor = settings.value( "/qgis/zoom_factor", QVariant(2) ).toDouble()[0]
		self.setWheelAction( QgsMapCanvas.WheelAction(action), zoomFactor )

		self._clear()
开发者ID:netconstructor,项目名称:db_manager,代码行数:13,代码来源:layer_preview.py

示例8: __init__

    def __init__(self, parent=None):
        QgsMapCanvas.__init__(self, parent)
        self.parent = parent
        self.setCanvasColor(QColor(255, 255, 255))

        self.item = None
        self.dirty = False
        self.currentLayer = None

        # reuse settings from QGIS
        settings = QgsSettings()
        self.enableAntiAliasing(settings.value("/qgis/enable_anti_aliasing", False, type=bool))
        zoomFactor = settings.value("/qgis/zoom_factor", 2, type=float)
        self.setWheelFactor(zoomFactor)
开发者ID:cayetanobv,项目名称:QGIS,代码行数:14,代码来源:layer_preview.py

示例9: testVisibility

    def testVisibility(self):
        """ test that map canvas annotation item visibility follows layer"""
        a = QgsTextAnnotation()
        canvas = QgsMapCanvas()
        i = QgsMapCanvasAnnotationItem(a, canvas)

        self.assertTrue(i.isVisible())

        layer = QgsVectorLayer("Point?crs=EPSG:3111&field=fldtxt:string",
                               'test', "memory")
        a.setMapLayer(layer)
        self.assertFalse(i.isVisible())
        canvas.setLayers([layer])
        self.assertTrue(i.isVisible())
开发者ID:m-kuhn,项目名称:QGIS,代码行数:14,代码来源:test_qgsmapcanvasannotationitem.py

示例10: get_qgis_app

def get_qgis_app():
    """ Start one QGis application to test against

    Input
        NIL

    Output
        handle to qgis app


    If QGis is already running the handle to that app will be returned
    """

    global QGIS_APP  # pylint: disable=W0603

    if QGIS_APP is None:
        gui_flag = True  # All test will run qgis in safe_qgis mode
        # noinspection PyPep8Naming
        QGIS_APP = QgsApplication(sys.argv, gui_flag)

        # Note: This block is not needed for  QGIS > 1.8 which will
        # automatically check the QGIS_PREFIX_PATH var so it is here
        # for backwards compatibility only
        if "QGIS_PREFIX_PATH" in os.environ:
            path = os.environ["QGIS_PREFIX_PATH"]
            use_default_path_flag = True
            QGIS_APP.setPrefixPath(path, use_default_path_flag)

        QGIS_APP.initQgis()
        s = QGIS_APP.showSettings()
        LOGGER.debug(s)

    global PARENT  # pylint: disable=W0603
    if PARENT is None:
        # noinspection PyPep8Naming
        PARENT = QtGui.QWidget()

    global CANVAS  # pylint: disable=W0603
    if CANVAS is None:
        # noinspection PyPep8Naming
        CANVAS = QgsMapCanvas(PARENT)
        CANVAS.resize(QtCore.QSize(400, 400))

    global IFACE  # pylint: disable=W0603
    if IFACE is None:
        # QgisInterface is a stub implementation of the QGIS plugin interface
        # noinspection PyPep8Naming
        IFACE = QgisInterface(CANVAS)

    return QGIS_APP, CANVAS, IFACE, PARENT
开发者ID:vdeparday,项目名称:inasafe,代码行数:50,代码来源:utilities_for_testing.py

示例11: get_qgis_app

def get_qgis_app():
    """Start one QGIS application to test against.

    This method has been copied from PluginBuilder generated code by Gary
    Sherman: https://github.com/g-sherman/Qgis-Plugin-Builder

    :returns: Handle to QGIS app, canvas, iface and parent. If there are any
        errors the tuple members will be returned as None.
    :rtype: (QgsApplication, CANVAS, IFACE, PARENT)

    If QGIS is already running the handle to that app will be returned.
    """
    try:
        from PyQt4 import QtGui, QtCore
        from qgis.core import QgsApplication
        from qgis.gui import QgsMapCanvas
        from qgis_interface import QgisInterface
    except ImportError:
        return None, None, None, None

    global QGIS_APP  # pylint: disable=W0603

    if QGIS_APP is None:
        gui_flag = True  # All test will run qgis in gui mode
        #noinspection PyPep8Naming
        QGIS_APP = QgsApplication(sys.argv, gui_flag)
        # Make sure QGIS_PREFIX_PATH is set in your env if needed!
        QGIS_APP.initQgis()
        s = QGIS_APP.showSettings()
        LOGGER.debug(s)

    global PARENT  # pylint: disable=W0603
    if PARENT is None:
        #noinspection PyPep8Naming
        PARENT = QtGui.QWidget()

    global CANVAS  # pylint: disable=W0603
    if CANVAS is None:
        #noinspection PyPep8Naming
        CANVAS = QgsMapCanvas(PARENT)
        CANVAS.resize(QtCore.QSize(400, 400))

    global IFACE  # pylint: disable=W0603
    if IFACE is None:
        # QgisInterface is a stub implementation of the QGIS plugin interface
        #noinspection PyPep8Naming
        IFACE = QgisInterface(CANVAS)

    return QGIS_APP, CANVAS, IFACE, PARENT
开发者ID:elpaso,项目名称:qgis-tester-plugin,代码行数:49,代码来源:utils.py

示例12: __init__

  def __init__(self, parent=None):
    QgsMapCanvas.__init__(self, parent)
    self.setCanvasColor(QColor(255,255,255))

    self.item = None
    self.dirty = False

    # reuse settings from QGIS
    settings = QSettings()
    self.enableAntiAliasing( settings.value( "/qgis/enable_anti_aliasing", False, type=bool ) )
    action = settings.value( "/qgis/wheel_action", 0, type=float )
    zoomFactor = settings.value( "/qgis/zoom_factor", 2, type=float )
    self.setWheelAction( QgsMapCanvas.WheelAction(action), zoomFactor )

    self._clear()
开发者ID:Aladar64,项目名称:QGIS,代码行数:15,代码来源:layer_preview.py

示例13: getQgisTestApp

def getQgisTestApp():
    """ Start one QGis application to test agaist

    Input
        NIL

    Output
        handle to qgis app


    If QGis is already running the handle to that app will be returned
    """

    global QGISAPP  # pylint: disable=W0603

    if QGISAPP is None:
        myGuiFlag = True  # All test will run qgis in gui mode

        # In python3 we need to conver to a bytes object (or should
        # QgsApplication accept a QString instead of const char* ?)
        try:
            argvb = list(map(os.fsencode, sys.argv))
        except AttributeError:
            argvb = sys.argv

        # Note: QGIS_PREFIX_PATH is evaluated in QgsApplication -
        # no need to mess with it here.
        QGISAPP = QgsApplication(argvb, myGuiFlag)

        QGISAPP.initQgis()
        s = QGISAPP.showSettings()
        print(s)

    global PARENT  # pylint: disable=W0603
    if PARENT is None:
        PARENT = QWidget()

    global CANVAS  # pylint: disable=W0603
    if CANVAS is None:
        CANVAS = QgsMapCanvas(PARENT)
        CANVAS.resize(QSize(400, 400))

    global IFACE  # pylint: disable=W0603
    if IFACE is None:
        # QgisInterface is a stub implementation of the QGIS plugin interface
        IFACE = QgisInterface(CANVAS)

    return QGISAPP, CANVAS, IFACE, PARENT
开发者ID:Geoneer,项目名称:QGIS,代码行数:48,代码来源:utilities.py

示例14: initGui

 def initGui(self):
     #Models
     self.tblChanges.setModel( ChangeModel() )
     proxyChanges = HistoryProxyModel()
     proxyChanges.setSourceModel( HistoryModel() )
     self.tblHistory.setModel( proxyChanges )
     #Signals
     self.plugin.tvIdentificationResult.model().sourceModel().on_history.connect( self.historyChanged )
     self.tblHistory.selectionModel().currentChanged.connect( self.currentHistoryChanged )
     #Widgets
     settings = QSettings()
     self.mapCanvas = QgsMapCanvas(self.vSplitter)
     self.mapCanvas.setDestinationCrs( QgsCoordinateReferenceSystem('EPSG:4326') )
     zoomFactor = settings.value( "/qgis/zoom_factor", 2.0, type=float )
     action = settings.value( "/qgis/wheel_action", 0, type=int)
     self.mapCanvas.setWheelFactor( zoomFactor )
     self.mapCanvas.enableAntiAliasing( settings.value( "/qgis/enable_anti_aliasing", False, type=bool ))
     #self.mapCanvas.useImageToRender( settings.value( "/qgis/use_qimage_to_render", False, type=bool ))
     self.toolPan = QgsMapToolPan( self.mapCanvas )
     self.mapCanvas.setMapTool( self.toolPan )
     #Canvas items
     self.new_geometry = QgsRubberBand(self.mapCanvas)
     self.new_geometry.setWidth(2)
     self.new_geometry.setIcon( QgsRubberBand.ICON_CIRCLE )
     g = QColor(0, 128, 0, 100)
     self.new_geometry.setColor( g )
     self.old_geometry = QgsRubberBand(self.mapCanvas)
     self.old_geometry.setWidth(2)
     self.old_geometry.setIcon( QgsRubberBand.ICON_CIRCLE )
     r = QColor(255, 0, 0, 100)
     self.old_geometry.setColor( r )
开发者ID:gis-support,项目名称:DIVI-QGIS-Plugin,代码行数:31,代码来源:history_dialog.py

示例15: setupUi

    def setupUi(self, frmPropertyPreview):
        frmPropertyPreview.setObjectName(_fromUtf8("frmPropertyPreview"))
        frmPropertyPreview.resize(627, 480)
        frmPropertyPreview.setTabPosition(QtGui.QTabWidget.South)
        self.local = QtGui.QWidget()
        self.local.setObjectName(_fromUtf8("local"))
        self.gridLayout = QtGui.QGridLayout(self.local)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.localMap = QgsMapCanvas(self.local)
        self.localMap.setObjectName(_fromUtf8("localMap"))
        self.gridLayout.addWidget(self.localMap, 0, 0, 1, 2)
        self.label = QtGui.QLabel(self.local)
        self.label.setMaximumSize(QtCore.QSize(120, 16777215))
        self.label.setObjectName(_fromUtf8("label"))
        self.gridLayout.addWidget(self.label, 1, 0, 1, 1)
        self.cboMapReference = QtGui.QComboBox(self.local)
        self.cboMapReference.setMinimumSize(QtCore.QSize(0, 30))
        self.cboMapReference.setObjectName(_fromUtf8("cboMapReference"))
        self.gridLayout.addWidget(self.cboMapReference, 1, 1, 1, 1)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/plugins/stdm/images/icons/local.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        frmPropertyPreview.addTab(self.local, icon, _fromUtf8(""))
        self.web = QtGui.QWidget()
        self.web.setObjectName(_fromUtf8("web"))
        self.webView = QtWebKit.QWebView(self.web)
        self.webView.setGeometry(QtCore.QRect(19, 19, 561, 401))
        self.webView.setUrl(QtCore.QUrl(_fromUtf8("about:blank")))
        self.webView.setObjectName(_fromUtf8("webView"))
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(_fromUtf8(":/plugins/stdm/images/icons/web.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        frmPropertyPreview.addTab(self.web, icon1, _fromUtf8(""))

        self.retranslateUi(frmPropertyPreview)
        frmPropertyPreview.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(frmPropertyPreview)
开发者ID:7o9,项目名称:stdm-plugin,代码行数:35,代码来源:ui_property_preview.py


注:本文中的qgis.gui.QgsMapCanvas类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。