[mapserver-users] passing variables to includes

lars.schylberg at blixtmail.se lars.schylberg at blixtmail.se
Fri Oct 13 04:40:33 PDT 2017


Hi Jörg,

I also had this same thought and it would be a good mechanism. 
But I solved it with my own preprocessing. 

I have been doing Nautical charts with Mapserver for a 
couple of years and realized that I was reusing 
the same layers up to 18 times.  

So I did templates where I had LAYER->NAME, LAYER->GROUP, 
LAYER->DATA and STYLE->COLOR as variables in Mapserver templates.  
Color for instance has fixed names like “DEPVS”, 
that means depth very shallow.  
But depending on if it is day mode, dawn dusk mode or night mode 
the colors have different rgb or hex values.  
All variables are stored in csv files.  The variables are read into 
associative arrays in a bash script.  Then  I use my Mapserver 
mapfile templates that are processed with a very long sed statement 
that substitutes the variables depending on color mode and scale level.   

Layer names and groups have one csv file that tells how to 
assemble all the layers.  To make it even more flexible, I can 
also use offical IHO colors, Swedish or French color tables 
to get different look and feel.

An example is for instance the layer template for rivers:

#### Rivers Lines ####

LAYER
    NAME  "Rivers_line_{CL}"
    GROUP "{GROUP}"
    METADATA
        "ows_title"   "Rivers"
        "ows_enable_request"   "*"
        "gml_include_items" "all"
        "wms_feature_mime_type" "text/html"
    END
    TEMPLATE blank.html
    TYPE LINE
    STATUS ON
    MAXSCALEDENOM {MAXSCALE}
    DATA "{PATH}"
    CLASS
        NAME "Rivers (lines)"
        STYLE
           # DEPVS
           # RGB # COLOR {DEPVS_rgb}
           COLOR "{DEPVS}"
           WIDTH 1.5
           # RGB # COLOR {OUTLL_rgb}
           OUTLINECOLOR "{OUTLL}"
           OUTLINEWIDTH 0.3
        END
    END
END


All this can be seen in the git hub:  https://github.com/LarsSchy/SMAC-M 
I finally got permission from my company to release it this summer, so that we can discuss this.
I would like to do a demo site with open data, but haven't had time to do this yet.

The script: process_layer_color.sh shows the real processing part and the sed script. 

https://github.com/LarsSchy/SMAC-M/blob/master/chart-installation/generate_map_files/scripts/process_layer_colors.sh

Have fun 

Lars Schylberg
Saab AB


-----Originalmeddelande----- 
> Från: "Jörg Thomsen (WhereGroup)" <joerg.thomsen at wheregroup.com> 
> Till: mapserver-users at lists.osgeo.org 
> Datum: 2017-10-13 09:43 
> Ämne: [mapserver-users] passing variables to includes 
> 
> Hi,
> 
> I had a MapServer Training this week and one of the participations asks
> a nice question:
> 
> Is it possible to pass variables to includes? I think this is a very
> good idea, it could save a lot of includefiles. In know it's very close
> to mapscript, but has anyone done this without?
> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20171013/e34d4837/attachment-0001.html>


More information about the mapserver-users mailing list