Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runsub MapScript functions #5857

Merged
merged 3 commits into from
Sep 22, 2019

Conversation

geographika
Copy link
Member

This pull request adds a applyDefaultSubstitutions function to all SWIG MapScripts, and an applySubstitutions function to Python MapScript along with an appropriate typemap.

Usage is as follows - applyDefaultSubstitutions can be called directly on a mabObj:

        s = """
MAP
    WEB
        VALIDATION
            'key1' '.*'
            'default_key1' 'Test Title'
        END
        METADATA
            "wms_title" "%key1%"
        END
    END
END
        """
        map = mapscript.fromstring(s)
        map.applyDefaultSubstitutions()

applySubstitutions can be used in Python by supplying a dict of keys and values (both need to be strings) to replace any variables in a Mapfile.

        s = """
MAP
    WEB
        VALIDATION
            'key1' '.*'
            'default_key1' 'Test Title'
        END
        METADATA
            "wms_title" "%key1%"
        END
    END
    LAYER
        TYPE POINT
        FILTER ([size]<%my_filter%)
        VALIDATION
            'my_filter' '^[0-9]$'
        END
    END
END
        """
        map = mapscript.fromstring(s)

        d = {"key1": "New Title", "my_filter": "3"}
        map.applySubstitutions(d)

@geographika geographika merged commit 95ddad7 into MapServer:master Sep 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant