1

I have and SLD with following rule

<se:Rule>
      <se:Name>Primary Pole</se:Name>
      <se:Description>
        <se:Title>Primary Pole</se:Title>
      </se:Description>
      <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
        <ogc:PropertyIsEqualTo>
          <ogc:PropertyName>type</ogc:PropertyName>
          <ogc:Literal>type1</ogc:Literal>
        </ogc:PropertyIsEqualTo>
      </ogc:Filter>
      <se:PointSymbolizer>
        <se:Graphic>            
          <se:ExternalGraphic>
            <se:OnlineResource xlink:type="simple" xlink:href="svgs/type1.svg"/>
            <se:Format>image/svg+xml</se:Format>
          </se:ExternalGraphic>             
          <se:Size>16</se:Size>
        </se:Graphic>
      </se:PointSymbolizer>
    </se:Rule>

and for creating the base64 representation of this rule i am using below code

 // assuming we  will provide only point
 BufferedImage image = null;
 image = Glyph.point(rule);
 ByteArrayOutputStream bos = new ByteArrayOutputStream();
 ImageIO.write(image, "png", bos);
 Base64.Encoder encoder = Base64.getEncoder();
 String imageString = encoder.encodeToString(bos.toByteArray());

but issue is the when i show it on client when height and width is 16 image is displayed fine but when i increase the height and width the generated base64 image is blured (pixelated) what i think its generated the image w.r.t the size in rule is there any option to ignore it and provide my own size? Or is there a better way to generate the legend.

1

This is actually much harder than it looks - see GeoServer's BufferedImageLegendGraphicBuilder class for the full gory detail. The key step seems to be the method calcSymbolSize:

    private double[] calcSymbolSize(
        double defaultMaxSize,
        double defaultMinSize,
        FeatureType featureType,
        Feature feature,
        final Rule[] rules) {
    // check for max and min size in rendered symbols
    double minSize = defaultMaxSize;
    double maxSize = defaultMinSize;

    final int ruleCount = rules.length;
    for (int i = 0; i < ruleCount; i++) {
        Feature sample = getSampleFeatureForRule(featureType, feature, rules[i]);
        MetaBufferEstimator estimator = new MetaBufferEstimator(sample);
        final Symbolizer[] symbolizers = rules[i].getSymbolizers();
        for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) {
            final Symbolizer symbolizer = symbolizers[sIdx];
            if (symbolizer instanceof PointSymbolizer || symbolizer instanceof LineSymbolizer) {
                double size = getSymbolizerSize(estimator, symbolizer, defaultMaxSize);
                // a line symbolizer is depicted as a line of the requested size, so don't go
                // below min
                if (size < minSize && !(symbolizer instanceof LineSymbolizer)) {
                    minSize = size;
                }
                if (size > maxSize) {
                    maxSize = size;
                }
            }
        }
    }
    return new double[] {minSize, maxSize};
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.