1

Writing a SLD file to style a Points layer which I publish as WMS with GeoServer, is it possible to specify a rule that is only applied to the first and last features in the underlying PostGIS table?

The table is sorted by means of that the point features represent a road track which has a start- and endpoint. My goal is to use a specific style for the start- and endpoint, different from how all the other points are styled. However, the table's length is dynamic so that the first feature will always have featureid==1 but the last one is unknown in advance and thus cannot be hard-coded.

Is there any possibility in SLD to filter for the first and last feature in a column? Naturally, the features of interest have the lowest and highest featureIDs out of all features so something like min(featureid) and max(featureid) would also work, if available.

Access to the database table could also be provided if it is possible in any way to filter for the result of a SQL query like SELECT min(featureID).

This part of the documentation refers to functions called startPoint and endPoint but apparently these can only style the start- and endpoint of a linestring, not the first and last point out of a column of points.

0

Meanwhile I found a way how this can be achieved, using variable substitution in the WMS GetMap request.

In my PostGIS table that stores the data queried by the WMS requests, there is a column called featureno which stores the information of interest - the geometries with the lowest and highest values in this columns should be visualized differently to all the others.

I get the lowest value from this database column in my table called myTableName with

SELECT
    featureno
FROM
    myTableName
WHERE
    featureno = (SELECT min(featureno) from myTableName)
;

respectively, the highest with

SELECT
    featureno
FROM
    myTableName
WHERE
    featureno = (SELECT max(featureno) from myTableName)
;

In the SLD file that GeoServer is using to style the data, I added the following to use a specific *.png file for styling the first/last point (the only thing to chance accordingly is <ogc:Literal>lowestID</ogc:Literal> and the reference to the correct image file):

<sld:FeatureTypeStyle>
<sld:Rule>
  <sld:Title>FirstPoint</sld:Title>  
  <ogc:Filter>
    <ogc:PropertyIsEqualTo>
      <ogc:PropertyName>featureno</ogc:PropertyName>
        <ogc:Function name="env">
          <ogc:Literal>lowestID</ogc:Literal>
        </ogc:Function>
    </ogc:PropertyIsEqualTo>
  </ogc:Filter>
  <sld:PointSymbolizer>
    <sld:Graphic>
      <sld:ExternalGraphic>
        <sld:OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="first_point.png"/>
        <sld:Format>image/png</sld:Format>
      </sld:ExternalGraphic>
    </sld:Graphic>
  </sld:PointSymbolizer>
</sld:Rule>
</sld:FeatureTypeStyle> 

The important part is

<ogc:PropertyIsEqualTo>
  <ogc:PropertyName>featureno</ogc:PropertyName>
    <ogc:Function name="env">
      <ogc:Literal>lowestID</ogc:Literal>
    </ogc:Function>
</ogc:PropertyIsEqualTo>

which allows to set the filter for featureno according to an environment variable called lowestID which is passed via the GetMap request URL.

Now, when you found out the desired feature(s) with the SQL queries given above, the variable can be appended to your GetMap request in whatever language you are using to send your requests (e.g. JavaScript, Python, ...). The format is:

&env=lowestID:myValue;highestID:myOtherValue

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.