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