forked from MapServer/MapServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwxs.py
More file actions
64 lines (43 loc) · 1.46 KB
/
wxs.py
File metadata and controls
64 lines (43 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
"""
Output WMS GetCapabilities response for a Mapfile
Usage:
python wxs.py test.map
"""
import sys
import xml.dom.minidom
import mapscript
def main(map_file):
map = mapscript.mapObj(map_file)
map.web.metadata.set("ows_onlineresource", "http://dummy.org/")
ows_req = mapscript.OWSRequest()
ows_req.type = mapscript.MS_GET_REQUEST
ows_req.setParameter("SERVICE", "WMS")
ows_req.setParameter("VERSION", "1.1.0")
ows_req.setParameter("REQUEST", "GetCapabilities")
mapscript.msIO_installStdoutToBuffer()
dispatch_status = map.OWSDispatch(ows_req)
if dispatch_status != mapscript.MS_SUCCESS:
print("An error occurred")
content_type = mapscript.msIO_stripStdoutBufferContentType()
mapscript.msIO_stripStdoutBufferContentHeaders()
result = mapscript.msIO_getStdoutBufferBytes()
# [('Content-Type', 'application/vnd.ogc.wms_xml; charset=UTF-8'), ('Content-Length', '11385')]
response_headers = [
("Content-Type", content_type),
("Content-Length", str(len(result))),
]
assert int(response_headers[1][1]) > 0
dom = xml.dom.minidom.parseString(result)
print(dom.toprettyxml(indent="", newl=""))
def usage():
"""
Display usage if program is used incorrectly
"""
print("Syntax: %s <mapfile_path>" % sys.argv[0])
sys.exit(2)
# make sure a filename argument is provided
if len(sys.argv) != 2:
usage()
map_file = sys.argv[1]
main(map_file)