Exemplo n.º 1
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])
Exemplo n.º 2
0
    def testQgsClassificationFixedIntervalInvalidInterval(self):
        values = [-33, -41, -43, 16, 29, 9, -35, 57, 26, -30]
        vl = createMemoryLayer(values)
        m = QgsClassificationFixedInterval()
        m.setParameterValues({'INTERVAL': 0})

        r = m.classes(vl, 'value', 4)
        self.assertEqual(len(r), 1)
        self.assertEqual(QgsClassificationMethod.rangesToBreaks(r), [57.0])
Exemplo n.º 3
0
    def testQgsClassificationJenksSimple(self):
        # This is a simple Natural Breaks Jenks test checking if simple calculation can be done
        # when number of values is below 3000 (value hardcoded in qgsclassificationjenks.h)
        # And if returned values are consistent (the same as at the time of creation of this test)
        values = [-33, -41, -43, 16, 29, 9, -35, 57, 26, -30]
        vl = createMemoryLayer(values)
        m = QgsClassificationJenks()

        r = m.classes(vl, 'value', 4)
        self.assertEqual(len(r), 4)
        self.assertEqual(QgsClassificationMethod.rangesToBreaks(r),
                         [-30.0, 16.0, 29.0, 57.0])
Exemplo n.º 4
0
    def testQgsClassificationJenksHighNumber(self):
        # This test checks if Jenkis classification does not crash when number of
        # values in a set is higher than 3000 (value hardcoded in qgsclassificationjenks.h)
        # And if returned values are consistent (the same as at the time of creation of this test)
        random.seed(42 * 42)
        values = [random.randint(-1000, 1000) for _ in range(5000)]
        vl = createMemoryLayer(values)
        m = QgsClassificationJenks()

        r = m.classes(vl, 'value', 4)
        self.assertEqual(len(r), 4)
        self.assertEqual(QgsClassificationMethod.rangesToBreaks(r),
                         [-506.0, -4.0, 499.0, 1000.0])
Exemplo n.º 5
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])
Exemplo n.º 6
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)