Пример #1
0
 def test_prepare_metadata(self):
     """Test we can generate the metadata."""
     temp_path = temp_dir()
     iface = QgisInterface(None)
     builder = PluginBuilder(iface)
     builder.plugin_path = temp_path
     builder._prepare_results_html(self.specification)
Пример #2
0
 def test_prepare_code(self):
     """Test the prepare code helper works."""
     temp_path = temp_dir()
     iface = QgisInterface(None)
     builder = PluginBuilder(iface)
     builder.plugin_path = temp_path
     builder._prepare_code(self.specification, temp_path)
Пример #3
0
 def test_prepare_readme(self):
     """Test we can generate the readme ok."""
     temp_path = temp_dir()
     iface = QgisInterface(None)
     builder = PluginBuilder(iface)
     builder.plugin_path = temp_path
     builder._prepare_readme(self.specification, 'fake_module')
Пример #4
0
 def test_prepare_results_html(self):
     """Test the prepare results helper works."""
     temp_path = temp_dir()
     iface = QgisInterface(None)
     builder = PluginBuilder(iface)
     builder.plugin_path = temp_path
     results_popped, template_module_name = builder._prepare_results_html(
         self.specification)
     self.assertIn('You just built a plugin for QGIS!', results_popped)
     self.assertEquals(template_module_name, 'fake_module')
Пример #5
0
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
Пример #6
0
def get_qgis_app():
    """
    Start one QGIS application to test against.

    If QGIS is already running the handle to that app is returned.

    :returns:
     | A tuple containing:
     |    - *QgsApplication* -- QGIS application
     |    - *QgisInterface* -- QGIS interface
     |    - *QgsMapCanvas* -- QGIS map canvas
     |    - *QWidget* -- parent
    :rtype: tuple
    """

    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

    if QGIS_APP is None:
        # All test will run qgis in gui mode
        gui_flag = True
        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
    if PARENT is None:
        PARENT = QtGui.QWidget()

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

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

    return QGIS_APP, IFACE, CANVAS, PARENT
Пример #7
0
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
Пример #8
0
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 safe_qgis mode
        QGISAPP = QgsApplication(sys.argv, myGuiFlag)

        # 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:
            myPath = os.environ['QGIS_PREFIX_PATH']
            myUseDefaultPathFlag = True
            QGISAPP.setPrefixPath(myPath, myUseDefaultPathFlag)

        QGISAPP.initQgis()
        s = QGISAPP.showSettings()
        LOGGER.debug(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
Пример #9
0
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

    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)
        else:
            print 'Warning: QGISPATH is not set'

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

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

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

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

    return (QGISAPP, CANVAS, IFACE, PARENT)
Пример #10
0
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.
    """

    from PyQt5 import QtCore, QtWidgets
    from qgis.core import QgsApplication
    from qgis.gui import QgsMapCanvas
    from qgis_interface import QgisInterface

    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([bytes(sys.argv[0], 'latin-1')], 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 = QtWidgets.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
Пример #11
0
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

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

        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
Пример #12
0
    ring.AddPoint(ring_xright_origin, ring_ytop)
    ring.AddPoint(ring_xright_origin, ring_ybottom)
    ring.AddPoint(ring_xleft_origin, ring_ybottom)
    ring.AddPoint(ring_xleft_origin, ring_ytop)
    poly = ogr.Geometry(ogr.wkbPolygon)
    poly.AddGeometry(ring)
    return poly


if __name__ == '__main__' or __name__ == '__console__':
    app = QApplication([])
    QgsApplication.setPrefixPath(r'C:\Program Files\QGIS 2.18\apps\qgis', True)
    QgsApplication.initQgis()

    canvas = QgsMapCanvas()
    iface = QgisInterface(canvas)

    output_source = r'D:\Projetos\0023.2016_TAESA\data\iginicao\tmp\grid.shp'

    base_layer_source = r'D:\Projetos\0023.2016_TAESA\data\iginicao\tmp\buffer.shp'
    basename = os.path.splitext(os.path.basename(base_layer_source))[0]

    input_layer = QgsVectorLayer(base_layer_source, basename, 'ogr')
    '''
    https://gis.stackexchange.com/questions/245811/getting-layer-extent-in-pyqgis
    https://gis.stackexchange.com/questions/130794/getting-shapefile-extent-from-standalone-pyqgis-script
    https://gis.stackexchange.com/questions/224930/how-to-select-polygons-which-contain-at-least-one-point-with-spatial-index
    https://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html
    https://gis.stackexchange.com/questions/174622/how-to-access-shapefile-metadata-and-metatypes-information-using-ogr
    '''
Пример #13
0
def iface(qgis_application):
    return QgisInterface(None)