[MapServer-users] Use SCALETOKEN in FILTER?

Jesper Kempe jesper.kempe at gmail.com
Wed Feb 12 06:13:39 PST 2025


Hi

I am trying to show different levels of details based on zoom level in a
map based on Natural earth 10m data (ne_10m_lakes.zip from
https://www.naturalearthdata.com/downloads/10m-physical-vectors/) using the
attribute scalerank in the shape file.

My plan was to use SCALETOKEN to replace the value in a FILTER with the
current max scalerank to use.
But I cant get it to work. Nothing is shown in the map.

Should it be possible to use a scaletoken in a filter expresssion?

Looking at https://mapserver.org/development/rfc/ms-rfc-86.html#discussion
it looks like it at least was planned to work?

Now I get errors like this in the log file:

[Wed Feb 12 13:50:20 2025].23938 replacing scaletoken (%ne_scalerank%) with
(5) in layer->filter (ne_10m_lakes) for scale=221471921.250000
[Wed Feb 12 13:50:20 2025].24460 msEvalExpression(): General error message.
Cannot evaluate expression, no item index defined.
[Wed Feb 12 13:50:20 2025].24474 msEvalExpression(): General error message.
Cannot evaluate expression, no item index defined.
[Wed Feb 12 13:50:20 2025].24482 msEvalExpression(): General error message.
Cannot evaluate expression, no item index defined.

Using this mapfile:
MAP
    CONFIG "MS_ERRORFILE" "ms_error.txt"

    STATUS ON

    PROJECTION
        "init=epsg:4326"
    END

    EXTENT -180 -90 180 90

    WEB
        METADATA
            "wms_title"           "WMS Demo Server"
            "wms_srs"             "EPSG:4326"
            "wms_enable_request"  "*"
        END
    END

    LAYER
        DEBUG 5
        NAME 'ne_10m_lakes'

        TYPE POLYGON
        PROJECTION
            "init=epsg:4326"
        END
        EXTENT -180 -90 180 90
        DATA "ne_10m_lakes.shp"

        SCALETOKEN
            NAME "%ne_scalerank%"
            VALUES
                "0" "10"
                "1000" "8"
                "10000000" "5"
            END # VALUES
        END # SCALETOKEN

        FILTER ([scalerank] < %ne_scalerank% )

        CLASS
            STYLE
                OUTLINECOLOR "#647078"
                WIDTH 1
                COLOR "#EBEEF0"
            END
        END

    END

END

For this request
https://myserver/wms?&service=WMS&request=GetMap&layers=ne_10m_lakes&styles=&format=image%2Fpng&transparent=false&version=1.1.1&map=ne_10m_lakes.map&height=512&width=512&srs=EPSG%3A4326&bbox=-180,-90,180,90

Worth noting is if I replace FILTER ([scalerank] < %ne_scalerank% ) with
FILTER ([scalerank] < 5 ) in the mapfile it works fine.

Anyone with thoughts or ideas on how this can be solved?

I am on Mapserver 7.6.4.

Thanks,
Jesper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20250212/0fe2de51/attachment.htm>


More information about the MapServer-users mailing list