예제 #1
0
파일: tests.py 프로젝트: azavea/django-sld
    def test_related_fields(self):
        """
        Test the queryset and style generation using django related fields
        syntax.
        """
        sld = generator.as_quantiles(Pipeline.objects.filter(material='ceramic'), 'reservoir__volume', 5, geofield='path')
        self.assertEqual(len(sld.NamedLayer.UserStyle.FeatureTypeStyle.Rules), 5)

        sld = generator.as_quantiles(Hydrant.objects.filter(pressure=1), 'pipeline__diameter', 5, geofield='location')
        self.assertEqual(len(sld.NamedLayer.UserStyle.FeatureTypeStyle.Rules), 5)

        sld = generator.as_quantiles(Hydrant.objects.filter(pressure=1), 'pipeline__reservoir__volume', 5, geofield='location')
        self.assertEqual(len(sld.NamedLayer.UserStyle.FeatureTypeStyle.Rules), 5)
예제 #2
0
파일: tests.py 프로젝트: azavea/django-sld
    def test_q_classes_poly(self):
        """
        Test the Quantiles classifier for a polygon-based geographic model.
        """
        sld = generator.as_quantiles(Reservoir.objects.filter(name__startswith='City'), 'volume', 5, geofield='coastline')

        self.assertEqual(len(sld.NamedLayer.UserStyle.FeatureTypeStyle.Rules), 5)

        sld = generator.as_quantiles(Reservoir.objects.filter(name__startswith='County'), 'volume', 5, geofield='coastline')

        literals = sld._node.xpath('//ogc:PropertyIsLessThanOrEqualTo/ogc:Literal',namespaces=sld._nsmap)
        expected = ['1168000.0', '4246000.0', '9244000.0', '16162000.0', '25000000.0']

        for i,n in enumerate(literals):
            self.assertEqual(n.text, expected[i], 'Class %d is not correct.' % i)
예제 #3
0
파일: tests.py 프로젝트: azavea/django-sld
    def test_q_classes_ln(self):
        """
        Test the Quantiles classifier for a line-based geographic model.
        """
        sld = generator.as_quantiles(Pipeline.objects.filter(material='ceramic'), 'diameter', 5, geofield='path')

        self.assertEqual(len(sld.NamedLayer.UserStyle.FeatureTypeStyle.Rules), 5)

        sld = generator.as_quantiles(Pipeline.objects.filter(material='concrete'), 'diameter', 5, geofield='path')

        literals = sld._node.xpath('//ogc:PropertyIsLessThanOrEqualTo/ogc:Literal',namespaces=sld._nsmap)
        expected = ['9.8', '19.6', '29.4', '39.2', '49.0']

        for i,n in enumerate(literals):
            self.assertEqual(n.text, expected[i], 'Class %d is not correct.' % i)
예제 #4
0
파일: tests.py 프로젝트: azavea/django-sld
    def test_q_classes_pt(self):
        """
        Test the Quantiles classifier for a point-based geographic model.
        """
        sld = generator.as_quantiles(Hydrant.objects.filter(pressure=1), 'number', 5, geofield='location')

        self.assertEqual(len(sld.NamedLayer.UserStyle.FeatureTypeStyle.Rules), 5)

        sld = generator.as_quantiles(Hydrant.objects.filter(pressure=2), 'number', 5, geofield='location')

        literals = sld._node.xpath('//ogc:PropertyIsLessThanOrEqualTo/ogc:Literal',namespaces=sld._nsmap)
        expected = ['96.2', '384.4', '864.6', '1536.8', '2401.0']

        for i,n in enumerate(literals):
            self.assertEqual(n.text, expected[i], 'Class %d is not correct.' % i)
예제 #5
0
파일: tests.py 프로젝트: azavea/django-sld
    def test_invert_gradient(self):
        """
        Test the generation of an inverted gradient.
        """

        # First, test the regular gradient
        sld = generator.as_quantiles(Hydrant.objects.filter(pressure=2), 'number', 5, geofield='location', invertgradient=False)
        self.assertEqual(len(sld.NamedLayer.UserStyle.FeatureTypeStyle.Rules), 5)

        literals = sld._node.xpath('//ogc:PropertyIsLessThanOrEqualTo/ogc:Literal',namespaces=sld._nsmap)
        expected = ['96.2', '384.4', '864.6', '1536.8', '2401.0']

        for i,n in enumerate(literals):
            self.assertEqual(n.text, expected[i], 'Class %d is not correct.' % i)

        shades = sld._node.xpath('//sld:Fill/sld:CssParameter[@name="fill"]',namespaces=sld._nsmap)
        self.assertEquals(len(shades), 5)

        expected = [(255, 255, 255), (204, 204, 204), (153, 153, 153), (102, 102, 102), (51, 51, 51)]

        for i,n in enumerate(shades):
            exp_shade = '#%02x%02x%02x' % expected[i]
            self.assertEqual(n.text, exp_shade, 'Shade %d is not correct. Expected: "%s" / Actual: "%s"' % (i, exp_shade, n.text,))

        # Second, test the inverted gradient
        sld = generator.as_quantiles(Hydrant.objects.filter(pressure=2), 'number', 5, geofield='location', invertgradient=True)
        self.assertEqual(len(sld.NamedLayer.UserStyle.FeatureTypeStyle.Rules), 5)

        literals = sld._node.xpath('//ogc:PropertyIsLessThanOrEqualTo/ogc:Literal',namespaces=sld._nsmap)
        expected = ['96.2', '384.4', '864.6', '1536.8', '2401.0']

        for i,n in enumerate(literals):
            self.assertEqual(n.text, expected[i], 'Class %d is not correct.' % i)

        shades = sld._node.xpath('//sld:Fill/sld:CssParameter[@name="fill"]',namespaces=sld._nsmap)
        self.assertEquals(len(shades), 5)

        expected = [(0, 0, 0), (51, 51, 51), (102, 102, 102), (153, 153, 153), (204, 204, 204)]

        for i,n in enumerate(shades):
            exp_shade = '#%02x%02x%02x' % expected[i]
            self.assertEqual(n.text, exp_shade, 'Shade %d is not correct.' % i)
예제 #6
0
파일: tests.py 프로젝트: azavea/django-sld
    def test_inverted_colorbrewer(self):
        """
        Test the generation of shades using colorbrewer names, and inverted.
        """
        sld = generator.as_quantiles(Hydrant.objects.filter(pressure=2), 'number', 5, geofield='location', 
            colorbrewername='Greys', invertgradient=True)
        self.assertEqual(len(sld.NamedLayer.UserStyle.FeatureTypeStyle.Rules), 5)

        expected = [(37, 37, 37), (99, 99, 99), (150, 150, 150), (204, 204, 204), (247, 247, 247)]

        shades = sld._node.xpath('//sld:Fill/sld:CssParameter[@name="fill"]',namespaces=sld._nsmap)
        self.assertEqual(len(shades), 5)

        for i,n in enumerate(shades):
            exp_shade = '#%02x%02x%02x' % expected[i]
            self.assertEqual(n.text, exp_shade, 'Shade %d is not correct.' % i)