view contrib/python/generateHTML.py @ 346:ab4e4c4b83c9

Add Install_Linux.txt with all my notes from the installtion this file should be cleaned for publishing
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 16 Nov 2012 17:02:07 +0100
parents 4dc2b9aa3c57
children
line wrap: on
line source
#!/usr/bin/env python
#
# Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
# 
# This file is part of MXD2map.
#
# This program is free software under the LGPL (>=v2.1)
# Read the file LICENCE.txt coming with the software for details
# or visit http://www.gnu.org/licenses/ if it does not exist.
#
# MXD2map has been developed on behalf of the
# Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
# by Intevation GmbH.
#
# Authors:
# Raimund Renkert <raimund.renkert@intevation.de>
# Bjoern Schilberg <bjoern.schilberg@intevation.de>
# 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='
getcaps = url + '?Request=GetCapabilities&Service=WMS&Version=1.1.1'

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)
    png = mapfile.replace(".map", "_arcpy.png")
    gc = getcaps + '&map=' + mapfile
    print '''<li>Layer:  <strong><a target='_mapfile' href='file://%s'>%s</a></strong> | <a target='_getcaps' href='%s'>GetCapabilities</a></li>
<br>
<a target="bild" href="file://%s"><img witdth="80" height="60" border="" src="file://%s"></a>
Anzahl der Layer: %s
''' % (mapfile, basename, gc, png, png, 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='_getmap' href='%s'>WMS GetMap</a></li>" % (urlmapfile, layers[i], gm) 
        i=i+1
    print "</ul>"

def generateArcImage(mapfile):
	basename = os.path.basename(mapfile)
	mxdfile = mapfile.replace(".map",".mxd")
	output = mapfile.replace(".map", "_arcpy.png")
	if debug:
		print "MXDfile: %s\nOutput: %s " % (mxdfile, output)

	if not output:
		import arcpy
		mxd = arcpy.mapping.MapDocument(mxdfile)
		df = arcpy.mapping.ListDataFrames(mxd)[0]
		arcpy.mapping.ExportToPNG(mxd, output, df, df_export_width=800, 
					  df_export_height=600, world_file=True)
		del mxd


def writeGroups(mapfile,groups):
    if len(groups) > 1:
        print "Anzahl der Gruppen: %s" % len(groups)
        i = 0
        print "<ul>"
        while i < len(groups):
	    if os.name == "nt":
		mapfile = mapfile.replace('\\', '/')
            urlmapfile  = url + '?map=' + mapfile
            urlmapfile += '&template=openlayers&mode=browse&layers=' + groups[i]
	    print "<li><a target='_group' 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)
    
    		    generateArcImage(f)
                    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)