diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contrib/python/generateHTML.py	Fri Jul 22 09:45:47 2011 +0200
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+#
+# (C) 2011, Intevation GmbH, Stephan Holl <stephan.holl@intevation.de>
+#
+#
+# Generate a HTML-Page based on a recursive folder structure of generated
+# mapfiles from MXD2map
+#
+#
+# Usage: generateHTML.py > output.html
+
+
+import os
+
+# this is intended to run in the folder where the generates mapfiles are
+# stored:
+rootdir = os.getcwd() + '/map-test-2'
+debug = False
+
+# adopt for you needs:
+url = 'http://localhost/cgi-bin/mapserv.exe'
+getmap  = url + '?Request=GetMap&Service=WMS&Version=1.1.1'
+getmap += '&srs=EPSG:4326&width=800&height=600&format=image/png&styles='
+
+def writeHeader():
+    print '''<html>
+<head>
+<title>MXD2map-examples</title>
+<style>
+body {
+    font-family: arial, sans-serif;
+    font-size: 12pt;
+}
+</style>
+</head>
+<body>
+<h1>Verfuegbare MXD-Dateien</h1>
+'''
+
+def writeFooter():
+    content = "</body></html>"
+    print content
+
+def writeLayers(mapfile, layers, extent):
+    basename = os.path.basename(mapfile)
+    print '''<li>Layer:  <strong>%s</strong></li>
+<br>
+Anzahl der Layer: %s
+''' % (basename, len(layers))
+    i = 0
+    print "<ul>"
+    while i < len(layers):
+        urlmapfile  = url + '?map=' + mapfile
+        urlmapfile += '&template=openlayers&mode=browse&layers=' + layers[i]
+        gm  = getmap + '&map=' + mapfile + '&layers=' + layers[i]
+        if extent:
+            ext = str(extent).strip('[\'\'\\r\\n]')
+            gm += '&bbox='+''.join(ext)
+        print "<li><a target='_new' href='%s'>%s</a> | <a target='_new' href='%s'>WMS GetMap</a></li>" % (urlmapfile, layers[i], gm) 
+        i=i+1
+    print "</ul>"
+
+def writeGroups(mapfile,groups):
+    if len(groups) > 1:
+        print "Anzahl der Gruppen: %s" % len(groups)
+        i = 0
+        print "<ul>"
+        while i < len(groups):
+            urlmapfile  = url + '?map=' + mapfile
+            urlmapfile += '&template=openlayers&mode=browse&layers=' + groups[i]
+            print "<li><a href='%s'>%s</a></li>" % (urlmapfile, groups[i]) 
+            i=i+1
+        print "</ul>"
+
+def main():
+    writeHeader()
+    for root, subFolders, files in os.walk(rootdir):
+        for file in files:
+            f = os.path.join(root, file)
+            if os.path.isfile(f):
+                basename, extension = os.path.splitext(f)
+                if extension.lower() == ".map":
+                    if "orig" in f:
+                        # do not generate links for -orig.map-files
+                        continue
+                    if debug:
+                        print "Bearbeite Dokument %s" % f
+                    #read file and search for wms_title
+                    layers = []
+                    groups = []
+                    extent = []
+                    for line in open(f):
+                        if "wms_title" in line:
+                            #print line
+                            la = line.strip()[12:].replace('"','')
+                            if la != "Layers":
+                                layers.append(la)
+                        if "GROUP" in line:
+                            gr = line.strip()[6:].replace('"','')
+                            if gr not in groups:
+                                groups.append(gr)
+                        if "EXTENT" in line:
+                            ext =  line[9:].replace('"','').replace(' ', ',')
+                            extent.append(ext)
+    
+                    print "<ul>"
+                    writeLayers(f, layers, extent)
+                    print "</ul>"
+                    
+                    # write groups
+                    print "<ul>"
+                    writeGroups(f, groups)
+                    print "</ul>"
+                    if debug:
+                        print "Layer %s hat %s Layer" % (f, len(layers))
+                        print "Layer %s hat %s Gruppen" % (f, len(groups))
+    
+    writeFooter()
+
+main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)