2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-08 11:49:50 +00:00

stopo prospecting map crashing

This commit is contained in:
Philip Sargent
2021-04-16 21:28:44 +01:00
parent 49277216ba
commit fa1df39923
4 changed files with 120 additions and 81 deletions

View File

@@ -15,8 +15,52 @@ from troggle.core.models.caves import Entrance, Area, SurvexStation, Cave
from troggle.core.views.caves import caveKey
''' Generates the prospecting guide document.
Also produces the overlay of points on top of a prospecting_image map - to be deleted.
I have tried to make this work with the version of PIL we have installed but something is missing still.
'''
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'),
('2b or 4 (unclear)', '2b or 4 (unclear)'),
('2c', '2c – Kaninchenhöhle area'),
('2d', '2d – Steinbrückenhöhle area'),
('3', '3 – Bräuning Alm'),
('4', '4 – Kratzer valley'),
('5', '5 – Schwarzmoos-Wildensee'),
('6', '6 – Far plateau'),
('1626 or 6 (borderline)', '1626 or 6 (borderline)'),
('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')
]
def prospecting(request):
'''This produces the multipage 'prospecting guide' document,
intended to be printed and carried into the field - in 1999.
All the formatting and selection clverness is in the template file.
'''
areas = []
for key, name in AREANAMES:
a = Area.objects.get(short_name = key) # assumes unique
caves = list(a.cave_set.all())
caves.sort(key=caveKey)
areas.append((name, a, caves))
return render(request, 'prospecting.html', {"areas": areas})
class MapLocations(object):
p = [
("laser.0_7", "BNase", "Reference", "Bräuning Nase laser point"),
@@ -54,48 +98,17 @@ class MapLocations(object):
def __str__(self):
return "{} map locations".format(len(self.p))
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'),
('2b or 4 (unclear)', '2b or 4 (unclear)'),
('2c', '2c – Kaninchenhöhle area'),
('2d', '2d – Steinbrückenhöhle area'),
('3', '3 – Bräuning Alm'),
('4', '4 – Kratzer valley'),
('5', '5 – Schwarzmoos-Wildensee'),
('6', '6 – Far plateau'),
('1626 or 6 (borderline)', '1626 or 6 (borderline)'),
('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')
]
def prospecting(request):
#for key, name in AREANAMES:
#print(key, Area.objects.get(short_name = key))
areas = []
for key, name in AREANAMES:
a = Area.objects.get(short_name = key) # assumes unique
caves = list(a.cave_set.all())
caves.sort(key=caveKey)
areas.append((name, a, caves))
return render(request, 'prospecting.html', {"areas": areas})
# Parameters for big map and zoomed subarea maps:
# big map first (zoom factor ignored)
# These are the values for the url? /prospecting/[mapcode].png ??
maps = {
# id left top right bottom zoom
# G&K G&K G&K G&K factor
@@ -157,6 +170,7 @@ TEXTSIZE = 16
CIRCLESIZE =8
LINEWIDTH = 2
myFont = ImageFont.truetype(FONT, TEXTSIZE)
print(f' - myFont {myFont} {FONT} {TEXTSIZE}')
def mungecoord(x, y, mapcode, img):
# Top of Zinken is 73 1201 = dataset 34542 81967
@@ -186,7 +200,7 @@ def plot(surveypoint, number, point_type, label, mapcode, draw, img):
E, N = ss.x, ss.y
shortnumber = number.replace("—","")
(x,y) = list(map(int, mungecoord(E, N, mapcode, img)))
#imgmaps[maparea].append( [x-4, y-SIZE/2, x+4+draw.textsize(shortnumber)[0], y+SIZE/2, shortnumber, label] )
imgmaps[maparea].append( [x-4, y-SIZE/2, x+4+draw.textsize(shortnumber)[0], y+SIZE/2, shortnumber, label] )
draw.rectangle([(x+CIRCLESIZE, y-TEXTSIZE/2), (x+CIRCLESIZE*2+draw.textsize(shortnumber)[0], y+TEXTSIZE/2)], fill="#ffffff")
draw.text((x+CIRCLESIZE * 1.5,y-TEXTSIZE/2), shortnumber, fill="#000000")
draw.ellipse([(x-CIRCLESIZE,y-CIRCLESIZE),(x+CIRCLESIZE,y+CIRCLESIZE)], fill=COL_TYPES[point_type], outline="#000000")
@@ -195,6 +209,21 @@ def plot(surveypoint, number, point_type, label, mapcode, draw, img):
def prospecting_image(request, name):
# We should replace all this with something that exports an overlay for Google Maps and OpenStreetView
test = os.path.join(settings.EXPOFILES, "location_maps", "testmap.png")
response = HttpResponse(content_type = "image/png")
with Image.open(test) as im:
draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line((0, im.size[1], im.size[0], 0), fill=128)
# write to stdout
#im.save(sys.stdout, "PNG")
img.save(response, "PNG")
return response
mainImage = Image.open(os.path.join(settings.EXPOFILES, "location_maps", "pguidemap.jpg"))
if settings.PUBLIC_SITE and not request.user.is_authenticated:
mainImage = Image.new("RGB", mainImage.size, '#ffffff')
@@ -214,7 +243,7 @@ def prospecting_image(request, name):
h = int(round(m[ZOOM] * (m[B] - m[T]) / (M[B] - M[T]) * H))
img = img.resize((w, h), Image.BICUBIC)
draw = ImageDraw.Draw(img)
draw.setfont(myFont)
#draw.setfont(myFont)
if name == "all":
for maparea in list(maps.keys()):
if maparea == "all":
@@ -225,7 +254,7 @@ def prospecting_image(request, name):
text = maparea + " map"
textlen = draw.textsize(text)[0] + 3
draw.rectangle([l, t, l+textlen, t+TEXTSIZE+2], fill='#ffffff')
draw.text((l+2, t+1), text, fill="#000000")
draw.text((l+2, t+1), text, fill="#000000", font=myFont)
#imgmaps.append( [l, t, l+textlen, t+SIZE+2, "submap" + maparea, maparea + " subarea map"] )
draw.line([l, t, r, t], fill='#777777', width=LINEWIDTH)
draw.line([l, b, r, b], fill='#777777', width=LINEWIDTH)
@@ -242,13 +271,14 @@ def prospecting_image(request, name):
draw.line([10, TEXTSIZE*2, 10+m100, TEXTSIZE*2], fill='#000000', width=LINEWIDTH)
draw.line([10+m100, TEXTSIZE * 3, 10+m100, TEXTSIZE*2], fill='#000000', width=LINEWIDTH)
label = "100m"
draw.text([10 + (m100 - draw.textsize(label)[0]) / 2, TEXTSIZE/2], label, fill='#000000')
draw.text([10 + (m100 - draw.textsize(label)[0]) / 2, TEXTSIZE/2], label, fill='#000000', font=myFont)
for p in MapLocations.points():
ml = MapLocations()
for p in ml.points():
surveypoint, number, point_type, label = p
plot(surveypoint, number, point_type, label, name, draw, img)
for (N, E, D, num) in [(35975.37, 83018.21, 100,"177"), # Calculated from bearings
for (N, E, D, num) in [(35975.37, 83018.21, 100, "177"), # Calculated from bearings
(35350.00, 81630.00, 50, "71"), # From Auer map
(36025.00, 82475.00, 50, "146"), # From mystery map
(35600.00, 82050.00, 50, "35"), # From Auer map
@@ -270,4 +300,5 @@ def prospecting_image(request, name):
response = HttpResponse(content_type = "image/png")
del draw
img.save(response, "PNG")
return response