Mercurial > mxd2map
comparison contrib/python/generateHTML.py @ 208:0c58db91311c
* contrib/python/generateHTML.py: New. Script for generating a
HTML-page with links to mapfiles. Useful when converting a bunch
of MXD-files to mapfiles in order to test.
It generates an OpenLayers-Link for every included layer though.
author | Stephan Holl <stephan.holl@intevation.de> |
---|---|
date | Fri, 22 Jul 2011 09:45:47 +0200 |
parents | |
children | d0acdab62b03 |
comparison
equal
deleted
inserted
replaced
207:448a2fd085e0 | 208:0c58db91311c |
---|---|
1 #!/usr/bin/env python | |
2 # | |
3 # (C) 2011, Intevation GmbH, Stephan Holl <stephan.holl@intevation.de> | |
4 # | |
5 # | |
6 # Generate a HTML-Page based on a recursive folder structure of generated | |
7 # mapfiles from MXD2map | |
8 # | |
9 # | |
10 # Usage: generateHTML.py > output.html | |
11 | |
12 | |
13 import os | |
14 | |
15 # this is intended to run in the folder where the generates mapfiles are | |
16 # stored: | |
17 rootdir = os.getcwd() + '/map-test-2' | |
18 debug = False | |
19 | |
20 # adopt for you needs: | |
21 url = 'http://localhost/cgi-bin/mapserv.exe' | |
22 getmap = url + '?Request=GetMap&Service=WMS&Version=1.1.1' | |
23 getmap += '&srs=EPSG:4326&width=800&height=600&format=image/png&styles=' | |
24 | |
25 def writeHeader(): | |
26 print '''<html> | |
27 <head> | |
28 <title>MXD2map-examples</title> | |
29 <style> | |
30 body { | |
31 font-family: arial, sans-serif; | |
32 font-size: 12pt; | |
33 } | |
34 </style> | |
35 </head> | |
36 <body> | |
37 <h1>Verfuegbare MXD-Dateien</h1> | |
38 ''' | |
39 | |
40 def writeFooter(): | |
41 content = "</body></html>" | |
42 print content | |
43 | |
44 def writeLayers(mapfile, layers, extent): | |
45 basename = os.path.basename(mapfile) | |
46 print '''<li>Layer: <strong>%s</strong></li> | |
47 <br> | |
48 Anzahl der Layer: %s | |
49 ''' % (basename, len(layers)) | |
50 i = 0 | |
51 print "<ul>" | |
52 while i < len(layers): | |
53 urlmapfile = url + '?map=' + mapfile | |
54 urlmapfile += '&template=openlayers&mode=browse&layers=' + layers[i] | |
55 gm = getmap + '&map=' + mapfile + '&layers=' + layers[i] | |
56 if extent: | |
57 ext = str(extent).strip('[\'\'\\r\\n]') | |
58 gm += '&bbox='+''.join(ext) | |
59 print "<li><a target='_new' href='%s'>%s</a> | <a target='_new' href='%s'>WMS GetMap</a></li>" % (urlmapfile, layers[i], gm) | |
60 i=i+1 | |
61 print "</ul>" | |
62 | |
63 def writeGroups(mapfile,groups): | |
64 if len(groups) > 1: | |
65 print "Anzahl der Gruppen: %s" % len(groups) | |
66 i = 0 | |
67 print "<ul>" | |
68 while i < len(groups): | |
69 urlmapfile = url + '?map=' + mapfile | |
70 urlmapfile += '&template=openlayers&mode=browse&layers=' + groups[i] | |
71 print "<li><a href='%s'>%s</a></li>" % (urlmapfile, groups[i]) | |
72 i=i+1 | |
73 print "</ul>" | |
74 | |
75 def main(): | |
76 writeHeader() | |
77 for root, subFolders, files in os.walk(rootdir): | |
78 for file in files: | |
79 f = os.path.join(root, file) | |
80 if os.path.isfile(f): | |
81 basename, extension = os.path.splitext(f) | |
82 if extension.lower() == ".map": | |
83 if "orig" in f: | |
84 # do not generate links for -orig.map-files | |
85 continue | |
86 if debug: | |
87 print "Bearbeite Dokument %s" % f | |
88 #read file and search for wms_title | |
89 layers = [] | |
90 groups = [] | |
91 extent = [] | |
92 for line in open(f): | |
93 if "wms_title" in line: | |
94 #print line | |
95 la = line.strip()[12:].replace('"','') | |
96 if la != "Layers": | |
97 layers.append(la) | |
98 if "GROUP" in line: | |
99 gr = line.strip()[6:].replace('"','') | |
100 if gr not in groups: | |
101 groups.append(gr) | |
102 if "EXTENT" in line: | |
103 ext = line[9:].replace('"','').replace(' ', ',') | |
104 extent.append(ext) | |
105 | |
106 print "<ul>" | |
107 writeLayers(f, layers, extent) | |
108 print "</ul>" | |
109 | |
110 # write groups | |
111 print "<ul>" | |
112 writeGroups(f, groups) | |
113 print "</ul>" | |
114 if debug: | |
115 print "Layer %s hat %s Layer" % (f, len(layers)) | |
116 print "Layer %s hat %s Gruppen" % (f, len(groups)) | |
117 | |
118 writeFooter() | |
119 | |
120 main() |