stephan@208: #!/usr/bin/env python stephan@208: # raimund@256: # Copyright (c) 2011 by Intevation GmbH, Germany raimund@256: # raimund@256: # This file is part of MXD2map. stephan@208: # raimund@256: # This program is free software under the LGPL (>=v2.1) raimund@256: # Read the file LICENCE.txt coming with the software for details raimund@256: # or visit http://www.gnu.org/licenses/ if it does not exist. raimund@256: # raimund@256: # MXD2map has been developed on behalf of the raimund@256: # Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg raimund@256: # by Intevation GmbH. raimund@256: # raimund@256: # Authors: raimund@256: # Raimund Renkert raimund@256: # Bjoern Schilberg raimund@256: # Stephan Holl raimund@256: stephan@208: # stephan@208: # Generate a HTML-Page based on a recursive folder structure of generated stephan@208: # mapfiles from MXD2map stephan@208: # stephan@208: # stephan@208: # Usage: generateHTML.py > output.html stephan@208: stephan@208: stephan@208: import os stephan@208: stephan@208: # this is intended to run in the folder where the generates mapfiles are stephan@208: # stored: stephan@208: rootdir = os.getcwd() + '/map-test-2' stephan@208: debug = False stephan@208: stephan@208: # adopt for you needs: stephan@208: url = 'http://localhost/cgi-bin/mapserv.exe' stephan@208: getmap = url + '?Request=GetMap&Service=WMS&Version=1.1.1' stephan@208: getmap += '&srs=EPSG:4326&width=800&height=600&format=image/png&styles=' stephan@225: getcaps = url + '?Request=GetCapabilities&Service=WMS&Version=1.1.1' stephan@208: stephan@208: def writeHeader(): stephan@208: print ''' stephan@208: stephan@208: MXD2map-examples stephan@208: stephan@208: stephan@208: stephan@208:

Verfuegbare MXD-Dateien

stephan@208: ''' stephan@208: stephan@208: def writeFooter(): stephan@208: content = "" stephan@208: print content stephan@208: stephan@208: def writeLayers(mapfile, layers, extent): stephan@208: basename = os.path.basename(mapfile) stephan@217: png = mapfile.replace(".map", "_arcpy.png") stephan@227: gc = getcaps + '&map=' + mapfile stephan@228: print '''
  • Layer: %s | GetCapabilities
  • stephan@208:
    stephan@221: stephan@208: Anzahl der Layer: %s stephan@228: ''' % (mapfile, basename, gc, png, png, len(layers)) stephan@208: i = 0 stephan@208: print "
      " stephan@208: while i < len(layers): stephan@208: urlmapfile = url + '?map=' + mapfile stephan@208: urlmapfile += '&template=openlayers&mode=browse&layers=' + layers[i] stephan@208: gm = getmap + '&map=' + mapfile + '&layers=' + layers[i] stephan@208: if extent: stephan@208: ext = str(extent).strip('[\'\'\\r\\n]') stephan@208: gm += '&bbox='+''.join(ext) stephan@227: print "
    • %s | WMS GetMap
    • " % (urlmapfile, layers[i], gm) stephan@208: i=i+1 stephan@208: print "
    " stephan@208: stephan@216: def generateArcImage(mapfile): stephan@216: basename = os.path.basename(mapfile) stephan@216: mxdfile = mapfile.replace(".map",".mxd") stephan@216: output = mapfile.replace(".map", "_arcpy.png") stephan@216: if debug: stephan@216: print "MXDfile: %s\nOutput: %s " % (mxdfile, output) stephan@216: stephan@216: if not output: stephan@216: import arcpy stephan@216: mxd = arcpy.mapping.MapDocument(mxdfile) stephan@216: df = arcpy.mapping.ListDataFrames(mxd)[0] stephan@216: arcpy.mapping.ExportToPNG(mxd, output, df, df_export_width=800, stephan@216: df_export_height=600, world_file=True) stephan@216: del mxd stephan@216: stephan@216: stephan@208: def writeGroups(mapfile,groups): stephan@208: if len(groups) > 1: stephan@208: print "Anzahl der Gruppen: %s" % len(groups) stephan@208: i = 0 stephan@208: print "
      " stephan@208: while i < len(groups): stephan@222: if os.name == "nt": stephan@222: mapfile = mapfile.replace('\\', '/') stephan@208: urlmapfile = url + '?map=' + mapfile stephan@208: urlmapfile += '&template=openlayers&mode=browse&layers=' + groups[i] stephan@221: print "
    • %s
    • " % (urlmapfile, groups[i]) stephan@208: i=i+1 stephan@208: print "
    " stephan@208: stephan@208: def main(): stephan@208: writeHeader() stephan@208: for root, subFolders, files in os.walk(rootdir): stephan@208: for file in files: stephan@208: f = os.path.join(root, file) stephan@208: if os.path.isfile(f): stephan@208: basename, extension = os.path.splitext(f) stephan@208: if extension.lower() == ".map": stephan@208: if "orig" in f: stephan@208: # do not generate links for -orig.map-files stephan@208: continue stephan@208: if debug: stephan@208: print "Bearbeite Dokument %s" % f stephan@208: #read file and search for wms_title stephan@208: layers = [] stephan@208: groups = [] stephan@208: extent = [] stephan@208: for line in open(f): stephan@208: if "wms_title" in line: stephan@208: #print line stephan@208: la = line.strip()[12:].replace('"','') stephan@208: if la != "Layers": stephan@208: layers.append(la) stephan@208: if "GROUP" in line: stephan@208: gr = line.strip()[6:].replace('"','') stephan@208: if gr not in groups: stephan@208: groups.append(gr) stephan@208: if "EXTENT" in line: stephan@208: ext = line[9:].replace('"','').replace(' ', ',') stephan@208: extent.append(ext) stephan@208: stephan@216: generateArcImage(f) stephan@208: print "
      " stephan@208: writeLayers(f, layers, extent) stephan@208: print "
    " stephan@208: stephan@208: # write groups stephan@208: print "
      " stephan@208: writeGroups(f, groups) stephan@208: print "
    " stephan@208: if debug: stephan@208: print "Layer %s hat %s Layer" % (f, len(layers)) stephan@208: print "Layer %s hat %s Gruppen" % (f, len(groups)) stephan@208: stephan@208: writeFooter() stephan@208: stephan@208: main()