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


Python QgsApplication.initQgis方法代码示例

本文整理汇总了Python中qgis.core.QgsApplication.initQgis方法的典型用法代码示例。如果您正苦于以下问题:Python QgsApplication.initQgis方法的具体用法?Python QgsApplication.initQgis怎么用?Python QgsApplication.initQgis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.core.QgsApplication的用法示例。


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

示例1: start_app

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
def start_app(cleanup=True):
    """
    Will start a QgsApplication and call all initialization code like
    registering the providers and other infrastructure. It will not load
    any plugins.

    You can always get the reference to a running app by calling `QgsApplication.instance()`.

    The initialization will only happen once, so it is safe to call this method repeatedly.

        Parameters
        ----------

        cleanup: Do cleanup on exit. Defaults to true.

        Returns
        -------
        QgsApplication

        A QgsApplication singleton
    """
    global QGISAPP

    try:
        QGISAPP
    except NameError:
        myGuiFlag = True  # All test will run qgis in gui mode

        try:
            sys.argv
        except:
            sys.argv = ['']

        # In python3 we need to convert 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()
        print(QGISAPP.showSettings())

        def debug_log_message(message, tag, level):
            print('{}({}): {}'.format(tag, level, message))

        QgsApplication.instance().messageLog().messageReceived.connect(debug_log_message)

        if cleanup:
            import atexit

            @atexit.register
            def exitQgis():
                QGISAPP.exitQgis()

    return QGISAPP
开发者ID:AlisterH,项目名称:Quantum-GIS,代码行数:62,代码来源:__init__.py

示例2: globalQgis

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
def globalQgis():
    """Singleton implementation for a global QGIS app instance.

    Args:
        None
    Returns:
        A QGIS Application instance
    Raises:
        None
    """

    global QGISAPP

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

        QGISAPP.initQgis()
        s = QGISAPP.showSettings()
        print s
    return QGISAPP
开发者ID:rudithiede,项目名称:QGIS-Bucket-Fill,代码行数:27,代码来源:utilities_test.py

示例3: getTestApp

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
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,代码行数:31,代码来源:app.py

示例4: init_qgis

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
def init_qgis(verbose=False):
    """ Initialize qgis application
    """
    from qgis.core import Qgis, QgsApplication
    global qgis_application 

    qgisPrefixPath = os.environ.get('QGIS_PREFIX_PATH','/usr/')
    sys.path.append(os.path.join(qgisPrefixPath, "share/qgis/python/plugins/"))

    # Set offscreen mode when no display 
    # This will prevent Qt tryning to connect to display
    if os.environ.get('DISPLAY') is None:
        os.environ['QT_QPA_PLATFORM'] = 'offscreen'

    qgis_application = QgsApplication([], False )
    qgis_application.setPrefixPath(qgisPrefixPath, True)
    qgis_application.initQgis()

    os.environ['QGIS_PREFIX_PATH'] = qgisPrefixPath

    # Auto cleanup
    @atexit.register
    def extQgis():
        global qgis_application
        if qgis_application:
            qgis_application.exitQgis()
            del qgis_application

    if verbose:
         print(qgis_application.showSettings(),file=sys.stderr)
    
    # Install logging hook
    install_message_hook( verbose )
开发者ID:3liz,项目名称:lizmap-plugin,代码行数:35,代码来源:commands.py

示例5: init

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
def init(args=None, guienabled=True, configpath=None, sysexit=True):
    """
    Create a new QGIS Qt application.

    You should use this before creating any Qt widgets or QGIS objects for
    your custom QGIS based application.

    usage:
        from wrappers import QGIS

        QGIS.init()

    args - args passed to the underlying QApplication.
    guienabled - True by default will create a QApplication with a GUI. Pass
                 False if you wish to create no GUI based app, e.g a server app.
    configpath - Custom config path QGIS will use to load settings.
    sysexit - Call sys.exit on app exit. True by default.
    """
    if not args:
        args = []
    if not configpath:
        configpath = ''
    app = QgsApplication(args, guienabled, configpath)
    QgsApplication.initQgis()
    return app
开发者ID:NathanW2,项目名称:ascii_qgis,代码行数:27,代码来源:QGIS.py

示例6: qgisapp

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
def qgisapp(args=None, guienabled=True, configpath=None, sysexit=True):
    """
    Create a new QGIS Qt application.

    You should use this before creating any Qt widgets or QGIS objects for
    your custom QGIS based application.

    usage:
        from qgis.core.contextmanagers import qgisapp

        def main(app):
            # Run your main code block

            with qgisapp(sys.argv) as app:
                main(app)

    args - args passed to the underlying QApplication.
    guienabled - True by default will create a QApplication with a GUI. Pass
                 False if you wish to create no GUI based app, e.g a server app.
    configpath - Custom config path QGIS will use to load settings.
    sysexit - Call sys.exit on app exit. True by default.
    """
    if not args:
        args = []
    app = QgsApplication(args, guienabled, configpath)
    QgsApplication.initQgis()
    yield app
    if guienabled:
        exitcode = app.exec_()
    else:
        exitcode = 0
    QgsApplication.exitQgis()
    if sysexit:
        sys.exit(exitcode)
