mirror of
https://expo.survex.com/repositories/expoweb/.git/
synced 2024-11-23 15:51:56 +00:00
332 lines
12 KiB
Python
332 lines
12 KiB
Python
|
# 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("<map id=\"%s\" name=\"%s\">" % (mapname, mapname))
|
||
|
for j in xrange(n):
|
||
|
try:
|
||
|
i = data[n-j-1]
|
||
|
htmlfile.write("<area shape=\"rect\" coords=\"%d, %d, %d, %d\" href=\"#id%s\" title=\"%s\" />\n" % (i[0],i[1],i[2],i[3],i[4],i[5]))
|
||
|
except:
|
||
|
print "Died on", repr( data[n-j-1] )
|
||
|
#raise
|
||
|
htmlfile.write("</map>")
|
||
|
|
||
|
|
||
|
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("<html><head><title>Prospecting Guide</title>\n")
|
||
|
htmlfile.write("<style type=\"text/css\">.locn { font-size: x-small }</style></head>\n")
|
||
|
htmlfile.write("<body><h1>Prospecting Guide</h1>")
|
||
|
htmlfile.write("<p>Generated " + time.strftime("%x %X") + "</p>\n")
|
||
|
htmlfile.write("<p><b>Notes:</b></p><ul><li>A marking status of \"Retag\" means a tag is in place but it carries a provisional number, or in some cases an incorrect number, and needs replacing with a new tag.</li>\n<li>Kataster status codes indicate the size of a cave, its character and its exploration status, as described <a href=\"../katast.htm\">here</a>.</li><li>For more info on each cave, see the links to detailed description pages.</li></ul><p><img src=\"prospecting_guide.jpg\" usemap=\"#map1\" ismap=\"ismap\" /></p><h3>Eishöhle area detail</h3><p><img src=\"prospecting_guide_40area.jpg\" usemap=\"#map40\" ismap=\"ismap\" /></p><h3>Steinbrückenhöhle area detail</h3><p><img src=\"prospecting_guide_204area.jpg\" usemap=\"#map204\" ismap=\"ismap\" /></p>\n")
|
||
|
|
||
|
cachednumber = ""
|
||
|
cachedarea = ""
|
||
|
cachedname = ""
|
||
|
imagemap_areas=[]
|
||
|
imagemap40_areas=[]
|
||
|
imagemap204_areas=[]
|
||
|
for cave in cavetab:
|
||
|
if cave["Link file"]: continue
|
||
|
number = find_effective_number(cave)
|
||
|
if(cave["Multiple entrances"] not in ["", "yes"]):
|
||
|
number = "—" + cachednumber + cave["Entrances"]
|
||
|
shortnumber = cachednumber
|
||
|
if not cave["Area"]: cave["Area"] = cachedarea
|
||
|
if not cave["Name"]: cave["Name"] = cachedname
|
||
|
else:
|
||
|
cachednumber = number
|
||
|
shortnumber = number
|
||
|
cachedname = cave["Name"] or cave["Unofficial Name"]
|
||
|
cachedarea = cave["Area"]
|
||
|
|
||
|
area = cave["Area"]
|
||
|
if area == '1626': continue
|
||
|
|
||
|
|
||
|
loctuple = find_location(cave)
|
||
|
label = find_label(cave, shortnumber)
|
||
|
if(cave["Multiple entrances"] == "yes"):
|
||
|
locn = "<td colspan=\"3\"> </td>"
|
||
|
elif(loctuple):
|
||
|
locn = "<td>%d</td><td>%d</td><td>%d</td>" % loctuple
|
||
|
try:
|
||
|
plot(loctuple, number, area, label)
|
||
|
except:
|
||
|
plot(loctuple, number, "6", label)
|
||
|
else:
|
||
|
locn = "<td colspan=\"3\">"+ cave["Findability"] + "</td>"
|
||
|
try:#if(not cavelists.has_key(area)): cavelists[area]=[]
|
||
|
cavelists[area].append((number, cave, locn))
|
||
|
except:
|
||
|
print number, area
|
||
|
|
||
|
plot(positions["laser.0_7"], "BNase", "6", "Bräuning Näse laser point")
|
||
|
plot(positions["226-96"], "BZkn", "6", "Bräuning Zinken trig point")
|
||
|
plot(positions["vd1"],"VD1","6", "VD1 laser point")
|
||
|
plot(positions["laser.kt114_96"],"HSK","6", "Hinterer Schwarzmooskogel trig point")
|
||
|
plot(positions["2000"],"Nipple","6", "Nipple (Weiße Warze)")
|
||
|
plot(positions["3000"],"VSK","6", "Vorderer Schwarzmooskogel summit")
|
||
|
plot(positions["topcamp"], "TC", "6", "Top Camp")
|
||
|
plot(positions["laser.0_1"], "LSR1", "6", "Laser Point 0/1")
|
||
|
plot(positions["laser.0_5"], "LSR5", "6", "Laser Point 0/5")
|
||
|
|
||
|
|
||
|
for area in areas:
|
||
|
if area:
|
||
|
htmlfile.write("<h3><span style=\"background-color: %s; border: 1px solid black\"> </span> %s</h3>" % (areacolours.get(area, "#ffffff"), areanames[area]))
|
||
|
else:
|
||
|
htmlfile.write("<h3>Location unclear</h3>")
|
||
|
htmlfile.write("<table border=\"1\">\n<tr><th>Cave Number</th><th>Name</th><th>E</th><th>N</th><th>Alt</th><th>Marking</th><th>Status</th>")
|
||
|
|
||
|
for (number, cave, locn) in cavelists[area]:
|
||
|
if cave["Autogen file"]:
|
||
|
htmlfile.write("<tr><td><a href=\"../%s\">%s</a></td><td><a id=\"id%s\">%s</a></td>" % (cave["Autogen file"], longnumber(cave, number), number.replace("—", ""), cave["Name"] or cave["Unofficial Name"]))
|
||
|
else:
|
||
|
htmlfile.write("<tr><td>%s</td><td><a id=\"id%s\">%s</a></td>" % (longnumber(cave, number), number.replace("—", ""), cave["Name"] or cave["Unofficial Name"]))
|
||
|
htmlfile.write(locn + "<td>%s</td><td>%s</td>" % (cave["Marking"], cave["Kat Status Code"]))
|
||
|
if(cave["Findability"] != "Surveyed" and cave["Multiple entrances"] != "yes"):
|
||
|
htmlfile.write("<td class=\"locn\">%s %s</td>" % (cave["Location"], cave["Bearings"]))
|
||
|
htmlfile.write("</tr>\n")
|
||
|
|
||
|
htmlfile.write("</table>\n")
|
||
|
|
||
|
|
||
|
fakedpositions = file("fakedpositions.dat")
|
||
|
for p in fakedpositions:
|
||
|
try:
|
||
|
(x,y,d,name, area) = re.match(r'\(([0-9.]*?),\t([0-9.]*?),\t([0-9.]*?)\)\t(.*)\t(.*)#', chomp(p)).groups()
|
||
|
except:
|
||
|
print "Couldn't understand" + repr(chomp(p))
|
||
|
continue
|
||
|
x,y,d = map(float, (x,y,d))
|
||
|
x,y,d = map(round, (x,y,d))
|
||
|
lo = mungecoord(x-d,y+d)
|
||
|
hi = mungecoord(x+d,y-d)
|
||
|
foo = mungecoord(x-d, y)
|
||
|
myDraw.ellipse([lo,hi], outline="#000000")
|
||
|
myDraw.ellipse([lo[0]+1, lo[1]+1,hi[0]-1, hi[1]-1], outline=areacolours[area])
|
||
|
myDraw.ellipse([lo[0]+2, lo[1]+2,hi[0]-2, hi[1]-2], outline=areacolours[area])
|
||
|
myDraw.rectangle([foo[0],foo[1]-SIZE/2, foo[0] + myDraw.textsize(name)[0], foo[1]+SIZE/2], fill="#ffffff")
|
||
|
imagemap_areas.append( [foo[0],foo[1]-SIZE/2, foo[0] + myDraw.textsize(name)[0], foo[1]+SIZE/2, name, "Approx position of %s" % name] )
|
||
|
|
||
|
myDraw.text((foo[0], foo[1]-SIZE/2), name, fill="#000000")
|
||
|
|
||
|
writeout_imagemap(imagemap_areas, "map1")
|
||
|
writeout_imagemap(imagemap40_areas, "map40")
|
||
|
writeout_imagemap(imagemap204_areas, "map204")
|
||
|
|
||
|
htmlfile.write("</body></html>")
|
||
|
htmlfile.close()
|
||
|
del myDraw
|
||
|
del my40Draw
|
||
|
del my204Draw
|
||
|
myImage.save("../prospecting_guide.jpg", "JPEG")
|
||
|
my40Image.save("../prospecting_guide_40area.jpg", "JPEG")
|
||
|
my204Image.save("../prospecting_guide_204area.jpg", "JPEG")
|
||
|
|
||
|
|
||
|
|
||
|
|