@staticmethod
    def generate_style(geolevel, qset, nclasses, subject=None, layername=None):
        """
        Generate SLD content for a queryset. This uses quantile classification
        for nclasses classes, using the 'Greys' colorbrewer palette, on an inverted
        gradient. The queryset is assumed to be all the geounits in a geolevel.
        The subject is an instance of the Subject model.
        """
        if subject:
            qset = qset.filter(characteristic__subject=subject)
            us_title = subject.get_short_label()
        else:
            us_title = layername
            
        qset = qset.annotate(Avg('characteristic__number'))

        doc = generator.as_quantiles(qset, 'characteristic__number__avg', nclasses, propertyname='number',
            userstyletitle=us_title, colorbrewername='Greys', invertgradient=False)

        # set the width of the borders to 0.25 by default
        strokes = doc._node.xpath('//sld:Stroke', namespaces=doc._nsmap)
        for stroke in strokes:
            node = stroke.xpath('sld:CssParameter[@name="stroke-width"]', namespaces=doc._nsmap)[0]
            node.text = '0.25'

        if subject:
            # set the name of the layer
            node = doc._node.xpath('//sld:NamedLayer/sld:Name', namespaces=doc._nsmap)[0]
            node.text = subject.name

        elif nclasses == 1:
            # remove any fill if subject is missing
            fill = doc._node.xpath('//sld:Fill', namespaces=doc._nsmap)[0]
            fill.getparent().remove(fill)
        
            if layername:
                # set the name of the layer
                name = doc._node.xpath('//sld:Name', namespaces=doc._nsmap)[0]
                name.text = layername
        
                # set the title of the user style
                name = doc._node.xpath('//sld:UserStyle/sld:Title', namespaces=doc._nsmap)[0]
                name.text = geolevel.get_long_description()
        
                # set the title of the rule
                name = doc._node.xpath('//sld:Rule/sld:Title', namespaces=doc._nsmap)[0]
                name.text = _('Boundary')

                if layername == 'boundary':
                    stroke = doc._node.xpath('//sld:Stroke', namespaces=doc._nsmap)[0]
                    node = stroke.xpath('sld:CssParameter[@name="stroke-width"]', namespaces=doc._nsmap)[0]
                    node.text = '3'

                    node = stroke.xpath('sld:CssParameter[@name="stroke"]', namespaces=doc._nsmap)[0]
                    node.text = '#2BB673'

                    strokeopacity = {'name':'stroke-opacity'}
                    node = stroke.makeelement('{%s}CssParameter' % doc._nsmap['sld'], attrib=strokeopacity, nsmap=doc._nsmap)
                    node.text = '0.45'

                    stroke.append(node)


        return doc.as_sld()
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/config.py/SpatialUtils.generate_style/original