# Script to create a slightly more useful attempt # at a prospecting guide. areas = ['', '1a','1b','1c','1d', '2a', '2b', '2c', '2d', '3', '4', '5', '6','7', '8a', '8b', '8c', '8d', '9', '10', '11'] areanames = { '': 'Location unclear', '1a': '1a – Plateau: around Top Camp', '1b': '1b – Western plateau near 182', '1c': '1c – Eastern plateau near 204 walk-in path', '1d': '1d – Further plateau around 76', '2a': '2a – Southern Schwarzmooskogel near 201 path and the Nipple', '2b': '2b – Eishöhle area', '2c': '2c – Kaninchenhöhle area', '2d': '2d – Steinbrückenhöhle area', '3': '3 – Bräning Alm', '4': '4 – Kratzer valley', '5': '5 – Schwarzmoos-Wildensee', '6': '6 – Far plateau', '7': '7 – Egglgrube', '8a': '8a – Loser south face', '8b': '8b – Loser below Dimmelwand', '8c': '8c – Augst See', '8d': '8d – Loser-Hochganger ridge', '9': '9 – Gschwandt Alm', '10': '10 – Altaussee', '11': '11 – Augstbach', } areacolours = { '1a' : '#00ffff', '1b' : '#ff00ff', '1c' : '#ffff00', '1d' : '#ffffff', '2a' : '#ff0000', '2b' : '#00ff00', '2c' : '#008800', '2d' : '#ff9900', '4' : '#0000ff', '6' : '#000000', # doubles for surface fixed pts '7' : '#808080' } cavelists={} for a in areas: cavelists[a]=[] def chomp(s): if(s[-1]=="\n"): return s[:-1] else: return s def find_effective_number(c): """Determine an appropriate number to use.""" if c["Kataster Number"]: return c["Kataster Number"] else: return c["Unofficial number"] def longnumber(c, number): """Both numbers""" if (c["Unofficial number"] and c["Unofficial number"] != number): return number + " (" + c["Unofficial number"] + ")" else: return number def find_location(cave): for fixtype in ["tag point in dataset", "other point in dataset", "exact entrance in dataset (drip line/highest enclosed contour)", "GPS post SA", "GPS pre SA"]: if(cave[fixtype]): return positions[cave[fixtype]] return 0 def munge_allposline(line): x, y, z, name = re.match(r'\(([0-9.]*?),\s*([0-9.]*?),\s*([0-9.]*?)\s*\)\s*(.*)\n', line).groups() x,y, z = map(float, [x,y,z]) return (name, x,y,z) def find_label(cave, number): t = longnumber(cave, number) + " " if(cave["Name"] and cave["Unofficial Name"]): t += cave["Name"] + " (" + cave["Unofficial Name"] + ")" elif cave["Name"]: t += cave["Name"] else: t += cave["Unofficial Name"] try: n = number if(n[-1] in string.lowercase): n = n[:-1] except: n = "NONE" if(lengths.has_key(n)): t += (" %sm long %sm deep" % (lengths[n][0], lengths[n][1])) return t import Image, ImageDraw, ImageFont, string myImage = Image.open("pguidemap.jpg") myDraw = ImageDraw.Draw(myImage) my40Image = Image.open("pguidemap_40area.jpg") my40Draw = ImageDraw.Draw(my40Image) my204Image = Image.open("pguidemap_204area.jpg") my204Draw = ImageDraw.Draw(my204Image) FONT = "/usr/X11R6/lib/X11/fonts/truetype/arial.ttf" SIZE = 8 myFont = ImageFont.truetype(FONT, SIZE) myDraw.setfont(myFont) my40Draw.setfont(myFont) my204Draw.setfont(myFont) def mungecoord(x, y, mapcode = ""): # Top of Zinken is 73 1201 = dataset 34542 81967 # Top of Hinter is 1073 562 = dataset 36670 83317 # image is 1417 by 2201 # FACTOR1 = 1000.0 / (36670.0-34542.0) # FACTOR2 = (1201.0-562.0) / (83317 - 81967) # FACTOR = (FACTOR1 + FACTOR2)/2 # The factors aren't the same as the scanned map's at a slight angle. I # can't be bothered to fix this. Since we zero on the Hinter it makes # very little difference for caves in the areas round 76 or 204. # xoffset = (x - 36670)*FACTOR # yoffset = (y - 83317)*FACTOR # return (1073 + xoffset, 562 - yoffset) # Parameters for big map MAP_LEFT_GK = 34394.9 MAP_TOP_GK = 84508.6 MAP_RIGHT_GK = 37399.4 MAP_BOTTOM_GK = 80895.6 MAP_WIDTH = 1417 MAP_HEIGHT = 1704 # Parameters for zoomed smaller maps MAP40_LEFT_GK = 36275.6 MAP40_TOP_GK = 82392.5 MAP40_RIGHT_GK = 36780.3 MAP40_BOTTOM_GK = 81601.7 MAP40_WIDTH = 714 MAP40_HEIGHT = 1119 MAP204_LEFT_GK = 36354.1 MAP204_TOP_GK = 84154.5 MAP204_RIGHT_GK = 37047.4 MAP204_BOTTOM_GK = 83399.7 MAP204_WIDTH = 972 MAP204_HEIGHT = 1068 if(mapcode == "40"): return (x - MAP40_LEFT_GK)/(MAP40_RIGHT_GK - MAP40_LEFT_GK) * MAP40_WIDTH, MAP40_HEIGHT - (y - MAP40_BOTTOM_GK)/(MAP40_TOP_GK - MAP40_BOTTOM_GK) * MAP40_HEIGHT elif(mapcode == "204"): return (x - MAP204_LEFT_GK)/(MAP204_RIGHT_GK - MAP204_LEFT_GK) * MAP204_WIDTH, MAP204_HEIGHT - (y - MAP204_BOTTOM_GK)/(MAP204_TOP_GK - MAP204_BOTTOM_GK) * MAP204_HEIGHT else: return (x - MAP_LEFT_GK)/(MAP_RIGHT_GK - MAP_LEFT_GK) * MAP_WIDTH, MAP_HEIGHT - (y - MAP_BOTTOM_GK)/(MAP_TOP_GK - MAP_BOTTOM_GK) * MAP_HEIGHT def plot(loctuple, number, area, label): shortnumber = number.replace("—","") (x,y) = mungecoord(loctuple[0], loctuple[1]) x = int(x) y = int(y) imagemap_areas.append( [x-4, y-SIZE/2, x+4+myDraw.textsize(shortnumber)[0], y+SIZE/2, shortnumber, label] ) myDraw.ellipse([(x-4,y-4),(x+4,y+4)], fill=areacolours[area], outline="#000000") myDraw.rectangle([(x+4, y-SIZE/2), (x+4+myDraw.textsize(shortnumber)[0], y+SIZE/2)], fill="#ffffff") myDraw.text((x+6,y-SIZE/2), shortnumber, fill="#000000") (x,y) = mungecoord(loctuple[0], loctuple[1], "40") x = int(x) y = int(y) imagemap40_areas.append( [x-4, y-SIZE/2, x+4+myDraw.textsize(shortnumber)[0], y+SIZE/2, shortnumber, label] ) my40Draw.ellipse([(x-4,y-4),(x+4,y+4)], fill=areacolours[area], outline="#000000") my40Draw.rectangle([(x+4, y-SIZE/2), (x+4+myDraw.textsize(shortnumber)[0], y+SIZE/2)], fill="#ffffff") my40Draw.text((x+6,y-SIZE/2), shortnumber, fill="#000000") (x,y) = mungecoord(loctuple[0], loctuple[1], "204") x = int(x) y = int(y) imagemap204_areas.append( [x-4, y-SIZE/2, x+4+myDraw.textsize(shortnumber)[0], y+SIZE/2, shortnumber, label] ) my204Draw.ellipse([(x-4,y-4),(x+4,y+4)], fill=areacolours[area], outline="#000000") my204Draw.rectangle([(x+4, y-SIZE/2), (x+4+myDraw.textsize(shortnumber)[0], y+SIZE/2)], fill="#ffffff") my204Draw.text((x+6,y-SIZE/2), shortnumber, fill="#000000") def writeout_imagemap(data, mapname): # Munge the list of coordinates into a proper image map. # There is a wrinkle here: the HTML spec gives priority # to the _first_ defined elt, so we swap the order! n = len(data) htmlfile.write("") import csv, re, time cavetabfile = file("../CAVETAB2.CSV") fieldnames=chomp(cavetabfile.next()).replace('"','').split(",") cavetab = csv.DictReader(cavetabfile, fieldnames) positionfile = file("../all.pos") positionfile.next() positions = {} print "Munging all.pos" for stn in positionfile: t = munge_allposline(stn) positions[t[0]] = (t[1],t[2],t[3]) print "Done" print "Munging lengths.dat" lengthsfile = file("lengths.dat") lengths = {} for l in lengthsfile: t = l.replace("\"","").replace("\n", "").split("\t") lengths[t[0]] = (t[1], t[2]) print "Done" htmlfile = file("../prospecting_guide.html", "w") htmlfile.write("
Generated " + time.strftime("%x %X") + "
\n") htmlfile.write("Notes:
Cave Number | Name | E | N | Alt | Marking | Status | ") for (number, cave, locn) in cavelists[area]: if cave["Autogen file"]: htmlfile.write("
---|---|---|---|---|---|---|
%s | %s | " % (cave["Autogen file"], longnumber(cave, number), number.replace("—", ""), cave["Name"] or cave["Unofficial Name"])) else: htmlfile.write("|||||
%s | %s | " % (longnumber(cave, number), number.replace("—", ""), cave["Name"] or cave["Unofficial Name"])) htmlfile.write(locn + "%s | %s | " % (cave["Marking"], cave["Kat Status Code"])) if(cave["Findability"] != "Surveyed" and cave["Multiple entrances"] != "yes"): htmlfile.write("%s %s | " % (cave["Location"], cave["Bearings"])) htmlfile.write("