Newer
Older
import qgis, re
assert '.app' in qgis.__file__, 'Can not locate path of QGIS.app'
PATH_QGIS_APP = re.split(r'\.app[\/]', qgis.__file__)[0] + '.app'
PATH_QGIS = os.path.join(PATH_QGIS_APP, *['Contents', 'MacOS'])
os.environ['GDAL_DATA'] = r'/Library/Frameworks/GDAL.framework/Versions/Current/Resources/gdal'
QApplication.addLibraryPath(os.path.join(PATH_QGIS_APP, *['Contents', 'PlugIns']))
QApplication.addLibraryPath(os.path.join(PATH_QGIS_APP, *['Contents', 'PlugIns', 'qgis']))
else:
# assume OSGeo4W startup
PATH_QGIS = os.environ['QGIS_PREFIX_PATH']
assert os.path.exists(PATH_QGIS)
qgsApp = QgsApplication([], True)
qgsApp.setPrefixPath(PATH_QGIS, True)
qgsApp.initQgis()
def printQgisLog(tb, error, level):
if error not in ['Python warning']:
print(tb)
QgsApplication.instance().messageLog().messageReceived.connect(printQgisLog)
def createCRSTransform(src, dst):
assert isinstance(src, QgsCoordinateReferenceSystem)
assert isinstance(dst, QgsCoordinateReferenceSystem)
t = QgsCoordinateTransform()
t.setSourceCrs(src)
t.setDestinationCrs(dst)
return t
if __name__ == '__main__':
#nice predecessors
qgsApp = initQgisApplication()

benjamin.jakimow@geo.hu-berlin.de
committed
se = SpatialExtent.world()
assert nicePredecessor(26) == 25
assert nicePredecessor(25) == 25
assert nicePredecessor(23) == 20
assert nicePredecessor(999) == 950
assert nicePredecessor(1001) == 1000
assert nicePredecessor(1.2) == 1.0 #
assert nicePredecessor(0.8) == 0.5
assert nicePredecessor(0.2) == 0.1
assert nicePredecessor(0.021) == 0.01
assert nicePredecessor(0.0009991) == 0.0005