view contrib/python/generateHTML.py @ 209:1d7fc059e538

* doku/source/functionality.txt: Added part about the translation of umlauts into the doku.
author Stephan Holl <stephan.holl@intevation.de>
date Fri, 22 Jul 2011 11:14:19 +0200
parents 0c58db91311c
children d0acdab62b03
line wrap: on
line source
#!/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)