Skip to content

Commit

Permalink
mapscript: add an optional version parameter for map.generateSLD()
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 24, 2019
1 parent 6dbece4 commit 1681765
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 40 deletions.
67 changes: 39 additions & 28 deletions mapscript/python/tests/cases/map_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,16 @@ class MapRunSubTestCase(MapTestCase):

def testDefaultSubstitutions(self):
s = """
MAP
WEB
VALIDATION
'key1' '.*'
'default_key1' 'Test Title'
END
METADATA
"wms_title" "%key1%"
END
END
MAP
WEB
VALIDATION
'key1' '.*'
'default_key1' 'Test Title'
END
METADATA
"wms_title" "%key1%"
END
END
END
"""
map = mapscript.fromstring(s)
Expand All @@ -353,33 +353,44 @@ def testRuntimeSubstitutions(self):
For supported parameters see https://mapserver.org/cgi/runsub.html#parameters-supported
"""
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
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"}
d = {"key1": "New Title", "my_filter": "3"}
map.applySubstitutions(d)

assert map.web.metadata["wms_title"] == "New Title"
assert map.getLayer(0).getFilterString() == "([size]<3)"


class MapSLDTestCase(MapTestCase):
def test(self):

test_map = mapscript.mapObj(TESTMAPFILE)
result = test_map.generateSLD()
assert result.startswith('<StyledLayerDescriptor version="1.0.0"'), result

result = test_map.generateSLD("1.1.0")
assert result.startswith('<StyledLayerDescriptor version="1.1.0"'), result


if __name__ == '__main__':
unittest.main()
24 changes: 12 additions & 12 deletions mapscript/swiginc/map.i
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@
}

%newobject generateSLD;
char *generateSLD() {
return (char *) msSLDGenerateSLD(self, -1, NULL);
char *generateSLD(char *sldVersion=NULL) {
return (char *) msSLDGenerateSLD(self, -1, sldVersion);
}


Expand Down Expand Up @@ -513,20 +513,20 @@
%feature("docstring") applyDefaultSubstitutions
"Apply any default values
defined in a VALIDATION block used for runtime substitutions"
void applyDefaultSubstitutions()
{
msApplyDefaultSubstitutions(self);
}

void applyDefaultSubstitutions()
{
msApplyDefaultSubstitutions(self);
}

%feature("autodoc", "3");
%feature("docstring") applySubstitutions
"Pass in runtime substitution
keys and values and apply them to the map.
**Note** This method is currently enabled for Python only.
Typemaps are needed for other mapscript languages."
void applySubstitutions(char **names, char **values, int npairs)
{
msApplySubstitutions(self, names, values, npairs);
**Note** This method is currently enabled for Python only.
Typemaps are needed for other mapscript languages."
void applySubstitutions(char **names, char **values, int npairs)
{
msApplySubstitutions(self, names, values, npairs);
}
}

0 comments on commit 1681765

Please sign in to comment.