def _as_classification(classification, queryset, field, nclasses, geofield='<STR_LIT>', <EOL>propertyname=None, userstyletitle=None, featuretypestylename=None, colorbrewername='<STR_LIT>',<EOL>invertgradient=False, **kwargs):
thesld = StyledLayerDescriptor()<EOL>ftype = queryset.model._meta.get_field_by_name(geofield)[<NUM_LIT:0>]<EOL>if isinstance(ftype, fields.LineStringField) or isinstance(ftype, fields.MultiLineStringField):<EOL><INDENT>symbolizer = LineSymbolizer<EOL><DEDENT>elif isinstance(ftype, fields.PolygonField) or isinstance(ftype, fields.MultiPolygonField):<EOL><INDENT>symbolizer = PolygonSymbolizer<EOL><DEDENT>else:<EOL><INDENT>symbolizer = PointSymbolizer<EOL><DEDENT>if propertyname is None:<EOL><INDENT>propertyname = field<EOL><DEDENT>nl = thesld.create_namedlayer('<STR_LIT>' % (nclasses, field, classification.__name__))<EOL>us = nl.create_userstyle()<EOL>if not userstyletitle is None:<EOL><INDENT>us.Title = str(userstyletitle)<EOL><DEDENT>fts = us.create_featuretypestyle()<EOL>if not featuretypestylename is None:<EOL><INDENT>fts.Name = str(featuretypestylename)<EOL><DEDENT>if nclasses == <NUM_LIT:1>:<EOL><INDENT>rule = fts.create_rule(propertyname, symbolizer=symbolizer)<EOL>shade = <NUM_LIT:0> if invertgradient else <NUM_LIT:255><EOL>shade = '<STR_LIT>' % (shade, shade, shade,)<EOL>if symbolizer == PointSymbolizer:<EOL><INDENT>rule.PointSymbolizer.Graphic.Mark.Fill.CssParameters[<NUM_LIT:0>].Value = shade<EOL><DEDENT>elif symbolizer == LineSymbolizer:<EOL><INDENT>rule.LineSymbolizer.Stroke.CssParameters[<NUM_LIT:0>].Value = shade<EOL><DEDENT>elif symbolizer == PolygonSymbolizer:<EOL><INDENT>rule.PolygonSymbolizer.Stroke.CssParameters[<NUM_LIT:0>].Value = '<STR_LIT>'<EOL>rule.PolygonSymbolizer.Fill.CssParameters[<NUM_LIT:0>].Value = shade<EOL><DEDENT>thesld.normalize()<EOL>return thesld<EOL><DEDENT>datavalues = array(queryset.order_by(field).values_list(field, flat=True))<EOL>q = classification(datavalues, nclasses, **kwargs)<EOL>shades = None<EOL>if q.k == nclasses and colorbrewername and not colorbrewername == '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>import colorbrewer<EOL>shades = getattr(colorbrewer, colorbrewername)[nclasses]<EOL>if invertgradient:<EOL><INDENT>shades.reverse()<EOL><DEDENT><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>for i,qbin in enumerate(q.bins):<EOL><INDENT>if type(qbin) == ndarray:<EOL><INDENT>qbin = qbin[<NUM_LIT:0>]<EOL><DEDENT>title = '<STR_LIT>' % qbin<EOL>rule = fts.create_rule(title, symbolizer=symbolizer)<EOL>if shades:<EOL><INDENT>shade = '<STR_LIT>' % shades[i]<EOL><DEDENT>else:<EOL><INDENT>shade = (float(q.k - i) / q.k ) * <NUM_LIT:255><EOL>if invertgradient:<EOL><INDENT>shade = <NUM_LIT:255> - shade<EOL><DEDENT>shade = '<STR_LIT>' % (shade, shade, shade,)<EOL><DEDENT>if symbolizer == PointSymbolizer:<EOL><INDENT>rule.PointSymbolizer.Graphic.Mark.Fill.CssParameters[<NUM_LIT:0>].Value = shade<EOL><DEDENT>elif symbolizer == LineSymbolizer:<EOL><INDENT>rule.LineSymbolizer.Stroke.CssParameters[<NUM_LIT:0>].Value = shade<EOL><DEDENT>elif symbolizer == PolygonSymbolizer:<EOL><INDENT>rule.PolygonSymbolizer.Stroke.CssParameters[<NUM_LIT:0>].Value = '<STR_LIT>'<EOL>rule.PolygonSymbolizer.Fill.CssParameters[<NUM_LIT:0>].Value = shade<EOL><DEDENT>if i > <NUM_LIT:0>:<EOL><INDENT>f_low = Filter(rule)<EOL>f_low.PropertyIsGreaterThan = PropertyCriterion(f_low, '<STR_LIT>')<EOL>f_low.PropertyIsGreaterThan.PropertyName = propertyname<EOL>f_low.PropertyIsGreaterThan.Literal = str(q.bins[i-<NUM_LIT:1>])<EOL><DEDENT>f_high = Filter(rule)<EOL>f_high.PropertyIsLessThanOrEqualTo = PropertyCriterion(f_high, '<STR_LIT>')<EOL>f_high.PropertyIsLessThanOrEqualTo.PropertyName = propertyname<EOL>f_high.PropertyIsLessThanOrEqualTo.Literal = str(qbin)<EOL>if i > <NUM_LIT:0>:<EOL><INDENT>rule.Filter = f_low + f_high<EOL><DEDENT>else:<EOL><INDENT>rule.Filter = f_high<EOL><DEDENT><DEDENT>thesld.normalize()<EOL>return thesld<EOL>
Accept a queryset of objects, and return the values of the class breaks 
on the data distribution. If the queryset is empty, no class breaks are
computed.

@type  classification: pysal classifier
@param classification: A classification class defined in 
    pysal.esda.mapclassify. As of version 1.0.1, this list is comprised of:

      - Equal_Interval
      - Fisher_Jenks
      - Jenks_Caspall
      - Jenks_Caspall_Forced
      - Jenks_Caspall_Sampled
      - Max_P_Classifier
      - Maximum_Breaks
      - Natural_Breaks
      - Quantiles

@type  queryset: QuerySet
@param queryset: The query set that contains the entire distribution of data values.
@type     field: string
@param    field: The name of the field on the model in the queryset that contains the data values.
@type  nclasses: integer
@param nclasses: The number of class breaks desired.
@type  geofield: string
@keyword geofield: The name of the geography column on the model. Defaults to 'geom'
@type  propertyname: string
@keyword propertyname: The name of the filter property name, if different from the model field.
@type  userstyletitle: string
@keyword userstyletitle: The title of the UserStyle element.
@type  featuretypestylename: string
@keyword featuretypestylename: The name of the FeatureTypeStyle element.
@type    colorbrewername: string
@keyword colorbrewername: The name of a colorbrewer ramp name. Must have the same # of corresponding classes as nclasses.
@type    invertgradient: boolean
@keyword invertgradient: Should the resulting SLD have colors from high to low, instead of low to high?
@type    kwargs: keywords
@param   kwargs: Additional keyword arguments for the classifier.
@rtype: L{sld.StyledLayerDescriptor}
@returns: An SLD class object that represents the classification scheme 
    and filters.