开发者ID:dwsilk,项目名称:QGIS,代码行数:36,代码来源:contextmanagers.py

示例7: init

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
    def init(self, logo, title):
        from qgis.core import QgsApplication
        from PyQt4.QtGui import QApplication, QFont, QIcon
        from PyQt4.QtCore import QLocale, QTranslator
        try:
            import PyQt4.QtSql
        except ImportError:
            pass

        self.app = QgsApplication(self.sysargv, True)
        import roam.roam_style
        self.app.setStyleSheet(roam.roam_style.appstyle)
        QgsApplication.setPrefixPath(self.prefixpath, True)
        QgsApplication.initQgis()

        locale = QLocale.system().name()
        self.translationFile = os.path.join(self.i18npath, '{0}.qm'.format(locale))
        translator = QTranslator()
        translator.load(self.translationFile, "i18n")
        self.app.installTranslator(translator)

        QApplication.setStyle("Plastique")
        QApplication.setFont(QFont('Segoe UI'))
        QApplication.setWindowIcon(QIcon(logo))
        QApplication.setApplicationName(title)

        import roam.editorwidgets.core
        roam.editorwidgets.core.registerallwidgets()
        return self
开发者ID:HeatherHillers,项目名称:RoamMac,代码行数:31,代码来源:environ.py

示例8: __init__

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
  def __init__(self):
    """
    """

    # Folder icon
    QgsApplication.initQgis()
    style = QgsApplication.style()
    self.folder_icon = QtGui.QIcon()
    self.folder_icon.addPixmap(style.standardPixmap(QtGui.QStyle.SP_DirClosedIcon),
      QtGui.QIcon.Normal, QtGui.QIcon.Off)

    warn_icon_path = os.path.join(GpicGlobals.Instance().images_dir_path,
      GpicGlobals.Instance().ICON_WARN_FILE_NAME)
    self.warn_icon = QtGui.QIcon(warn_icon_path)

    wms_layer_icon_path = os.path.join(GpicGlobals.Instance().images_dir_path,
      GpicGlobals.Instance().ICON_WMS_LAYER_FILE_NAME)
    self.wms_layer_icon = QtGui.QIcon(wms_layer_icon_path)

    wms_style_icon_path = os.path.join(GpicGlobals.Instance().images_dir_path,
      GpicGlobals.Instance().ICON_WMS_STYLE_FILE_NAME)
    self.wms_style_icon = QtGui.QIcon(wms_style_icon_path)

    wfs_layer_icon_path = os.path.join(GpicGlobals.Instance().images_dir_path,
      GpicGlobals.Instance().ICON_WFS_LAYER_FILE_NAME)
    self.wfs_layer_icon = QtGui.QIcon(wfs_layer_icon_path)

    raster_layer_icon_path = os.path.join(GpicGlobals.Instance().images_dir_path,
      GpicGlobals.Instance().ICON_RASTER_LAYER_FILE_NAME)
    self.raster_layer_icon = QtGui.QIcon(raster_layer_icon_path)
开发者ID:bchartier,项目名称:geopicardie-qgis-plugin,代码行数:32,代码来源:gpic_icons.py

示例9: set_up_interface

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
def set_up_interface():
    """
    Sets up a QGIS pseudo-application which enables calling methods as if when calling them from QGIS-console.

    :return qgis_app: Pseudo QGIS-instance
    :rtype: QgsApplication
    :return canvas: The map canvas
    :rtype: QgsMapCanvas
    :return iface: A dummy interface, giving access to needed method-calls
    :rtype: QgisInterface
    """
    gui_flag = True  # All test will run qgis in gui mode
    qgis_app = QgsApplication(sys.argv, gui_flag)
    prefix_path = config.qgis_prefix_path()
    qgis_app.setPrefixPath(prefix_path, True)
    qgis_app.initQgis()
    QCoreApplication.setOrganizationName('QGIS')
    QCoreApplication.setApplicationName('QGIS2')

    # parent = QWidget()
    # canvas = QgsMapCanvas(parent)
    # canvas.resize(QSize(400, 400))
    canvas = MyMapCanvas()

    iface = QgisInterface(canvas)

    return qgis_app, canvas, iface
开发者ID:pgRouting,项目名称:pgRoutingLayer,代码行数:29,代码来源:qgis_models.py

