Exemplo n.º 1
0
    def test_filter_or(self):
        """
        Test the construction of a logical-or Filter.
        """
        sld_doc = copy.deepcopy(self._sld1)
        namedlayer = sld_doc.create_namedlayer('test named layer')
        userstyle = namedlayer.create_userstyle()
        featuretypestyle = userstyle.create_featuretypestyle()
        rule = featuretypestyle.create_rule('test rule', sld.PointSymbolizer)

        filter1 = sld.Filter(rule)
        filter1.PropertyIsGreaterThan = sld.PropertyCriterion(
            filter1, 'PropertyIsGreaterThan')
        filter1.PropertyIsGreaterThan.PropertyName = 'number'
        filter1.PropertyIsGreaterThan.Literal = '10'

        filter2 = sld.Filter(rule)
        filter2.PropertyIsLessThan = sld.PropertyCriterion(
            filter2, 'PropertyIsLessThan')
        filter2.PropertyIsLessThan.PropertyName = 'number'
        filter2.PropertyIsLessThan.Literal = '-10'

        rule.Filter = filter1 | filter2

        expected = """<sld:Rule xmlns:sld="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ogc="http://www.opengis.net/ogc"><sld:Title>test rule</sld:Title><sld:PointSymbolizer><sld:Graphic><sld:Mark><sld:WellKnownName>square</sld:WellKnownName><sld:Fill><sld:CssParameter name="fill">#ff0000</sld:CssParameter></sld:Fill></sld:Mark></sld:Graphic></sld:PointSymbolizer><ogc:Filter><ogc:Or><ogc:PropertyIsGreaterThan><ogc:PropertyName>number</ogc:PropertyName><ogc:Literal>10</ogc:Literal></ogc:PropertyIsGreaterThan><ogc:PropertyIsLessThan><ogc:PropertyName>number</ogc:PropertyName><ogc:Literal>-10</ogc:Literal></ogc:PropertyIsLessThan></ogc:Or></ogc:Filter></sld:Rule>"""
        actual = etree.tostring(rule._node, with_tail=False)
        self.assertEqual(actual, expected.encode('utf-8'))

        sld_doc.normalize()
        self.assertTrue(sld_doc.validate())
Exemplo n.º 2
0
    def _render_classBreaks(self, featureTypeStyle):
        field = self.renderer.get('field')
        minValue = str(self.renderer.get('minValue'))
        classBreakInfos = self.renderer.get('classBreakInfos')
        scales = self._convert_esriScales()

        for classBreakInfo in classBreakInfos:
            rule_label = classBreakInfo.get('label')
            classMaxValue = str(classBreakInfo.get('classMaxValue'))

            rule = featureTypeStyle.create_rule(
                rule_label,
                MinScaleDenominator=scales.get('max_scale'),
                MaxScaleDenominator=scales.get('min_scale'))
            del rule.PointSymbolizer

            filter1 = sld.Filter(rule)
            filter1.PropertyIsGreaterThanOrEqualTo = sld.PropertyCriterion(
                filter1, 'PropertyIsGreaterThanOrEqualTo')
            filter1.PropertyIsGreaterThanOrEqualTo.PropertyName = field
            filter1.PropertyIsGreaterThanOrEqualTo.Literal = minValue

            filter2 = sld.Filter(rule)
            filter2.PropertyIsLessThanOrEqualTo = sld.PropertyCriterion(
                filter2, 'PropertyIsLessThanOrEqualTo')
            filter2.PropertyIsLessThanOrEqualTo.PropertyName = field
            filter2.PropertyIsLessThanOrEqualTo.Literal = classMaxValue

            rule.Filter = filter1 + filter2
            minValue = classMaxValue

            symbol = classBreakInfo.get('symbol')
            symbol_type = symbol.get('type')

            converter = self._determine_type_converter(symbol_type)
            converter(rule, symbol)
Exemplo n.º 3
0
    def _render_esriGeometryPoint(self, featureTypeStyle):
        # min_scale = str(self.descriptor.get('minScale'))
        # max_scale = str(self.descriptor.get('maxScale'))

        renderer_type = self.drawingInfo.get('renderer').get('type')

        if renderer_type == "simple":
            rule_label = self.name

            rule = featureTypeStyle.create_rule(rule_label,
                                                sld.PointSymbolizer)

            del rule.PointSymbolizer

            symbol = self.drawingInfo.get('renderer').get('symbol')

            symbol_type = symbol.get('type')

            converter = self._determine_type_converter(symbol_type)
            converter(rule, symbol)

        if renderer_type == "uniqueValue":
            field1 = self.drawingInfo.get('renderer').get('field1')
            uniqueValueInfos = self.drawingInfo.get('renderer').get(
                'uniqueValueInfos')

            for uniqueValue in uniqueValueInfos:
                label = uniqueValue.get('label')
                value = uniqueValue.get('value')
                symbol = uniqueValue.get('symbol')

                rule = featureTypeStyle.create_rule(label, sld.PointSymbolizer)
                del rule.PointSymbolizer

                rule.create_filter(field1, '==', value)

                symbol_type = symbol.get('type')
                converter = self._determine_type_converter(symbol_type)
                converter(rule, symbol)

        if renderer_type == "classBreaks":
            field = self.drawingInfo.get('renderer').get('field')
            minValue = self.drawingInfo.get('renderer').get('minValue')
            minValue = str(minValue)

            classBreakInfos = self.drawingInfo.get('renderer').get(
                'classBreakInfos')

            for classBreakInfo in classBreakInfos:
                classMaxValue = str(classBreakInfo.get('classMaxValue'))
                label = classBreakInfo.get('label')
                symbol = classBreakInfo.get('symbol')

                rule = featureTypeStyle.create_rule(label, sld.PointSymbolizer)
                del rule.PointSymbolizer

                filter1 = sld.Filter(rule)
                filter1.PropertyIsGreaterThanOrEqualTo = sld.PropertyCriterion(
                    filter1, 'PropertyIsGreaterThanOrEqualTo')
                filter1.PropertyIsGreaterThanOrEqualTo.PropertyName = field
                filter1.PropertyIsGreaterThanOrEqualTo.Literal = minValue

                filter2 = sld.Filter(rule)
                filter2.PropertyIsLessThanOrEqualTo = sld.PropertyCriterion(
                    filter2, 'PropertyIsLessThanOrEqualTo')
                filter2.PropertyIsLessThanOrEqualTo.PropertyName = field
                filter2.PropertyIsLessThanOrEqualTo.Literal = classMaxValue

                rule.Filter = filter1 + filter2
                minValue = classMaxValue

                symbol_type = symbol.get('type')
                converter = self._determine_type_converter(symbol_type)
                converter(rule, symbol)