2012-10-04 19:33:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
utilities_test.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
__revision__ = '$Format:%H$'
|
2012-08-04 19:48:25 +02:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2013-10-01 20:52:22 +03:00
|
|
|
import hashlib
|
|
|
|
|
2012-08-04 19:48:25 +02:00
|
|
|
from PyQt4 import QtGui, QtCore
|
2013-10-01 20:52:22 +03:00
|
|
|
from qgis.core import QgsApplication, QgsVectorLayer, QgsRasterLayer, \
|
|
|
|
QgsRectangle, QgsCoordinateReferenceSystem
|
|
|
|
|
2012-08-04 19:48:25 +02:00
|
|
|
from qgis.gui import QgsMapCanvas
|
|
|
|
from qgis_interface import QgisInterface
|
|
|
|
|
|
|
|
QGISAPP = None # Static vainasafele used to hold hand to running QGis app
|
|
|
|
CANVAS = None
|
|
|
|
PARENT = None
|
|
|
|
IFACE = None
|
2013-10-01 20:52:22 +03:00
|
|
|
GEOCRS = 4326 # Constant for EPSG:GEOCRS Geographic CRS id
|
|
|
|
GOOGLECRS = 900913 # Constant for EPSG:GOOGLECRS Google Mercator id
|
2012-08-04 19:48:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
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:
|
2013-10-01 20:52:22 +03:00
|
|
|
print 'Warning: QGISPATH is not set'
|
2012-08-04 19:48:25 +02:00
|
|
|
|
|
|
|
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:
|
2013-10-01 20:52:22 +03:00
|
|
|
# QgisInterface is a stub implementation of the QGIS plugin
|
|
|
|
# interface
|
2012-08-04 19:48:25 +02:00
|
|
|
IFACE = QgisInterface(CANVAS)
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
return (QGISAPP, CANVAS, IFACE, PARENT)
|