I am currently evaluation different options to aggregate/cluster point data which is made available to users as a GeoServer layer via standard protocols (WMS, WMTS, WFS).
The idea is to group nearby points at low zoom levels, and show individual points when zooming in. The output should also be in a structured format (i.e. not raster images), so individual points/clusters can be selected in a client app.
A DB is used as the data store for this layer. Unless it is necessary performance or feature wise, I would prefer not to directly expose the DB to users or client apps.
To aggregate points on the server I tried a WMS request with a rendering transformation (pointstacker) as described here: Transforms — GeoServer 2.27.x User Manual.
The WMS request in MVT format without the rendering transformation succeeds, and I can inspect the output and visualize it e.g. in OpenLayers. This output contains all individual points.
With the rendering transformation applied, I can see the results only in raster output format (PNG). This output is clustered as expected and shown in the documentation.
With MVT, the output is empty, as confirmed using curl and OpenLayers/web browser network analysis tool. The curl command I used for testing is:
curl 'http://localhost:8080/geoserver/wms?REQUEST=GetMap&SERVICE=WMS&VERSION=1.3.0&FORMAT=application%2Fvnd.mapbox-vector-tile&STYLES=es_test%3Apointstacker&TRANSPARENT=true&CRS=EPSG%3A3857&LAYERS=es_test%3Ags_test&TILED=false&WIDTH=256&HEIGHT=256&BBOX=1565430.3392804079%2C5948635.289265556%2C1878516.4071364899%2C6261721.357121638' --output test.mvt
The GeoServer style es_test:pointstacker is defined as:
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>vol_stacked_point</Name>
<UserStyle>
<!-- Styles can have names, titles and abstracts -->
<Title>Stacked Point</Title>
<Abstract>Styles volcanoes using stacked points</Abstract>
<FeatureTypeStyle>
<Transformation>
<ogc:Function name="vec:PointStacker">
<ogc:Function name="parameter">
<ogc:Literal>data</ogc:Literal>
</ogc:Function>
<ogc:Function name="parameter">
<ogc:Literal>cellSize</ogc:Literal>
<ogc:Literal>30</ogc:Literal>
</ogc:Function>
<ogc:Function name="parameter">
<ogc:Literal>outputBBOX</ogc:Literal>
<ogc:Function name="env">
<ogc:Literal>wms_bbox</ogc:Literal>
</ogc:Function>
</ogc:Function>
<ogc:Function name="parameter">
<ogc:Literal>outputWidth</ogc:Literal>
<ogc:Function name="env">
<ogc:Literal>wms_width</ogc:Literal>
</ogc:Function>
</ogc:Function>
<ogc:Function name="parameter">
<ogc:Literal>outputHeight</ogc:Literal>
<ogc:Function name="env">
<ogc:Literal>wms_height</ogc:Literal>
</ogc:Function>
</ogc:Function>
</ogc:Function>
</Transformation>
<Rule>
<Name>rule1</Name>
<Title>Volcano</Title>
<ogc:Filter>
<ogc:PropertyIsLessThanOrEqualTo>
<ogc:PropertyName>count</ogc:PropertyName>
<ogc:Literal>1</ogc:Literal>
</ogc:PropertyIsLessThanOrEqualTo>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>triangle</WellKnownName>
<Fill>
<CssParameter name="fill">#FF0000</CssParameter>
</Fill>
</Mark>
<Size>8</Size>
</Graphic>
</PointSymbolizer>
</Rule>
<Rule>
<Name>rule29</Name>
<Title>2-9 Volcanoes</Title>
<ogc:Filter>
<ogc:PropertyIsBetween>
<ogc:PropertyName>count</ogc:PropertyName>
<ogc:LowerBoundary>
<ogc:Literal>2</ogc:Literal>
</ogc:LowerBoundary>
<ogc:UpperBoundary>
<ogc:Literal>9</ogc:Literal>
</ogc:UpperBoundary>
</ogc:PropertyIsBetween>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#AA0000</CssParameter>
</Fill>
</Mark>
<Size>14</Size>
</Graphic>
</PointSymbolizer>
<TextSymbolizer>
<Label>
<ogc:PropertyName>count</ogc:PropertyName>
</Label>
<Font>
<CssParameter name="font-family">Arial</CssParameter>
<CssParameter name="font-size">12</CssParameter>
<CssParameter name="font-weight">bold</CssParameter>
</Font>
<LabelPlacement>
<PointPlacement>
<AnchorPoint>
<AnchorPointX>0.5</AnchorPointX>
<AnchorPointY>0.8</AnchorPointY>
</AnchorPoint>
</PointPlacement>
</LabelPlacement>
<Halo>
<Radius>2</Radius>
<Fill>
<CssParameter name="fill">#AA0000</CssParameter>
<CssParameter name="fill-opacity">0.9</CssParameter>
</Fill>
</Halo>
<Fill>
<CssParameter name="fill">#FFFFFF</CssParameter>
<CssParameter name="fill-opacity">1.0</CssParameter>
</Fill>
</TextSymbolizer>
</Rule>
<Rule>
<Name>rule10</Name>
<Title>10 Volcanoes</Title>
<ogc:Filter>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>count</ogc:PropertyName>
<ogc:Literal>9</ogc:Literal>
</ogc:PropertyIsGreaterThan>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#AA0000</CssParameter>
</Fill>
</Mark>
<Size>22</Size>
</Graphic>
</PointSymbolizer>
<TextSymbolizer>
<Label>
<ogc:PropertyName>count</ogc:PropertyName>
</Label>
<Font>
<CssParameter name="font-family">Arial</CssParameter>
<CssParameter name="font-size">12</CssParameter>
<CssParameter name="font-weight">bold</CssParameter>
</Font>
<LabelPlacement>
<PointPlacement>
<AnchorPoint>
<AnchorPointX>0.5</AnchorPointX>
<AnchorPointY>0.8</AnchorPointY>
</AnchorPoint>
</PointPlacement>
</LabelPlacement>
<Halo>
<Radius>2</Radius>
<Fill>
<CssParameter name="fill">#AA0000</CssParameter>
<CssParameter name="fill-opacity">0.9</CssParameter>
</Fill>
</Halo>
<Fill>
<CssParameter name="fill">#FFFFFF</CssParameter>
<CssParameter name="fill-opacity">1.0</CssParameter>
</Fill>
</TextSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
Currently I do not know if I am missing something or if this expected behavior. My questions regarding this topic and GeoServer right now are:
- Is it possible via WMS to request the result of this rendering transformation in MVT?
- Are there other methods to cluster point data server-side, and retrieve the result in a structured format using standard protocols?