示例10: testImportCSVFile

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
    def testImportCSVFile(self):
        QgsApplication.setPrefixPath("/usr/share/qgis", True)
        qgs = QgsApplication([], False)
        # load providers
        qgs.initQgis()

        # shapefile
        aroundtheblockPath = os.path.join(os.path.abspath("../../sampledata/aroundtheblock/"), "aroundtheblock.csv")
        logger = mockLogger()
        messageBar = MockMessageBar(logger)
        messageBox = MockMessageBox
        layer = loadCSVLayer(
            dateFormat='mm/dd/yyyy',
            gpsPath=aroundtheblockPath,
            logger=logger,
            mainWindow=None,
            messageBar=messageBar,
            messageBox=messageBox
        )

        self.assertIsNotNone(layer)
        self.assertIsInstance(layer, QgsVectorLayer)
        self.assertTrue(layer.isValid())

        featuresCount = sum(1 for _ in layer.getFeatures())
        self.assertEqual(featuresCount, 587)
开发者ID:EdFarrell,项目名称:MilkMachine,代码行数:28,代码来源:test_MMImport.py

示例11: main

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
def main(argv):

    # create Qt application
    app = QtGui.QApplication(argv, True)

    # Set the app style
    mySplashPix = QtGui.QPixmap(QtCore.QString(DATA_DIR + '/OCEAN.png'))
    mySplashPixScaled = mySplashPix.scaled(500, 300, Qt.Qt.KeepAspectRatio)
    mySplash = QtGui.QSplashScreen(mySplashPixScaled)
    mySplash.show()

    # initialize qgis libraries
    QgsApplication.setPrefixPath(QGIS_PREFIX, True)
    QgsApplication.initQgis()

    # create main window
    wnd = MainWindow(mySplash)
    wnd.show()

    # Create signal for app finish
    app.connect(
        app, QtCore.SIGNAL('lastWindowClosed()'), app, QtCore.SLOT('quit()'))

    # Start the app up
    retval = app.exec_()

    # We got an exit signal so time to clean up
    QgsApplication.exitQgis()

    sys.exit(retval)
开发者ID:gem,项目名称:qt-experiments,代码行数:32,代码来源:example_canvas.py

示例12: qgis_app

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
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,代码行数:30,代码来源:utils.py

示例13: get_qgis_app

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
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,代码行数:59,代码来源:utilities.py

示例14: getQgisTestApp

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
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,代码行数:56,代码来源:utilities.py

示例15: testExportToFileWithModel

# 需要导入模块: from qgis.core import QgsApplication [as 别名]
# 或者: from qgis.core.QgsApplication import initQgis [as 别名]
    def testExportToFileWithModel(self):
        QgsApplication.setPrefixPath("/usr/share/qgis", True)
        qgs = QgsApplication([], False)
        # load providers
        qgs.initQgis()

        # shapefile
        aroundtheblockPath = os.path.join(os.path.abspath("../../sampledata/"), "amsterdam-yymmdd.csv")
        logger = test_MMImport.mockLogger()
        messageBar = test_MMImport.MockMessageBar(logger)
        messageBox = test_MMImport.MockMessageBox
        layer = loadCSVLayer(
            dateFormat='yyyy/mm/dd',
            gpsPath=aroundtheblockPath,
            logger=logger,
            mainWindow=None,
            messageBar=messageBar,
            messageBox=messageBox
        )
        self.assertTrue(layer.isValid())

        # reset the flag
        messageBar.gotSuccess = False

        fields = test_MMImport.field_indices(layer)
        # if model data should be included
        modelTemplate = {'link': None, 'longitude': None, 'latitude': None, 'altitude' : None, 'scale': None}
        layer.startEditing()
        layer.beginEditCommand("Rendering Editing")
        for feature in layer.getFeatures():
            attributes = feature.attributes()
            model = modelTemplate
            model['link'] = 'files/red_sphereC.dae'
            model['longitude'] = attributes[fields['x']]
            model['latitude'] = attributes[fields['y']]
            model['scale'] = 1
            model['altitude'] = attributes[fields['altitude']]
            layer.changeAttributeValue(feature.id(), fields['model'], str(model))
        layer.endEditCommand()

        loggerPath = ""
        exportToFile(
            activeLayer=layer,
            audioHREF="",
            audioOffset=0,
            exportPath="amsterdam-yymmdd-model.kml",
            fields=fields,
            lastDirectory=".",
            logger=logger,
            loggerPath=loggerPath,
            messageBar=messageBar
        )

        self.assertTrue(messageBar.gotSuccess)
开发者ID:EdFarrell,项目名称:MilkMachine,代码行数:56,代码来源:test_MMExport.py


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