stephan@208: #!/usr/bin/env python stephan@208: # stephan@208: # (C) 2011, Intevation GmbH, Stephan Holl stephan@208: # 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@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@208: print '''
  • Layer: %s
  • stephan@208:
    stephan@221: stephan@208: Anzahl der Layer: %s stephan@217: ''' % (basename, png, png, len(layers)) stephan@208: i = 0 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: 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: stephan@208: # write 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()