mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-14 22:37:06 +00:00
prospect and moving code to better places
This commit is contained in:
@@ -13,6 +13,7 @@ from django.shortcuts import render
|
||||
import troggle.settings as settings
|
||||
from troggle.core.models.caves import Entrance, Area, SurvexStation, Cave
|
||||
from troggle.core.views.caves import caveKey
|
||||
from troggle.parsers.survex import MapLocations
|
||||
|
||||
''' Generates the prospecting guide document.
|
||||
|
||||
@@ -61,49 +62,7 @@ def prospecting(request):
|
||||
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"),
|
||||
("226-96", "BZkn", "Reference", "Bräuning Zinken trig point"),
|
||||
("vd1","VD1","Reference", "VD1 survey point"),
|
||||
("laser.kt114_96","HSK","Reference", "Hinterer Schwarzmooskogel trig point"),
|
||||
("2000","Nipple","Reference", "Nipple (Weiße Warze)"),
|
||||
("3000","VSK","Reference", "Vorderer Schwarzmooskogel summit"),
|
||||
("topcamp", "OTC", "Reference", "Old Top Camp"),
|
||||
("laser.0", "LSR0", "Reference", "Laser Point 0"),
|
||||
("laser.0_1", "LSR1", "Reference", "Laser Point 0/1"),
|
||||
("laser.0_3", "LSR3", "Reference", "Laser Point 0/3"),
|
||||
("laser.0_5", "LSR5", "Reference", "Laser Point 0/5"),
|
||||
("225-96", "BAlm", "Reference", "Bräuning Alm trig point")
|
||||
]
|
||||
def points(self):
|
||||
for ent in Entrance.objects.all():
|
||||
if ent.best_station():
|
||||
try:
|
||||
k = ent.caveandentrance_set.all()[0].cave
|
||||
except:
|
||||
message = " ! Failed to get Cave linked to Entrance:{} from:{} best:{}".format(ent.name, ent.filename, ent.best_station())
|
||||
DataIssue.objects.create(parser='entrances', message=message)
|
||||
print(message)
|
||||
raise
|
||||
try:
|
||||
areaName = k.getArea().short_name
|
||||
except:
|
||||
message = " ! Failed to get Area on cave '{}' linked to Entrance:{} from:{} best:{}".format(cave, ent.name, ent.filename, ent.best_station())
|
||||
DataIssue.objects.create(parser='entrances', message=message)
|
||||
print(message)
|
||||
raise
|
||||
self.p.append((ent.best_station(), "%s-%s" % (areaName, str(ent)[5:]), ent.needs_surface_work(), str(ent)))
|
||||
return self.p
|
||||
|
||||
def __str__(self):
|
||||
return "{} map locations".format(len(self.p))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Parameters for big map and zoomed subarea maps:
|
||||
# big map first (zoom factor ignored)
|
||||
|
||||
@@ -143,6 +102,7 @@ R = 2
|
||||
B = 3
|
||||
ZOOM = 4
|
||||
DESC = 5
|
||||
SIZE = 5
|
||||
|
||||
areacolours = {
|
||||
'1a' : '#00ffff',
|
||||
@@ -170,7 +130,7 @@ TEXTSIZE = 16
|
||||
CIRCLESIZE =8
|
||||
LINEWIDTH = 2
|
||||
myFont = ImageFont.truetype(FONT, TEXTSIZE)
|
||||
print(f' - myFont {myFont} {FONT} {TEXTSIZE}')
|
||||
#print(f' - myFont {myFont} {FONT} {TEXTSIZE}')
|
||||
|
||||
def mungecoord(x, y, mapcode, img):
|
||||
# Top of Zinken is 73 1201 = dataset 34542 81967
|
||||
@@ -194,41 +154,24 @@ COL_TYPES = {True: "red",
|
||||
False: "#dddddd",
|
||||
"Reference": "#dddddd"}
|
||||
|
||||
def plot(surveypoint, number, point_type, label, mapcode, draw, img):
|
||||
try:
|
||||
ss = SurvexStation.objects.lookup(surveypoint)
|
||||
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] )
|
||||
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")
|
||||
except:
|
||||
pass
|
||||
|
||||
def prospecting_image(request, name):
|
||||
# We should replace all this with something that exports an overlay for Google Maps and OpenStreetView
|
||||
'''This draws map outlines on an existing map image.
|
||||
But getting the entrances plotted is broken by later changes elsewhere in the system since this code was written.
|
||||
|
||||
# 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")
|
||||
SurvexStations are in x=latitude, y=longitude - these are what appear in essentials.gpx
|
||||
Entrances are in northing, easting
|
||||
|
||||
# return response
|
||||
which is why we can't simply plot all the Entrances...
|
||||
|
||||
We should replace all this with something that exports an overlay for Google Maps and OpenStreetView
|
||||
'''
|
||||
|
||||
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')
|
||||
m = maps[name]
|
||||
#imgmaps = []
|
||||
imgmaps = []
|
||||
if name == "all":
|
||||
img = mainImage
|
||||
else:
|
||||
@@ -255,7 +198,7 @@ def prospecting_image(request, name):
|
||||
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", font=myFont)
|
||||
#imgmaps.append( [l, t, l+textlen, t+SIZE+2, "submap" + maparea, maparea + " subarea map"] )
|
||||
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)
|
||||
draw.line([l, t, l, b], fill='#777777', width=LINEWIDTH)
|
||||
@@ -265,6 +208,7 @@ def prospecting_image(request, name):
|
||||
draw.line([l, t, l, t+TEXTSIZE+2], fill='#777777', width=LINEWIDTH)
|
||||
draw.line([l+textlen, t, l+textlen, t+TEXTSIZE+2], fill='#777777', width=LINEWIDTH)
|
||||
#imgmaps[maparea] = []
|
||||
|
||||
# Draw scale bar
|
||||
m100 = int(100 / (m[R] - m[L]) * img.size[0])
|
||||
draw.line([10, TEXTSIZE*3, 10, TEXTSIZE*2], fill='#000000', width=LINEWIDTH)
|
||||
@@ -273,11 +217,8 @@ def prospecting_image(request, name):
|
||||
label = "100m"
|
||||
draw.text([10 + (m100 - draw.textsize(label)[0]) / 2, TEXTSIZE/2], label, fill='#000000', font=myFont)
|
||||
|
||||
ml = MapLocations()
|
||||
for p in ml.points():
|
||||
surveypoint, number, point_type, label = p
|
||||
plot(surveypoint, number, point_type, label, name, draw, img)
|
||||
|
||||
# Draw the circles for known points
|
||||
# Northing, Easting, Diameter - but N&E are swapped re database
|
||||
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
|
||||
@@ -297,8 +238,66 @@ def prospecting_image(request, name):
|
||||
draw.ellipse([lo[0]+2, lo[1]+2, hi[0]-2, hi[1]-2], outline=areacolours[maparea])
|
||||
draw.rectangle([lpos[0],lpos[1]-TEXTSIZE/2, lpos[0] + draw.textsize(name)[0], lpos[1]+TEXTSIZE/2], fill="#ffffff")
|
||||
draw.text((lpos[0], lpos[1]-TEXTSIZE/2), num, fill="#000000")
|
||||
#print(f' CIRCLES - {num} {(N,E,D)}')
|
||||
|
||||
# ml = MapLocations()
|
||||
# for p in ml.points():
|
||||
# surveypoint, number, point_type, label = p
|
||||
# print(f'{surveypoint}, {number}, {point_type}, {label}')
|
||||
# plot(surveypoint, number, True, label, name, draw, img)
|
||||
# print(f'{name},\n{draw},\n{img}')
|
||||
|
||||
ents = Entrance.objects.all() # only has entrances and fixed points in it these days,
|
||||
# but there are only 11 Entrances with northing, easting and a useable tag!
|
||||
D = 50
|
||||
for e in ents:
|
||||
try:
|
||||
E, N = e.easting, e.northing
|
||||
if e.tag_station:
|
||||
st = e.tag_station
|
||||
elif e.exact_station:
|
||||
st = e.exact_station
|
||||
elif e.exact_station:
|
||||
st = e.exact_station
|
||||
else:
|
||||
# print(f' No tag - {e.name} ')
|
||||
continue
|
||||
if not e.northing:
|
||||
continue
|
||||
lo = mungecoord(N-D, E+D, st, img)
|
||||
hi = mungecoord(N+D, E-D, st, img)
|
||||
lpos = mungecoord(N-D, E, st, img)
|
||||
|
||||
draw.ellipse([lo,hi], outline="#000000")
|
||||
draw.ellipse([lo[0]+1, lo[1]+1, hi[0]-1, hi[1]-1], outline="#ffffff")
|
||||
draw.ellipse([lo[0]+2, lo[1]+2, hi[0]-2, hi[1]-2], outline="#ffffff")
|
||||
draw.rectangle([lpos[0],lpos[1]-TEXTSIZE/2, lpos[0] + draw.textsize(st)[0], lpos[1]+TEXTSIZE/2], fill="#ffffff")
|
||||
draw.text((lpos[0], lpos[1]-TEXTSIZE/2), num, fill="#000000")
|
||||
|
||||
# draw.ellipse([(x-CIRCLESIZE,y-CIRCLESIZE),(x+CIRCLESIZE,y+CIRCLESIZE)], fill="red", outline="blue")
|
||||
# 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")
|
||||
#print(f' SUCCESS - {st} {(E, N)} ')
|
||||
except:
|
||||
#print(f' FAIL - {st} {(E, N)} ')
|
||||
pass
|
||||
|
||||
response = HttpResponse(content_type = "image/png")
|
||||
del draw
|
||||
img.save(response, "PNG")
|
||||
|
||||
return response
|
||||
return response
|
||||
|
||||
# def plot(surveypoint, number, point_type, label, mapcode, draw, img):
|
||||
# try:
|
||||
# ss = SurvexStation.objects.lookup(surveypoint)
|
||||
# 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] )
|
||||
# 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")
|
||||
# print(f' SUCCESS - YES {surveypoint}, {number}, {point_type}, {label}')
|
||||
# except:
|
||||
# print(f' - NO {surveypoint}, {number}, {point_type}, {label}')
|
||||
# pass
|
||||
|
||||
Reference in New Issue
Block a user