0

I created a modified PointStacker which stacks/clusters the data features according to an indicated attribute of the data set (e.g. state or district) which is a user-indicated parameter in the sld style file.

When I am looking at the entire map extent, it works fine. For instance, I have 20 states and for each of them a cluster point with its number of clustered features is displayed. However, when I zoom into the map, and a state is not completely within the view anymore, the input data for this state is less than before, thus, the number of clustered features for this state is getting less as well - which is not my intended behaviour for this case. I do not want to cluster only the features within the view, but to cluster the entire data extent - independetly from my zoom level, thus view extent.

Is there any way to accomplish something like a constant data bounding box to request data from independently from zooming?

<?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>xyz</Name>
    <UserStyle>
      <Title>xyz</Title>
      <FeatureTypeStyle>
        <Transformation>
          <ogc:Function name="gs:PointStackerAttribute">
            <ogc:Function name="parameter">
              <ogc:Literal>data</ogc:Literal>
            </ogc:Function>
            <ogc:Function name="parameter">
              <ogc:Literal>clusterattribute</ogc:Literal>
              <ogc:Literal>state</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>
        ...
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

1 Answer 1

1

I used an SQL view (https://docs.geoserver.org/stable/en/user/data/database/sqlview.html) instead of the modified PointStacker, thus, compared to the PointStacker approach I prepared the data as I need them in advance.

  1. In GeoServer, Create new layer page
  2. Select your database, and remember your desired table that is now listed (e.g. name_tbl)
  3. Configure new SQL view…, and group by the desired attribute such as state.
SELECT state, 
       ST_PointOnSurface(
           ST_Collect(
             the_geom
          )) as the_geom, 
       count(state) as COUNT
FROM name_tbl
GROUP BY state
  1. Refresh attributes, if necessary, set Geometry (Point) and SRID
  2. Save
  3. Set bounding boxes (e.g. compute from data), and Save layer
  4. Create a new style for this layer (and do not forget to add this style in publishing to the layer)
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
                       xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/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>name-style</Name>
    <UserStyle>
      <Title>name-style</Title>
      <FeatureTypeStyle>
        <Rule>
          <Title>name-style</Title>
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>square</WellKnownName>
                <Fill>
                  <CssParameter name="fill">#fa8072</CssParameter>
                </Fill>
              </Mark>
              <Size>6</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.6</AnchorPointX>
                  <AnchorPointY>0</AnchorPointY>
                </AnchorPoint>
              </PointPlacement>
            </LabelPlacement>
            <Halo>
              <Radius>1</Radius>
              <Fill>
                <CssParameter name="fill">#FFFFFF</CssParameter>
                <CssParameter name="fill-opacity">0.9</CssParameter>
              </Fill>
            </Halo>
            <Fill>
              <CssParameter name="fill">#000000</CssParameter>
              <CssParameter name="fill-opacity">1.0</CssParameter>
            </Fill>
          </TextSymbolizer> 
        </Rule>

      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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