summaryrefslogtreecommitdiffstats
path: root/core/views/prospect.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2021-04-16 21:28:44 +0100
committerPhilip Sargent <philip.sargent@klebos.com>2021-04-16 21:28:44 +0100
commitfa1df39923d9ce5e1c134dec987c8665ce22c5de (patch)
treea4f8210ac15e768c68be4881ba15fa644c2bdfd3 /core/views/prospect.py
parent49277216bafa0db559705943342e30b1a5934369 (diff)
downloadtroggle-fa1df39923d9ce5e1c134dec987c8665ce22c5de.tar.gz
troggle-fa1df39923d9ce5e1c134dec987c8665ce22c5de.tar.bz2
troggle-fa1df39923d9ce5e1c134dec987c8665ce22c5de.zip
stopo prospecting map crashing
Diffstat (limited to 'core/views/prospect.py')
-rw-r--r--core/views/prospect.py115
1 files changed, 73 insertions, 42 deletions
diff --git a/core/views/prospect.py b/core/views/prospect.py
index 3ef768f..34f875b 100644
--- a/core/views/prospect.py
+++ b/core/views/prospect.py
@@ -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 &ndash; Plateau: around Top Camp'),
+ ('1b', '1b &ndash; Western plateau near 182'),
+ ('1c', '1c &ndash; Eastern plateau near 204 walk-in path'),
+ ('1d', '1d &ndash; Further plateau around 76'),
+ ('2a', '2a &ndash; Southern Schwarzmooskogel near 201 path and the Nipple'),
+ ('2b', '2b &ndash; Eish&ouml;hle area'),
+ ('2b or 4 (unclear)', '2b or 4 (unclear)'),
+ ('2c', '2c &ndash; Kaninchenh&ouml;hle area'),
+ ('2d', '2d &ndash; Steinbr&uuml;ckenh&ouml;hle area'),
+ ('3', '3 &ndash; Br&auml;uning Alm'),
+ ('4', '4 &ndash; Kratzer valley'),
+ ('5', '5 &ndash; Schwarzmoos-Wildensee'),
+ ('6', '6 &ndash; Far plateau'),
+ ('1626 or 6 (borderline)', '1626 or 6 (borderline)'),
+ ('7', '7 &ndash; Egglgrube'),
+ ('8a', '8a &ndash; Loser south face'),
+ ('8b', '8b &ndash; Loser below Dimmelwand'),
+ ('8c', '8c &ndash; Augst See'),
+ ('8d', '8d &ndash; Loser-Hochganger ridge'),
+ ('9', '9 &ndash; Gschwandt Alm'),
+ ('10', '10 &ndash; Altaussee'),
+ ('11', '11 &ndash; 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&auml;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 &ndash; Plateau: around Top Camp'),
- ('1b', '1b &ndash; Western plateau near 182'),
- ('1c', '1c &ndash; Eastern plateau near 204 walk-in path'),
- ('1d', '1d &ndash; Further plateau around 76'),
- ('2a', '2a &ndash; Southern Schwarzmooskogel near 201 path and the Nipple'),
- ('2b', '2b &ndash; Eish&ouml;hle area'),
- ('2b or 4 (unclear)', '2b or 4 (unclear)'),
- ('2c', '2c &ndash; Kaninchenh&ouml;hle area'),
- ('2d', '2d &ndash; Steinbr&uuml;ckenh&ouml;hle area'),
- ('3', '3 &ndash; Br&auml;uning Alm'),
- ('4', '4 &ndash; Kratzer valley'),
- ('5', '5 &ndash; Schwarzmoos-Wildensee'),
- ('6', '6 &ndash; Far plateau'),
- ('1626 or 6 (borderline)', '1626 or 6 (borderline)'),
- ('7', '7 &ndash; Egglgrube'),
- ('8a', '8a &ndash; Loser south face'),
- ('8b', '8b &ndash; Loser below Dimmelwand'),
- ('8c', '8c &ndash; Augst See'),
- ('8d', '8d &ndash; Loser-Hochganger ridge'),
- ('9', '9 &ndash; Gschwandt Alm'),
- ('10', '10 &ndash; Altaussee'),
- ('11', '11 &ndash; 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("&mdash;","")
(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 \ No newline at end of file