Example #1
0
    def test_issue121(self):
        """Test that point symbol size can be set from style (issue 121).
        .. seealso:: https://github.com/AIFDR/inasafe/issues/121
        """
        myLayer, myType = loadLayer('kecamatan_jakarta_osm_centroids.shp')
        del myType
        # Note the float quantity values below
        myStyleInfo = {'target_field': 'KEPADATAN', 'style_classes': [
            {'opacity': 1, 'max': 200, 'colour': '#fecc5c',
             'min': 45, 'label': 'Low', 'size': 1},
            {'opacity': 1, 'max': 350, 'colour': '#fd8d3c',
             'min': 201, 'label': 'Medium', 'size': 2},
            {'opacity': 1, 'max': 539, 'colour': '#f31a1c',
             'min': 351, 'label': 'High', 'size': 3}]}
        myMessage = 'Setting style with point sizes should work.'
        try:
            setVectorGraduatedStyle(myLayer, myStyleInfo)
        except:
            raise Exception(myMessage)
        # Now validate the size values were set as expected

        if myLayer.isUsingRendererV2():
            # new symbology - subclass of QgsFeatureRendererV2 class
            myRenderer = myLayer.rendererV2()
            myType = myRenderer.type()
            assert myType == 'graduatedSymbol'
            mySize = 1
            for myRange in myRenderer.ranges():
                mySymbol = myRange.symbol()
                mySymbolLayer = mySymbol.symbolLayer(0)
                myActualSize = mySymbolLayer.size()
                myMessage = (('Expected symbol layer 0 for range %s to have'
                             ' a size of %s, got %s') %
                             (mySize, mySize, myActualSize))
                assert mySize == myActualSize, myMessage
                mySize += 1
Example #2
0
 def test_issue230(self):
     """Verify that we give informative errors when style is not correct
        .. seealso:: https://github.com/AIFDR/inasafe/issues/230
     """
     myPath = unitTestDataPath('impact')
     myVectorLayer, myType = loadLayer('polygons_for_styling.shp', myPath)
     del myType
     myStyle = {'legend_title': u'Population Count',
                'target_field': 'population',
                'style_classes':
                [{'transparency': 0,
                  'min': [0],  # <-- intentionally broken list not number!
                  'max': 139904.08186340332,
                  'colour': '#FFFFFF',
                  'size': 1,
                  'label': u'Nil'},
                 {'transparency': 0,
                  'min': 139904.08186340332,
                  'max': 279808.16372680664,
                  'colour': '#38A800',
                  'size': 1,
                  'label': u'Low'},
                 {'transparency': 0,
                  'min': 279808.16372680664,
                  'max': 419712.24559020996,
                  'colour': '#79C900',
                  'size': 1,
                  'label': u'Low'},
                 {'transparency': 0,
                  'min': 419712.24559020996,
                  'max': 559616.32745361328,
                  'colour': '#CEED00',
                  'size': 1,
                  'label': u'Low'},
                 {'transparency': 0,
                  'min': 559616.32745361328,
                  'max': 699520.4093170166,
                  'colour': '#FFCC00',
                  'size': 1,
                  'label': u'Medium'},
                 {'transparency': 0,
                  'min': 699520.4093170166,
                  'max': 839424.49118041992,
                  'colour': '#FF6600',
                  'size': 1,
                  'label': u'Medium'},
                 {'transparency': 0,
                  'min': 839424.49118041992,
                  'max': 979328.57304382324,
                  'colour': '#FF0000',
                  'size': 1,
                  'label': u'Medium'},
                 {'transparency': 0,
                  'min': 979328.57304382324,
                  'max': 1119232.6549072266,
                  'colour': '#7A0000',
                  'size': 1,
                  'label': u'High'}]}
     try:
         setVectorGraduatedStyle(myVectorLayer, myStyle)
     except StyleError:
         # Exactly what should have happened
         return
     except Exception, e:
         print str(e)