I'm trying to perform pgRouting with MapServer so I've created a function in PostGIS and the call it in map file with runtime substitution. The DATA part is as follows:

DATA "geom FROM (SELECT * FROM routing_func(%source% , %target%)) AS foo USING UNIQUE seq using srid=2100" 

My validation section in the map file is:

        "source" "[0-9]+"
         "target" "[0-9]+"

and the CLASS object:

        NAME 'routing'
        EXPRESSION "%source% && %target%"
            COLOR 255 0 0
            WIDTH 4

I try to pass the parameters in map mode with the following request:

but nothing is drawn for the route that was supposed to be calculated.

If I try the OpenLayers template like:

The MS_ERRORFILE gives me the following error:

Error (ERROR:  syntax error at or near "%"
LINE 1: ...d, source, target, time as cost FROM roads_noded',%source%,%...

What am I missing here?


Your EXPRESSION part looks a little funny. Why do you need that?

First of all, I think you need a CLASSITEM which would be a filed to match against. Even then you "%source% && %target%" doesn't make sense.

What happens if you remove that.

Regarding your validation, I think it should work, however to insure only digits are in string, I would do instead:

    'source' '^[0-9]+$'
    'target' '^[0-9]+$'
  • When you say "Why do I need the expression" you mean it really doesn't need to be there or it's malformed? I thought that the expression says what should be substituted. Yeah I had a hunch about the CLASSITEM but I'm not sure what should I put there... – Stefanos Jan 15 '17 at 20:14
  • The variable name tells what should be substituted. If depends on the use case where to use substitution but you have it in DATA and I suppose that it is enough. Draw everything that gets selected and no classitem nor expression should be needed. – user30184 Jan 15 '17 at 21:21
  • I removed classitem and expression and only left VALIDATION as indicated in the answer ("source" "^[0-9]+$"). I'm trying it minimally at the moment so I leave a random number in the target variable and only substitute the source putting a number in the url like &source=12. Unfortunately I still get the same error: Error (ERROR: syntax error at or near "%" LINE 1: ...hex') as geom,"seq" from (SELECT * FROM _a_router(%source%, ... – Stefanos Jan 15 '17 at 22:02
  • It's almost as if your validation rules are being ignored. Where did you put the VALIDATION .. END. In your layer definition I presume? If not put it in as part of your layer definition. I should add I've only used mapserver with SERVICE=WMS and variable substitution has worked for me. I presume it should work in mode=map as well, though haven't tried. – LR1234567 Jan 15 '17 at 23:28
  • One other question just to rule out you are using a version that doesn't support substitution. What does mapserv -v (run that on command line) return? – LR1234567 Jan 15 '17 at 23:33

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.