Mercurial > mxd2map
view contrib/python/generateHTML.py @ 221:a44d442577ca
Fixes correct paths for Browser-output, added target for GROUP-output
author | Stephan Holl <stephan.holl@intevation.de> |
---|---|
date | Mon, 25 Jul 2011 12:33:24 +0200 |
parents | 13f1cf17f620 |
children | 316a2b3d4126 |
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) png = mapfile.replace(".map", "_arcpy.png") print '''<li>Layer: <strong>%s</strong></li> <br> <a target="bild" href="file://%s"><img witdth="80" height="60" border="" src="file://%s"></a> Anzahl der Layer: %s ''' % (basename, 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='_new' 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): 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()