0

In my project I have a SLD style which contain Transformation function. The SLD style is looks like this:

<PointSymbolizer>
    <Fill>
        <CssParameter name="fill">
            <ogc:Function name="Recode">
                <ogc:PropertyName>nature</ogc:PropertyName>
                <ogc:Literal>Commercial</ogc:Literal>
                <ogc:Literal>#ba0d5a</ogc:Literal>
                <ogc:Literal>Residential</ogc:Literal>
                <ogc:Literal>#ba0d5a</ogc:Literal>
            </ogc:Function>
        </CssParameter>
    </Fill>
</PointSymbolizer>

The output of the above looks like this:

enter image description here

So the map is showing properly, but I need to display LegendGraphic also. But requesting LegendGraphic is returning only one symbol

enter image description here

How to get legend based on different attribute?

EDIT :: For your reference this is my complete SLD file

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0"
    xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
    xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
    xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <NamedLayer>
        <Name>MadhyamgramGIS:apartment</Name>
        <UserStyle>
            <Title>Dynamic Apartment Layer</Title>
            <Abstract>Dynamic style for point layer</Abstract>
            <FeatureTypeStyle>
                <Rule>
                    <Name>Rule1</Name>
                    <Title>Apartment Layer</Title>
                    <Abstract>Point Rule</Abstract>
                    <PointSymbolizer>
                        <Graphic>
                            <Mark>
                                <WellKnownName>circle</WellKnownName>
                                <Fill>
                                    <CssParameter name="fill">
                                        <ogc:Function name="Recode">
                                            <ogc:PropertyName>nature</ogc:PropertyName>
                                            <ogc:Literal>Commercial</ogc:Literal>
                                            <ogc:Literal>#ba0d5a</ogc:Literal>
                                            <ogc:Literal>Residential</ogc:Literal>
                                            <ogc:Literal>#ba0d5a</ogc:Literal>
                                        </ogc:Function>
                                    </CssParameter>
                                </Fill>
                                <Stroke>
                                    <CssParameter name="stroke">
                                        <ogc:Function name="Recode">
                                            <ogc:PropertyName>nature</ogc:PropertyName>
                                            <ogc:Literal>Commercial</ogc:Literal>
                                            <ogc:Literal>#B0C4DE</ogc:Literal>
                                            <ogc:Literal>Residential</ogc:Literal>
                                            <ogc:Literal>#16e023</ogc:Literal>
                                        </ogc:Function>
                                    </CssParameter>
                                    <CssParameter name="stroke-width">
                                        <ogc:Function name="Recode">
                                            <ogc:PropertyName>nature</ogc:PropertyName>
                                            <ogc:Literal>Commercial</ogc:Literal>
                                            <ogc:Literal>1</ogc:Literal>
                                            <ogc:Literal>Residential</ogc:Literal>
                                            <ogc:Literal>2</ogc:Literal>
                                        </ogc:Function>
                                    </CssParameter>
                                </Stroke>
                            </Mark>
                            <Size>12</Size>
                        </Graphic>
                    </PointSymbolizer>
                </Rule>
            </FeatureTypeStyle>
        </UserStyle>
    </NamedLayer>
</StyledLayerDescriptor>
0

You have multiple choices. I provide more or less what the URL should look like but they are not working URLs

  1. You will need to provide a reference to your SLD like for your getMap call.

    http://localhost:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=topp:states&SLD=your_path_to_remote_sld

  2. You can provide the SLD body if necessary

    http://localhost:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=topp:states&SLD_BODY=your_sld_file_content_inlined

  3. You can also provide a style name as long as it's available as an alternate style for your layer internally in your GeoServer admin.

    http://localhost:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=topp:states&STYLE=your_style_name_if_available_as_alternate_style_for_the_layer

These informations were deduced from Get Legend Graphic documentation

  • I tried everything you provided but all return a single[one] symbol as i said in my question. I really need the all symbol displaying with my layer – atanu Jul 25 '18 at 6:06
0

I tried this problem using different <rule> for different attribute param. Now the SLD file is look like this

<FeatureTypeStyle>
    <Rule>
        <Title>Commercial</Title>
        <ogc:Filter>
            <ogc:PropertyIsEqualTo>
                <ogc:PropertyName>nature</ogc:PropertyName>
                <ogc:Literal>Commercial</ogc:Literal>
            </ogc:PropertyIsEqualTo>
        </ogc:Filter>
        <PointSymbolizer>
            <Graphic>
                <Mark>
                    <WellKnownName>circle</WellKnownName>
                    <Fill>
                        <CssParameter name="fill">#ba0d5a</CssParameter>
                    </Fill>
                    <Stroke>
                        <CssParameter name="stroke">#B0C4DE</CssParameter>
                        <CssParameter name="stroke-width">1</CssParameter>
                    </Stroke>
                </Mark>
                <Size>12</Size>
            </Graphic>
        </PointSymbolizer>
    </Rule>
    <Rule>
       <Title>Residential</Title>
        <ogc:Filter>
            <ogc:PropertyIsEqualTo>
                <ogc:PropertyName>nature</ogc:PropertyName>
                <ogc:Literal>Residential</ogc:Literal>
            </ogc:PropertyIsEqualTo>
        </ogc:Filter>
        <PointSymbolizer>
            <Graphic>
                <Mark>
                    <WellKnownName>triangle</WellKnownName>
                    <Fill>
                        <CssParameter name="fill">#B0C4DE</CssParameter>
                    </Fill>
                    <Stroke>
                        <CssParameter name="stroke">#ba0d5a</CssParameter>
                        <CssParameter name="stroke-width">1</CssParameter>
                    </Stroke>
                </Mark>
                <Size>10</Size>
            </Graphic>
        </PointSymbolizer>
    </Rule>
</FeatureTypeStyle>

Now call to GeoServer using @ThomasG77 answer provide me my requested Legend.

But using rule doesn't display other symbol with doesn't match with the rule, i.e. if their is another nature 'Commercial & Residential' for which i didn't defined any rule that does not display on GetMap

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.