Example #1
0
    def testQgsClassificationLogarithmic_FilterZeroNeg(self):
        values = [-2, 0, 1, 7, 66, 555, 4444]

        vl = createMemoryLayer(values)

        m = QgsClassificationLogarithmic()
        m.setParameterValues({'FILTER_ZERO_NEG_VALUES': True})
        r = m.classes(vl, 'value', 4)

        self.assertEqual(len(r), 4)
        self.assertEqual(r[0].label(), '1 - 10^1')
        self.assertEqual(QgsClassificationMethod.rangesToBreaks(r),
                         [10.0, 100.0, 1000.0, 10000.0])
    def testQgsClassificationLogarithmicCloseMinimum(self):
        """See issue GH #45454: Incorrect scale range legend after applying
        logarithmic graduated symbology to a vector layer"""

        values = [
            0.009900019065438, 0.010851322017611, 0.01755707784994,
            0.031925433036994, 0.046422733606398
        ]

        vl = createMemoryLayer(values)

        m = QgsClassificationLogarithmic()
        r = m.classes(vl, 'value', 4)

        classes = [(c.lowerBound(), c.upperBound()) for c in r]

        for l, h in classes:
            self.assertLess(l, h)
Example #3
0
    def testQgsClassificationLogarithmic(self):
        values = [
            2746.71, 66667.49, 77282.52, 986567.01, 1729508.41, 9957836.86,
            35419826.29, 52584164.80, 296572842.00
        ]

        vl = createMemoryLayer(values)

        m = QgsClassificationLogarithmic()
        r = m.classes(vl, 'value', 8)

        self.assertEqual(len(r), 6)
        self.assertEqual(r[0].label(),
                         '{} - 10^4'.format(QLocale().toString(2746.71)))
        self.assertEqual(QgsClassificationMethod.rangesToBreaks(r), [
            10000.0, 100000.0, 1000000.0, 10000000.0, 100000000.0, 1000000000.0
        ])

        self.assertEqual(len(m.classes(vl, 'value', 4)), 4)
Example #4
0
    def testQgsClassificationLogarithmic(self):
        values = [2746.71,
                  66667.49,
                  77282.52,
                  986567.01,
                  1729508.41,
                  9957836.86,
                  35419826.29,
                  52584164.80,
                  296572842.00]

        vl = createMemoryLayer(values)

        m = QgsClassificationLogarithmic()
        r = m.classes(vl, 'value', 9)

        self.assertEqual(r.count(), 6)
        self.assertEqual(r[0].label(), '2746.71 - 10^4')
        self.assertEqual(QgsClassificationMethod.listToValues(r),
                         [10000.0, 100000.0, 1000000.0, 10000000.0, 100000000.0, 1000000000.0])

        self.assertEqual(m.classes(vl, 'value', 4).count(), 4)
Example #5
0
    def testQgsClassificationLogarithmic_FilterZeroNeg(self):
        values = [-2, 0, 1, 7, 66, 555, 4444]
        vl = createMemoryLayer(values)
        m = QgsClassificationLogarithmic()

        m.setParameterValues({'ZERO_NEG_VALUES_HANDLE': QgsClassificationLogarithmic.Discard})
        r = m.classes(vl, 'value', 4)
        self.assertEqual(len(r), 4)
        self.assertEqual(r[0].label(), '1 - 10^1')
        self.assertEqual(QgsClassificationMethod.rangesToBreaks(r), [10.0, 100.0, 1000.0, 10000.0])

        m.setParameterValues({'ZERO_NEG_VALUES_HANDLE': QgsClassificationLogarithmic.PrependBreak})
        r = m.classes(vl, 'value', 4)
        self.assertEqual(r[0].label(), '-2 - 10^0')
        self.assertEqual(QgsClassificationMethod.rangesToBreaks(r), [1.0, 10.0, 100.0, 1000.0, 10000.0])