GeoServer SLD – How to Conditionally Display Points or Polygons by Zoom Level

geoserversld

This is not a duplicate of: how to display polygons as points until certain zoom level?

I want to do this with Geoserver v2.5.5 if possible (not openlayers).

Basically – I have a layer of polygons, which look great when zoomed in, but are nigh on impossible to see when zoomed out to a reasonable level.

I've tried using SLD to add a heavier stroke weight to the poly's, but it just looks rubbish (I get these weird looking triangles that are in no way representative of the poly). So I've come the conclusion that I'll need to display points instead when user is zoomed out.

I understand that I could just publish two layers and handle the conditional zoom logic client side – but, c'mon! Surely Geoserver should do the heavy lifting for me 😉

So bottom line – is it possible to publish a layer in Geoserver that will display points at one zoom level, and poly's at another?

EDIT:

Just to clarify: I don't need an actual point geometry, I just need to style polygon geometries to display like points at certain zoom levels.

Best Answer

If you style your polygon with a point symbolizer it will be displayed by a point. So all you need is two symbolizers (one point, one polygon) in a pair of rules with scale constraints on them.

EDIT:

Here's a simple SLD example:

<FeatureTypeStyle>
    <Rule>
        <MaxScaleDenominator>500000</MaxScaleDenominator>
        <PolygonSymbolizer>
            <Fill>
                <CssParameter name="fill">rgba(255, 255, 255, 0)</CssParameter>
            </Fill>
            <Stroke>
                <CssParameter name="stroke">#FF4000</CssParameter>
                <CssParameter name="stroke-width">1</CssParameter>
            </Stroke>
        </PolygonSymbolizer>
    </Rule>
    <Rule>
        <MinScaleDenominator>500000</MinScaleDenominator>
        <PointSymbolizer>
            <Graphic>
                <Mark>
                    <WellKnownName>circle</WellKnownName>
                    <Fill>
                        <CssParameter name="fill">#FF0000</CssParameter>
                    </Fill>
                </Mark>
                <Size>10</Size>
            </Graphic>
        </PointSymbolizer>
    </Rule>
</FeatureTypeStyle>