1

I want to use present year in a CLASS in a map file. I managed to write permanent expressions like:

LAYER
    CLASSITEM "YEAR"
...
    CLASS
        NAME "Previous years"
        EXPRESSION ('[YEAR]'<'2015')

But I failed to construct a working expression, which includes a reference to present time.

There is an example of what I would like to write:

LAYER
CLASSITEM "YEAR"
...
    CLASS
        NAME "Present year" # Year n
        EXPRESSION ('[YEAR]'=='([date format=YYYY]'))
...
    CLASS
        NAME "Previous year" # Year n-1
        EXPRESSION ('[YEAR]'=='([date format=YYYY]'-'1'))
...
    CLASS
        NAME "Archived years" # Years <n-1
        EXPRESSION ('[YEAR]'<'([date format=YYYY]'-'1'))

I adapted [date format=YYYY] expression from a MapServer template page.It didn't work.... But unfortunately I did find no simple examples of templates imported variables direct use in a map file, especially for [date] variables.

Has someone any idea of what it could look like? I'm just looking for reusable examples that I could adapt for my scripts.

  • 1
    By reading the same page as you mapserver.org/mapfile/template.html I would rather try with [data format="%Y"]. I would also read some reference to strftime() for example linux.die.net/man/3/strftime – user30184 Feb 5 '16 at 13:19
  • When you say it didn't work, what error do you get? Are you saying that nothing matches your expression? Does your attribute table contain a YEAR attribute? CLASSITEM [attribute] Item name in attribute table to use for class lookups. – nmtoken Apr 2 '16 at 10:50
1

I have an example that is working, (in the sense that mapserver does not make a timeout statement).

I have been investigating sources of documentation from Template.General, here I've found the syntax behind structuring the DATE-tag.

@user30184 posted this webpage, a manpage that explains the structure of the C-type syntax that "DATE"-tag is build upon.

Finally I've added a logical expression because the expression is supposed to work within two limitations of time:

("[*NAMEOFCOLUMN*]" gt "DATE format = %Y-%m-%d" && "[*NAMEOFCOLUMN*]" lt "DATE format = %Y-%m-%d")

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.