Example #1
0
    def test_transparency_of_minimum_value(self):
        """Test that transparency of minimum value works when set to 100%
        """
        # This dataset has all cells with value 1.3
        myLayer, _ = load_layer('issue126.tif')

        # Note the float quantity values below
        myStyleInfo = {'style_classes': [
            {'colour': '#FFFFFF', 'transparency': 100, 'quantity': 0.0},
            {'colour': '#38A800', 'quantity': 0.038362596547925065,
             'transparency': 0, 'label': u'Rendah [0 orang/sel]'},
            {'colour': '#79C900', 'transparency': 0,
             'quantity': 0.07672519309585013},
            {'colour': '#CEED00', 'transparency': 0,
             'quantity': 0.1150877896437752},
            {'colour': '#FFCC00', 'quantity': 0.15345038619170026,
             'transparency': 0, 'label': u'Sedang [0 orang/sel]'},
            {'colour': '#FF6600', 'transparency': 0,
             'quantity': 0.19181298273962533},
            {'colour': '#FF0000', 'transparency': 0,
             'quantity': 0.23017557928755039},
            {'colour': '#7A0000', 'quantity': 0.26853817583547546,
             'transparency': 0, 'label': u'Tinggi [0 orang/sel]'}]}

        try:
            setRasterStyle(myLayer, myStyleInfo)
        except Exception, e:
            myMessage = '\nCould not create raster style'
            e.args = (e.args[0] + myMessage,)
            raise
Example #2
0
    def test_issue126(self):
        """Test that non integer transparency ranges fail gracefully.
        .. seealso:: https://github.com/AIFDR/inasafe/issues/126
        """
        # This dataset has all cells with value 1.3
        myLayer, _ = load_layer('issue126.tif')

        # Note the float quantity values below
        myStyleInfo = {'style_classes': [
            dict(colour='#38A800', quantity=1.1, transparency=100),
            dict(colour='#38A800', quantity=1.4, transparency=0),
            dict(colour='#79C900', quantity=10.1, transparency=0)]}

        try:
            setRasterStyle(myLayer, myStyleInfo)
        except Exception, e:
            myMessage = (
                'Setting style info with float based ranges should fail '
                'gracefully.')
            e.args = (e.args[0] + myMessage,)
            raise
Example #3
0
    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 combos_to_string(DOCK)

        result, message = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='People',
            function='Need evacuation',
            function_id='Flood Evacuation Function')
        self.assertTrue(result, message)

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Run manually so we can get the output layer
        DOCK.clip_parameters = DOCK.get_clip_parameters()
        DOCK.prepare_aggregator()
        DOCK.aggregator.validate_keywords()
        DOCK.setup_calculator()
        test_runner = DOCK.calculator.get_runner()
        test_runner.run()  # Run in same thread
        safe_layer = test_runner.impact_layer()
        qgis_layer = read_impact_layer(safe_layer)
        style = safe_layer.get_style_info()
        setRasterStyle(qgis_layer, style)
        # simple test for now - we could test explicity for style state
        # later if needed.
        message = (
            'Raster layer was not assigned a Singleband pseudocolor'
            ' renderer as expected.')
        self.assertTrue(
            qgis_layer.renderer().type() == 'singlebandpseudocolor', message)
Example #4
0
    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 combos_to_string(DOCK)

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='People',
            function='Need evacuation',
            function_id='Flood Evacuation Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Run manually so we can get the output layer
        DOCK.prepare_aggregator()
        DOCK.aggregator.validate_keywords()
        DOCK.setup_calculator()
        myRunner = DOCK.calculator.get_runner()
        myRunner.run()  # Run in same thread
        myEngineImpactLayer = myRunner.impact_layer()
        myQgisImpactLayer = read_impact_layer(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
Example #5
0
    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 combos_to_string(DOCK)

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='People',
            function='Need evacuation',
            function_id='Flood Evacuation Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Run manually so we can get the output layer
        DOCK.prepare_aggregator()
        DOCK.aggregator.validate_keywords()
        DOCK.setup_calculator()
        myRunner = DOCK.calculator.get_runner()
        myRunner.run()  # Run in same thread
        myEngineImpactLayer = myRunner.impact_layer()
        myQgisImpactLayer = read_impact_layer(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
Example #6
0
class StylingTest(unittest.TestCase):
    """Tests for qgis styling related functions.
    """

    def setUp(self):
        os.environ['LANG'] = 'en'

    def tearDown(self):
        pass

    def test_issue126(self):
        """Test that non integer transparency ranges fail gracefully.
        .. seealso:: https://github.com/AIFDR/inasafe/issues/126
        """
        # This dataset has all cells with value 1.3
        myLayer, _ = load_layer('issue126.tif')

        # Note the float quantity values below
        myStyleInfo = {'style_classes': [
            dict(colour='#38A800', quantity=1.1, transparency=100),
            dict(colour='#38A800', quantity=1.4, transparency=0),
            dict(colour='#79C900', quantity=10.1, transparency=0)]}

        try:
            setRasterStyle(myLayer, myStyleInfo)
        except Exception, e:
            myMessage = (
                'Setting style info with float based ranges should fail '
                'gracefully.')
            e.args = (e.args[0] + myMessage,)
            raise
        # Now validate the transparency values were set to 255 because
        # they are floats and we cant specify pixel ranges to floats
        # Note we don't test on the exact interval because 464c6171dd55
        myValue1 = myLayer.renderer().rasterTransparency().alphaValue(1.2)
        myValue2 = myLayer.renderer().rasterTransparency().alphaValue(1.5)
        myMessage = ('Transparency should be ignored when style class'
                     ' quantities are floats')
        assert myValue1 == myValue2 == 255, myMessage

        # Now run the same test again for int intervals
        myStyleInfo['style_classes'] = [
            dict(colour='#38A800', quantity=2, transparency=100),
            dict(colour='#38A800', quantity=4, transparency=0),
            dict(colour='#79C900', quantity=10, transparency=0)]
        myMessage = ('Setting style info with generate valid transparent '
                     'pixel entries.')
        try:
            setRasterStyle(myLayer, myStyleInfo)
        except:
            raise Exception(myMessage)
        # Now validate the transparency values were set to 255 because
        # they are floats and we cant specify pixel ranges to floats
        myValue1 = myLayer.renderer().rasterTransparency().alphaValue(1)
        myValue2 = myLayer.renderer().rasterTransparency().alphaValue(3)
        myMessage1 = myMessage + 'Expected 0 got %i' % myValue1
        myMessage2 = myMessage + 'Expected 255 got %i' % myValue2
        assert myValue1 == 0, myMessage1
        assert myValue2 == 255, myMessage2

        # Verify that setRasterStyle doesn't break when floats coincide with
        # integers
        # See https://github.com/AIFDR/inasafe/issues/126#issuecomment-5978416
        myStyleInfo['style_classes'] = [
            dict(colour='#38A800', quantity=2.0, transparency=100),
            dict(colour='#38A800', quantity=4.0, transparency=0),
            dict(colour='#79C900', quantity=10.0, transparency=0)]

        try:
            setRasterStyle(myLayer, myStyleInfo)
        except Exception, e:
            myMessage = (
                'Broken: Setting style info with generate valid transparent '
                'floating point pixel entries such as 2.0, 3.0')
            e.args = (e.args[0] + myMessage,)
            raise