def test_runCategorizedHazardBuildingImpact(self): """Flood function runs in GUI with Flood in Jakarta hazard data Uses DKI buildings exposure data.""" myResult, myMessage = setupScenario( theHazard='Flood in Jakarta', theExposure='DKI buildings', theFunction='Be affected', theFunctionId='Categorised Hazard Building Impact Function') assert myResult, myMessage # Enable on-the-fly reprojection setCanvasCrs(GEOCRS, True) setJakartaGeoExtent() # Press RUN myButton = DOCK.pbnRunStop QTest.mouseClick(myButton, QtCore.Qt.LeftButton) myResult = DOCK.wvResults.page().currentFrame().toPlainText() myMessage = 'Result not as expected: %s' % myResult # This is the expected number of building might be affected assert '535' in myResult, myMessage assert '453' in myResult, myMessage assert '436' in myResult, myMessage
def test_runFloodPopulationImpactFunction(self): """Flood function runs in GUI with Jakarta data Raster on raster based function runs as expected.""" # Push OK with the left mouse button myButton = DOCK.pbnRunStop myMessage = 'Run button was not enabled' assert myButton.isEnabled(), myMessage myResult, myMessage = setupScenario( theHazard='A flood in Jakarta like in 2007', theExposure='Penduduk Jakarta', theFunction='HKVtest', theFunctionId='HKVtest') assert myResult, myMessage # Enable on-the-fly reprojection setCanvasCrs(GEOCRS, True) setJakartaGeoExtent() # Press RUN QTest.mouseClick(myButton, QtCore.Qt.LeftButton) myResult = DOCK.wvResults.page().currentFrame().toPlainText() # Check that the number is as what was calculated by # Marco Hartman form HKV myMessage = 'Result not as expected: %s' % myResult # This is the expected impact number assert '2480' in myResult, myMessage
def test_runFloodPopulationImpactFunction_scaling(self): """Flood function runs in GUI with 5x5km population data Raster on raster based function runs as expected with scaling.""" myResult, myMessage = setupScenario( theHazard='A flood in Jakarta like in 2007', theExposure='People', theFunction='Need evacuation', theFunctionId='Flood Evacuation Function') assert myResult, myMessage # Enable on-the-fly reprojection setCanvasCrs(GEOCRS, True) setJakartaGeoExtent() # Press RUN myButton = DOCK.pbnRunStop QTest.mouseClick(myButton, QtCore.Qt.LeftButton) myResult = DOCK.wvResults.page().currentFrame().toPlainText() myMessage = 'Result not as expected: %s' % myResult # Check numbers are OK (within expected errors from resampling) assert '10484' in myResult, myMessage assert '977' in myResult, myMessage # These are expected impact number
def Xtest_renderTemplate(self): """Test that load template works""" # Use the template from our resources bundle myInPath = ":/plugins/inasafe/basic.qpt" myLayer, _ = loadLayer("test_shakeimpact.shp") myCanvasLayer = QgsMapCanvasLayer(myLayer) CANVAS.setLayerSet([myCanvasLayer]) myMap = Map(IFACE) setJakartaGeoExtent() myMap.setImpactLayer(myLayer) myPath = unique_filename(prefix="outTemplate", suffix=".pdf", dir=temp_dir("test")) LOGGER.debug(myPath) myMap.renderTemplate(myInPath, myPath) assert os.path.exists(myPath)
def test_vectorProjections(self): """Test that vector input data is reprojected properly during clip""" # Input data is OSM in GOOGLE CRS # We are reprojecting to GEO and expecting the output shp to be in GEO # see https://github.com/AIFDR/inasafe/issues/119 # and https://github.com/AIFDR/inasafe/issues/95 myVectorLayer = QgsVectorLayer(VECTOR_PATH2, 'OSM Buildings', 'ogr') myMessage = 'Failed to load osm buildings' assert myVectorLayer is not None, myMessage assert myVectorLayer.isValid() setCanvasCrs(GEOCRS, True) setJakartaGeoExtent() myClipRect = [106.52, -6.38, 107.14, -6.07] # Clip the vector to the bbox myResult = clipLayer(myVectorLayer, myClipRect) assert (os.path.exists(myResult))
def Xtest_renderTemplate(self): """Test that load template works""" #Use the template from our resources bundle myInPath = ':/plugins/inasafe/basic.qpt' myLayer, _ = loadLayer('test_shakeimpact.shp') myCanvasLayer = QgsMapCanvasLayer(myLayer) CANVAS.setLayerSet([myCanvasLayer]) myMap = Map(IFACE) setJakartaGeoExtent() myMap.setImpactLayer(myLayer) myPath = unique_filename(prefix='outTemplate', suffix='.pdf', dir=temp_dir('test')) LOGGER.debug(myPath) myMap.renderTemplate(myInPath, myPath) assert os.path.exists(myPath)
def test_renderTemplate(self): """Test that load template works""" #Use the template from our resources bundle myInPath = ':/plugins/inasafe/basic.qpt' myLayer, myType = loadLayer('test_shakeimpact.shp') del myType myCanvasLayer = QgsMapCanvasLayer(myLayer) CANVAS.setLayerSet([myCanvasLayer]) myMap = Map(IFACE) setJakartaGeoExtent() myMap.setImpactLayer(myLayer) myOutPath = os.path.join(temp_dir(), 'outTemplate.pdf') if os.path.exists(myOutPath): os.remove(myOutPath) myMap.renderTemplate(myInPath, myOutPath) assert os.path.exists(myOutPath)
def test_vectorProjections(self): """Test that vector input data is reprojected properly during clip""" # Input data is OSM in GOOGLE CRS # We are reprojecting to GEO and expecting the output shp to be in GEO # see https://github.com/AIFDR/inasafe/issues/119 # and https://github.com/AIFDR/inasafe/issues/95 myVectorLayer = QgsVectorLayer(VECTOR_PATH2, 'OSM Buildings', 'ogr') myMessage = 'Failed to load osm buildings' assert myVectorLayer is not None, myMessage assert myVectorLayer.isValid() setCanvasCrs(GEOCRS, True) setJakartaGeoExtent() myClipRect = [106.52, -6.38, 107.14, -6.07] # Clip the vector to the bbox myResult = clipLayer(myVectorLayer, myClipRect) assert(os.path.exists(myResult))
def test_clipVectorHard(self): """Vector layers can be hard clipped. Hard clipping will remove any dangling, non intersecting elements. """ myVectorLayer = QgsVectorLayer(VECTOR_PATH3, 'OSM Buildings', 'ogr') myMessage = 'Failed to load osm buildings' assert myVectorLayer is not None, myMessage assert myVectorLayer.isValid() setCanvasCrs(GEOCRS, True) setJakartaGeoExtent() myClipRect = [106.8218, -6.1842, 106.8232, -6.1830] # Clip the vector to the bbox myResult = clipLayer(myVectorLayer, myClipRect, theHardClipFlag=True) # Check the output is valid assert (os.path.exists(myResult))
def test_ResultStyling(self): """Test that ouputs from a model are correctly styled (colours and opacity. """ # Push OK with the left mouse button print '--------------------' print combosToString(DOCK) myResult, myMessage = setupScenario( theHazard=('A flood in Jakarta like in 2007'), theExposure='People', theFunction='Need evacuation', theFunctionId='Flood Evacuation Function') assert myResult, myMessage # Enable on-the-fly reprojection setCanvasCrs(GEOCRS, True) setJakartaGeoExtent() # Run manually so we can get the output layer DOCK.setupCalculator() myRunner = DOCK.calculator.getRunner() myRunner.run() # Run in same thread myEngineImpactLayer = myRunner.impactLayer() myQgisImpactLayer = DOCK.readImpactLayer(myEngineImpactLayer) myStyle = myEngineImpactLayer.get_style_info() #print myStyle setRasterStyle(myQgisImpactLayer, myStyle) # simple test for now - we could test explicity for style state # later if needed. myMessage = ('Raster layer was not assigned a ColorRampShader' ' as expected.') assert myQgisImpactLayer.colorShadingAlgorithm() == \ QgsRasterLayer.ColorRampShader, myMessage myMessage = ('Raster layer was not assigned transparency' 'classes as expected.') myTransparencyList = (myQgisImpactLayer.rasterTransparency(). transparentSingleValuePixelList()) #print "Transparency list:" + str(myTransparencyList) assert (len(myTransparencyList) > 0)
def test_clipVectorHard(self): """Vector layers can be hard clipped. Hard clipping will remove any dangling, non intersecting elements. """ myVectorLayer = QgsVectorLayer(VECTOR_PATH3, 'OSM Buildings', 'ogr') myMessage = 'Failed to load osm buildings' assert myVectorLayer is not None, myMessage assert myVectorLayer.isValid() setCanvasCrs(GEOCRS, True) setJakartaGeoExtent() myClipRect = [106.8218, -6.1842, 106.8232, -6.1830] # Clip the vector to the bbox myResult = clipLayer(myVectorLayer, myClipRect, theHardClipFlag=True) # Check the output is valid assert(os.path.exists(myResult))
def test_runFloodPopulationPolygonHazardImpactFunction(self): """Flood function runs in GUI with Jakarta polygon flood hazard data. Uses population raster exposure layer""" myResult, myMessage = setupScenario( theHazard=('A flood in Jakarta in RW areas identified' ' as flood prone'), theExposure='Penduduk Jakarta', theFunction='Need evacuation', theFunctionId='Flood Evacuation Function Vector Hazard') assert myResult, myMessage # Enable on-the-fly reprojection setCanvasCrs(GEOCRS, True) setJakartaGeoExtent() # Press RUN myButton = DOCK.pbnRunStop QTest.mouseClick(myButton, QtCore.Qt.LeftButton) myResult = DOCK.wvResults.page().currentFrame().toPlainText() myMessage = 'Result not as expected: %s' % myResult # This is the expected number of people needing evacuation assert '134953000' in myResult, myMessage