[mapserver-users] Implementing a WMS ORDERBY Parameter

Seth G sethg at geographika.co.uk
Fri Apr 10 08:32:25 PDT 2020


Hi list,

Following on from a discussion on implementing a SORTBY parameter for WMS requests on the dev lists [1], I have a workaround that may be useful to some. 

This resolves WMS image requests producing different results if a consistent feature order isn't applied. A sort order can be hardcoded into a LAYER DATA clause, but this then means sorting using a WFS SORTBY parameter to the same layer is ignored. 

My current solution is to add a new runtime-substitution parameter (with validation to check for a single word) and then add this dynamically to an ORDER BY clause. The trick is to add a ORDER BY (SELECT NULL) as the default value for any requests to the layer not using the parameter. I'm not sure how different database drivers implement this in the DATA clause so it may need some tweaking. The example below works with the MSSQL driver. 

    DATA "GEOM FROM (
        SELECT *
        FROM myview
    ) 
    AS tbl USING UNIQUE fid USING SRID=3857 ORDER BY %ORDERBY%"

    VALIDATION
        "ORDERBY" "(^[A-Za-z]+$)"
        "default_ORDERBY" "(SELECT NULL)"
    END

A client WMS can then simply add ORDERBY=MyFieldName to ensure consistent results. 

Seth

[1] https://lists.osgeo.org/pipermail/mapserver-dev/2020-February/016071.html

--
web:http://geographika.co.uk
twitter: @geographika


More information about the mapserver-users mailing list