2020-05-28 01:16:45 +01:00
|
|
|
import os
|
|
|
|
import string
|
|
|
|
import re
|
|
|
|
import settings
|
|
|
|
import urllib.parse
|
2021-04-02 23:21:23 +01:00
|
|
|
import subprocess
|
|
|
|
from pathlib import Path
|
2020-05-28 01:16:45 +01:00
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
2021-04-02 23:21:23 +01:00
|
|
|
|
2012-01-07 19:05:25 +00:00
|
|
|
from django import forms
|
2020-05-28 01:16:45 +01:00
|
|
|
from django.conf import settings
|
2020-06-18 21:50:16 +01:00
|
|
|
from django.urls import reverse
|
2021-04-03 20:52:35 +01:00
|
|
|
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
|
2019-03-30 17:02:07 +00:00
|
|
|
from django.shortcuts import get_object_or_404, render
|
2021-03-28 23:47:47 +01:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
2013-08-01 16:00:01 +01:00
|
|
|
|
2020-05-28 01:16:45 +01:00
|
|
|
import troggle.settings as settings
|
2021-04-01 21:44:03 +01:00
|
|
|
from troggle.core.views import expo
|
2021-04-13 00:43:57 +01:00
|
|
|
from troggle.core.models.troggle import Expedition, DataIssue
|
2021-04-13 00:47:17 +01:00
|
|
|
from troggle.core.models.caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation, GetCaveLookup
|
2020-05-28 01:16:45 +01:00
|
|
|
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm
|
2021-04-02 15:51:14 +01:00
|
|
|
from .login import login_required_if_public
|
2019-02-26 00:43:05 +00:00
|
|
|
|
2021-04-13 01:37:42 +01:00
|
|
|
'''Manages the complex procedures to assemble a cave description out of the compnoents
|
|
|
|
Manages the use of cavern to parse survex files to produce 3d and pos files
|
|
|
|
|
|
|
|
Also generates the prospecting guide document.
|
|
|
|
'''
|
|
|
|
|
2020-05-28 01:16:45 +01:00
|
|
|
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"),
|
2020-06-15 03:28:51 +01:00
|
|
|
("topcamp", "OTC", "Reference", "Old Top Camp"),
|
2020-05-28 01:16:45 +01:00
|
|
|
("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():
|
2020-06-30 15:24:42 +01:00
|
|
|
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())
|
2021-03-28 23:47:47 +01:00
|
|
|
DataIssue.objects.create(parser='entrances', message=message)
|
2020-06-30 15:24:42 +01:00
|
|
|
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())
|
2021-03-28 23:47:47 +01:00
|
|
|
DataIssue.objects.create(parser='entrances', message=message)
|
2020-06-30 15:24:42 +01:00
|
|
|
print(message)
|
|
|
|
raise
|
2020-05-28 01:16:45 +01:00
|
|
|
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))
|
2011-07-11 02:10:22 +01:00
|
|
|
|
2021-04-02 23:21:23 +01:00
|
|
|
def getCaves(cave_id):
|
|
|
|
'''Only gets called if a call to getCave() raises a MultipleObjects exception
|
|
|
|
|
|
|
|
TO DO: search GCavelookup first, which should raise a MultpleObjectsReturned exception if there
|
|
|
|
are duplicates'''
|
|
|
|
try:
|
|
|
|
caves = Cave.objects.filter(kataster_number=cave_id)
|
|
|
|
caveset = set(caves)
|
|
|
|
|
|
|
|
Gcavelookup = GetCaveLookup() # dictionary makes strings to Cave objects
|
|
|
|
if cave_id in Gcavelookup:
|
|
|
|
caveset.add(Gcavelookup[cave_id])
|
|
|
|
return list(caveset)
|
|
|
|
except:
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
def getCave(cave_id):
|
2021-03-28 23:47:47 +01:00
|
|
|
'''Returns a cave object when given a cave name or number. It is used by views including cavehref, ent, and qm.
|
|
|
|
|
|
|
|
TO DO: search GCavelookup first, which should raise a MultpleObjectsReturned exception if there
|
|
|
|
are duplicates'''
|
2011-07-11 02:10:22 +01:00
|
|
|
try:
|
|
|
|
cave = Cave.objects.get(kataster_number=cave_id)
|
2021-03-31 20:18:46 +01:00
|
|
|
return cave
|
2021-03-28 23:47:47 +01:00
|
|
|
except Cave.MultipleObjectsReturned as ex:
|
|
|
|
raise MultipleObjectsReturned("Duplicate kataster number") from ex # propagate this up
|
|
|
|
|
2021-03-31 20:18:46 +01:00
|
|
|
except Cave.DoesNotExist as ex:
|
2021-03-28 23:47:47 +01:00
|
|
|
Gcavelookup = GetCaveLookup() # dictionary makes strings to Cave objects
|
|
|
|
if cave_id in Gcavelookup:
|
|
|
|
return Gcavelookup[cave_id]
|
2021-03-31 20:18:46 +01:00
|
|
|
else:
|
|
|
|
raise ObjectDoesNotExist("No cave found with this identifier in any id field") from ex # propagate this up
|
2021-03-28 23:47:47 +01:00
|
|
|
except:
|
|
|
|
raise ObjectDoesNotExist("No cave found with this identifier in any id field")
|
2011-07-11 02:10:22 +01:00
|
|
|
|
2012-08-05 18:26:24 +01:00
|
|
|
def pad5(x):
|
|
|
|
return "0" * (5 -len(x.group(0))) + x.group(0)
|
|
|
|
def padnumber(x):
|
|
|
|
return re.sub("\d+", pad5, x)
|
|
|
|
def numericalcmp(x, y):
|
|
|
|
return cmp(padnumber(x), padnumber(y))
|
|
|
|
|
2020-05-25 01:46:52 +01:00
|
|
|
def caveKey(x):
|
2020-07-28 01:22:06 +01:00
|
|
|
"""python3 function for sort. Done in a hurry.
|
2021-03-28 23:47:47 +01:00
|
|
|
Note that cave kataster numbers are not always integers.
|
2020-06-07 17:49:58 +01:00
|
|
|
This needs to be fixed make a decent sort order.
|
2020-05-25 01:46:52 +01:00
|
|
|
"""
|
2020-07-01 22:49:38 +01:00
|
|
|
if not x.kataster_number:
|
|
|
|
return "~"
|
2020-05-25 01:46:52 +01:00
|
|
|
return x.kataster_number
|
2012-06-10 14:59:21 +01:00
|
|
|
|
2020-06-07 16:13:59 +01:00
|
|
|
def getnotablecaves():
|
|
|
|
notablecaves = []
|
|
|
|
for kataster_number in settings.NOTABLECAVESHREFS:
|
|
|
|
try:
|
|
|
|
cave = Cave.objects.get(kataster_number=kataster_number)
|
|
|
|
notablecaves.append(cave)
|
|
|
|
except:
|
2021-04-03 20:52:35 +01:00
|
|
|
#print(" ! FAILED to get only one cave per kataster_number OR invalid number for: "+kataster_number)
|
2020-06-07 16:13:59 +01:00
|
|
|
caves = Cave.objects.all().filter(kataster_number=kataster_number)
|
|
|
|
for c in caves:
|
2021-04-03 20:52:35 +01:00
|
|
|
#print(c.kataster_number, c.slug())
|
2020-06-07 16:13:59 +01:00
|
|
|
if c.slug() != None:
|
|
|
|
notablecaves.append(c)
|
|
|
|
return notablecaves
|
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
def caveindex(request):
|
2019-06-26 20:57:24 +01:00
|
|
|
caves = Cave.objects.all()
|
2012-06-10 14:59:21 +01:00
|
|
|
caves1623 = list(Cave.objects.filter(area__short_name = "1623"))
|
|
|
|
caves1626 = list(Cave.objects.filter(area__short_name = "1626"))
|
2020-05-25 01:46:52 +01:00
|
|
|
caves1623.sort(key=caveKey)
|
|
|
|
caves1626.sort(key=caveKey)
|
2020-06-07 16:13:59 +01:00
|
|
|
return render(request,'caveindex.html', {'caves1623': caves1623, 'caves1626': caves1626, 'notablecaves':getnotablecaves(), 'cavepage': True})
|
2011-07-11 02:10:22 +01:00
|
|
|
|
2018-04-20 20:55:12 +01:00
|
|
|
def cave3d(request, cave_id=''):
|
2021-04-02 23:21:23 +01:00
|
|
|
'''This is used to create a download url in templates/cave.html if anyone wants to download the .3d file
|
|
|
|
The caller template tries kataster first, then unofficial_number if that kataster number does not exist
|
|
|
|
but only if Cave.survex_file is non-empty
|
2021-04-03 20:52:35 +01:00
|
|
|
|
|
|
|
But the template file cave.html has its own ideas about the name of the file and thus the href. Ouch.
|
|
|
|
/cave/3d/<cave_id>
|
2021-04-02 23:21:23 +01:00
|
|
|
'''
|
2021-03-28 23:47:47 +01:00
|
|
|
try:
|
2021-04-02 23:21:23 +01:00
|
|
|
cave = getCave(cave_id)
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
return None
|
|
|
|
except Cave.MultipleObjectsReturned:
|
|
|
|
# But only one might have survex data? So scan and return the first that works.
|
|
|
|
caves = getCaves(cave_id)
|
|
|
|
for c in caves:
|
|
|
|
if c.survex_file:
|
|
|
|
# exists, but may not be a valid file path to a valid .svx file in the Loser repo
|
|
|
|
return file3d(request, c, c.slug)
|
|
|
|
else:
|
|
|
|
return file3d(request, cave, cave_id)
|
|
|
|
|
|
|
|
def file3d(request, cave, cave_id):
|
|
|
|
'''Produces a .3d file directly for download.
|
2021-04-03 20:52:35 +01:00
|
|
|
survex_file should be in valid path format 'caves-1623/264/264.svx' but it might be mis-entered as simply '2012-ns-10.svx'
|
|
|
|
|
|
|
|
Also the cave.survex_file may well not match the cave description path:
|
|
|
|
e.g. it might be to the whole system 'smk-system.svx' instead of just for the specific cave.
|
2021-03-28 23:47:47 +01:00
|
|
|
|
2021-04-03 20:52:35 +01:00
|
|
|
- If the expected .3d file corresponding to cave.survex_file is present, return it.
|
|
|
|
- If the cave.survex_file exists, generate the 3d file, cache it and return it
|
|
|
|
- Use the cave_id to guess what the 3d file might be and, if in the cache, return it
|
|
|
|
- Use the cave_id to guess what the .svx file might be and generate the .3d file and return it
|
|
|
|
- (Use the incomplete cave.survex_file and a guess at the missing directories to guess the real .svx file location ?)
|
2021-04-02 23:21:23 +01:00
|
|
|
'''
|
2021-04-03 20:52:35 +01:00
|
|
|
def runcavern(survexpath):
|
|
|
|
#print(" - Regenerating cavern .log and .3d for '{}'".format(survexpath))
|
|
|
|
if not survexpath.is_file():
|
|
|
|
#print(" - - Regeneration ABORT\n - - from '{}'".format(survexpath))
|
2021-04-03 20:54:33 +01:00
|
|
|
pass
|
2021-04-02 23:21:23 +01:00
|
|
|
try:
|
2021-04-03 20:52:35 +01:00
|
|
|
completed_process = subprocess.run([settings.CAVERN, "--log", "--output={}".format(settings.THREEDCACHEDIR), "{}".format(survexpath)])
|
2021-04-02 23:21:23 +01:00
|
|
|
except OSError as ex:
|
2021-04-03 20:52:35 +01:00
|
|
|
# propagate this to caller.
|
|
|
|
raise OSError(completed_process.stdout) from ex
|
|
|
|
|
|
|
|
op3d = (Path(settings.THREEDCACHEDIR) / Path(survexpath).name).with_suffix('.3d')
|
|
|
|
op3dlog = Path(op3d.with_suffix('.log'))
|
|
|
|
|
|
|
|
if not op3d.is_file():
|
|
|
|
print(" - - Regeneration FAILED\n - - from '{}'\n - - to '{}'".format(survexpath, op3d))
|
|
|
|
print(" - - Regeneration stdout: ", completed_process.stdout)
|
|
|
|
print(" - - Regeneration cavern log output: ", op3dlog.read_text())
|
|
|
|
|
|
|
|
|
|
|
|
def return3d(threedpath):
|
|
|
|
if threedpath.is_file():
|
|
|
|
response = HttpResponse(content=open(threedpath, 'rb'), content_type='application/3d')
|
|
|
|
response['Content-Disposition'] = 'attachment; filename={}'.format(threedpath.name)
|
|
|
|
return response
|
|
|
|
else:
|
|
|
|
message = '<h1>Path provided does not correspond to any actual 3d file.</h1><p>path: "{}"'.format(threedpath)
|
|
|
|
#print(message)
|
|
|
|
return HttpResponseNotFound(message)
|
2021-04-02 23:21:23 +01:00
|
|
|
|
2021-04-03 20:52:35 +01:00
|
|
|
survexname = Path(cave.survex_file).name # removes directories
|
|
|
|
survexpath = Path(settings.SURVEX_DATA, cave.survex_file)
|
|
|
|
threedname = Path(survexname).with_suffix('.3d') # removes .svx, replaces with .3d
|
|
|
|
threedpath = Path(settings.THREEDCACHEDIR, threedname)
|
|
|
|
threedcachedir = Path(settings.THREEDCACHEDIR)
|
|
|
|
|
|
|
|
# These if statements need refactoring more cleanly
|
|
|
|
if cave.survex_file:
|
|
|
|
#print(" - cave.survex_file '{}'".format(cave.survex_file))
|
|
|
|
if threedpath.is_file():
|
|
|
|
#print(" - threedpath '{}'".format(threedpath))
|
|
|
|
# possible error here as several .svx files of same names in different directories will overwrite in /3d/
|
|
|
|
if survexpath.is_file():
|
|
|
|
if os.path.getmtime(survexpath) > os.path.getmtime(threedpath):
|
|
|
|
runcavern(survexpath)
|
|
|
|
return return3d(threedpath)
|
|
|
|
else:
|
|
|
|
#print(" - - survexpath '{}'".format(survexpath))
|
|
|
|
if survexpath.is_file():
|
|
|
|
#print(" - - - survexpath '{}'".format(survexpath))
|
|
|
|
runcavern(survexpath)
|
|
|
|
return return3d(threedpath)
|
|
|
|
|
|
|
|
# Get here if cave.survex_file was set but did not correspond to a valid svx file
|
|
|
|
if survexpath.is_file():
|
|
|
|
# a file, but invalid format
|
|
|
|
message='<h1>File is not valid .svx format.</h1><p>Could not generate 3d file from "{}"'.format(survexpath)
|
2021-04-02 23:21:23 +01:00
|
|
|
else:
|
2021-04-03 20:52:35 +01:00
|
|
|
# we could try to guess that 'caves-1623/' is missing,... nah.
|
|
|
|
message = '<h1>Path provided does not correspond to any actual file.</h1><p>path: "{}"'.format(survexpath)
|
|
|
|
|
|
|
|
return HttpResponseNotFound(message)
|
|
|
|
|
|
|
|
|
|
|
|
def rendercave(request, cave, slug, cave_id=''):
|
|
|
|
'''Gets the data and files ready and then triggers Django to render the template.
|
|
|
|
The resulting html contains urls which are dispatched independently, e.g. the 'download' link
|
|
|
|
'''
|
|
|
|
#print(" ! rendercave:'{}' slug:'{}' cave_id:'{}'".format(cave, slug, cave_id))
|
|
|
|
|
2021-04-07 21:53:17 +01:00
|
|
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated:
|
2021-04-03 20:52:35 +01:00
|
|
|
return render(request, 'nonpublic.html', {'instance': cave, 'cavepage': True, 'cave_id': cave_id})
|
|
|
|
else:
|
|
|
|
svxstem = Path(cave.survex_file).parent / Path(cave.survex_file).stem
|
|
|
|
svx3d = Path(cave.survex_file).stem
|
2021-04-14 00:11:59 +01:00
|
|
|
|
2021-04-03 20:52:35 +01:00
|
|
|
# NOTE the template itself loads the 3d file using javascript before it loads anything else.
|
|
|
|
# Django cannot see what this javascript is doing, so we need to ensure that the 3d file exists first.
|
|
|
|
# run this just for the side-effect of generating the 3d file? Nope, crashes.
|
2021-04-14 00:11:59 +01:00
|
|
|
# TO DO - restructure this so that the regeneration is callable from here.
|
2021-04-03 20:52:35 +01:00
|
|
|
#discard_response = cave3d(request, cave_id=cave_id)
|
2021-04-14 00:11:59 +01:00
|
|
|
|
|
|
|
if request.user.is_authenticated:
|
|
|
|
editable = True
|
|
|
|
else:
|
|
|
|
editable = False
|
|
|
|
print(" ! rendercave:'{}' svxstem:{} svx3d:'{}'".format(cave, svxstem, svx3d))
|
|
|
|
return render(request,'cave.html', {'cave_editable': editable, 'settings': settings, 'cave': cave, 'cavepage': True,
|
2021-04-03 20:52:35 +01:00
|
|
|
'cave_id': cave_id, 'svxstem': svxstem, 'svx3d':svx3d})
|
2018-04-17 21:57:02 +01:00
|
|
|
|
2021-04-01 20:08:57 +01:00
|
|
|
def cavepage(request, karea, subpath):
|
2021-04-01 21:44:03 +01:00
|
|
|
'''Displays a cave description page
|
2021-04-03 20:52:35 +01:00
|
|
|
accessed by kataster area number specifically
|
2021-04-01 21:44:03 +01:00
|
|
|
|
|
|
|
There are A LOT OF URLS to e.g. /1623/161/l/rl89a.htm which are IMAGES and html files
|
|
|
|
in cave descriptions. These need to be handled HERE
|
|
|
|
'''
|
2021-04-01 20:08:57 +01:00
|
|
|
path = karea + subpath
|
2021-04-03 20:52:35 +01:00
|
|
|
#print(" ! cavepage:'{}' kataster area:'{}' rest of path:'{}'".format(path, karea, subpath))
|
2021-04-01 20:08:57 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
cave = Cave.objects.get(url = path) # ideally this will be unique
|
2021-04-03 20:52:35 +01:00
|
|
|
return rendercave(request, cave, cave.slug())
|
|
|
|
|
2021-04-01 20:08:57 +01:00
|
|
|
except Cave.DoesNotExist:
|
2021-04-01 21:44:03 +01:00
|
|
|
# probably a link to text or an image e.g. 1623/161/l/rl89a.htm i.e. an expoweb page
|
|
|
|
return expo.expopage(request, path)
|
2021-04-01 20:08:57 +01:00
|
|
|
except Cave.MultipleObjectsReturned:
|
|
|
|
caves = Cave.objects.filter(url = path)
|
|
|
|
return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves })
|
|
|
|
except:
|
|
|
|
return render(request, 'pagenotfound.html', {'path': path})
|
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
def cave(request, cave_id='', offical_name=''):
|
2021-04-03 20:52:35 +01:00
|
|
|
'''Displays a cave description page
|
|
|
|
accesssed by a fairly random id which might be anything
|
|
|
|
'''
|
2021-03-28 23:47:47 +01:00
|
|
|
try:
|
|
|
|
cave=getCave(cave_id)
|
|
|
|
except MultipleObjectsReturned:
|
|
|
|
caves = Cave.objects.filter(kataster_number=cave_id)
|
|
|
|
return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves }) # not the right template, needs a specific one
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
return render(request, 'svxcavesingle404.html', {'settings': settings, "cave":cave_id })
|
2021-03-31 20:18:46 +01:00
|
|
|
except:
|
|
|
|
return render(request, 'svxcavesingle404.html', {'settings': settings })
|
2021-03-28 23:47:47 +01:00
|
|
|
|
2021-04-03 20:52:35 +01:00
|
|
|
return rendercave(request, cave, cave.slug(), cave_id=cave_id)
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
def caveEntrance(request, slug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = slug)
|
2021-04-07 21:53:17 +01:00
|
|
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated:
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'nonpublic.html', {'instance': cave})
|
2011-07-11 02:10:22 +01:00
|
|
|
else:
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'cave_entrances.html', {'cave': cave})
|
2012-05-23 09:23:40 +01:00
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
def caveDescription(request, slug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = slug)
|
2021-04-07 21:53:17 +01:00
|
|
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated:
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'nonpublic.html', {'instance': cave})
|
2011-07-11 02:10:22 +01:00
|
|
|
else:
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'cave_uground_description.html', {'cave': cave})
|
2016-07-02 23:42:47 +01:00
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
def caveQMs(request, slug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = slug)
|
2021-04-07 21:53:17 +01:00
|
|
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated:
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'nonpublic.html', {'instance': cave})
|
2011-07-11 02:10:22 +01:00
|
|
|
else:
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'cave_qms.html', {'cave': cave})
|
2021-04-01 20:08:57 +01:00
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
def caveLogbook(request, slug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = slug)
|
2021-04-07 21:53:17 +01:00
|
|
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated:
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'nonpublic.html', {'instance': cave})
|
2011-07-11 02:10:22 +01:00
|
|
|
else:
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'cave_logbook.html', {'cave': cave})
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
@login_required_if_public
|
2012-01-07 19:05:25 +00:00
|
|
|
def edit_cave(request, slug=None):
|
2021-04-02 23:21:23 +01:00
|
|
|
'''This is the form that edits all the cave data and writes out an XML file in the :expoweb: repo folder
|
|
|
|
The format for the file being saved is in templates/dataformat/cave.xml
|
|
|
|
'''
|
2012-08-12 18:10:23 +01:00
|
|
|
if slug is not None:
|
|
|
|
cave = Cave.objects.get(caveslug__slug = slug)
|
|
|
|
else:
|
|
|
|
cave = Cave()
|
2012-05-23 09:23:40 +01:00
|
|
|
if request.POST:
|
|
|
|
form = CaveForm(request.POST, instance=cave)
|
|
|
|
ceFormSet = CaveAndEntranceFormSet(request.POST)
|
2012-06-10 14:59:21 +01:00
|
|
|
versionControlForm = VersionControlCommentForm(request.POST)
|
|
|
|
if form.is_valid() and ceFormSet.is_valid() and versionControlForm.is_valid():
|
2012-08-12 18:10:23 +01:00
|
|
|
cave = form.save(commit = False)
|
2012-08-14 21:51:15 +01:00
|
|
|
if slug is None:
|
|
|
|
for a in form.cleaned_data["area"]:
|
|
|
|
if a.kat_area():
|
|
|
|
myArea = a.kat_area()
|
|
|
|
if form.cleaned_data["kataster_number"]:
|
|
|
|
myslug = "%s-%s" % (myArea, form.cleaned_data["kataster_number"])
|
|
|
|
else:
|
|
|
|
myslug = "%s-%s" % (myArea, form.cleaned_data["unofficial_number"])
|
|
|
|
else:
|
|
|
|
myslug = slug
|
|
|
|
cave.filename = myslug + ".html"
|
2012-08-12 18:10:23 +01:00
|
|
|
cave.save()
|
|
|
|
form.save_m2m()
|
|
|
|
if slug is None:
|
2012-08-14 21:51:15 +01:00
|
|
|
cs = CaveSlug(cave = cave, slug = myslug, primary = True)
|
2012-08-12 18:10:23 +01:00
|
|
|
cs.save()
|
2012-06-10 14:59:21 +01:00
|
|
|
ceinsts = ceFormSet.save(commit=False)
|
|
|
|
for ceinst in ceinsts:
|
|
|
|
ceinst.cave = cave
|
|
|
|
ceinst.save()
|
|
|
|
cave.writeDataFile()
|
|
|
|
return HttpResponseRedirect("/" + cave.url)
|
2012-05-23 09:23:40 +01:00
|
|
|
else:
|
|
|
|
form = CaveForm(instance=cave)
|
2012-06-10 14:59:21 +01:00
|
|
|
ceFormSet = CaveAndEntranceFormSet(queryset=cave.caveandentrance_set.all())
|
|
|
|
versionControlForm = VersionControlCommentForm()
|
|
|
|
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,
|
2012-01-07 19:05:25 +00:00
|
|
|
'editcave2.html',
|
|
|
|
{'form': form,
|
2012-06-10 14:59:21 +01:00
|
|
|
'caveAndEntranceFormSet': ceFormSet,
|
|
|
|
'versionControlForm': versionControlForm
|
|
|
|
})
|
|
|
|
|
|
|
|
@login_required_if_public
|
2012-08-14 21:51:15 +01:00
|
|
|
def editEntrance(request, caveslug, slug=None):
|
|
|
|
cave = Cave.objects.get(caveslug__slug = caveslug)
|
2012-08-12 18:10:23 +01:00
|
|
|
if slug is not None:
|
|
|
|
entrance = Entrance.objects.get(entranceslug__slug = slug)
|
|
|
|
else:
|
|
|
|
entrance = Entrance()
|
2012-06-10 14:59:21 +01:00
|
|
|
if request.POST:
|
|
|
|
form = EntranceForm(request.POST, instance = entrance)
|
|
|
|
versionControlForm = VersionControlCommentForm(request.POST)
|
2012-08-14 21:51:15 +01:00
|
|
|
if slug is None:
|
|
|
|
entletter = EntranceLetterForm(request.POST)
|
|
|
|
else:
|
|
|
|
entletter = None
|
|
|
|
if form.is_valid() and versionControlForm.is_valid() and (slug is not None or entletter.is_valid()):
|
2012-08-12 18:10:23 +01:00
|
|
|
entrance = form.save(commit = False)
|
|
|
|
if slug is None:
|
2012-08-14 21:51:15 +01:00
|
|
|
slugname = cave.slug() + entletter.cleaned_data["entrance_letter"]
|
|
|
|
entrance.cached_primary_slug = slugname
|
|
|
|
entrance.filename = slugname + ".html"
|
2012-08-12 18:10:23 +01:00
|
|
|
entrance.save()
|
|
|
|
if slug is None:
|
2012-08-14 21:51:15 +01:00
|
|
|
es = EntranceSlug(entrance = entrance, slug = slugname, primary = True)
|
|
|
|
es.save()
|
|
|
|
el = entletter.save(commit = False)
|
|
|
|
el.cave = cave
|
|
|
|
el.entrance = entrance
|
|
|
|
el.save()
|
2012-06-10 14:59:21 +01:00
|
|
|
entrance.writeDataFile()
|
2012-08-14 21:51:15 +01:00
|
|
|
return HttpResponseRedirect("/" + cave.url)
|
2012-06-10 14:59:21 +01:00
|
|
|
else:
|
|
|
|
form = EntranceForm(instance = entrance)
|
|
|
|
versionControlForm = VersionControlCommentForm()
|
2012-08-14 21:51:15 +01:00
|
|
|
if slug is None:
|
|
|
|
entletter = EntranceLetterForm(request.POST)
|
|
|
|
else:
|
|
|
|
entletter = None
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,
|
2012-06-10 14:59:21 +01:00
|
|
|
'editentrance.html',
|
|
|
|
{'form': form,
|
2012-08-14 21:51:15 +01:00
|
|
|
'versionControlForm': versionControlForm,
|
|
|
|
'entletter': entletter
|
2012-01-07 19:05:25 +00:00
|
|
|
})
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
def qm(request,cave_id,qm_id,year,grade=None):
|
|
|
|
year=int(year)
|
|
|
|
try:
|
2021-03-28 23:47:47 +01:00
|
|
|
qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year)
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'qm.html',locals())
|
2021-03-28 23:47:47 +01:00
|
|
|
except Cave.MultipleObjectsReturned: # entirely the wrong action, REPLACE with the right display
|
|
|
|
caves = Cave.objects.filter(kataster_number=cave_id)
|
|
|
|
return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves })
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
except QM.DoesNotExist:
|
2020-05-24 13:31:38 +01:00
|
|
|
url=urllib.parse.urljoin(settings.URL_ROOT, r'/admin/core/qm/add/'+'?'+ r'number=' + qm_id)
|
2011-07-11 02:10:22 +01:00
|
|
|
if grade:
|
|
|
|
url += r'&grade=' + grade
|
|
|
|
return HttpResponseRedirect(url)
|
|
|
|
|
|
|
|
def ent(request, cave_id, ent_letter):
|
|
|
|
cave = Cave.objects.filter(kataster_number = cave_id)[0]
|
|
|
|
cave_and_ent = CaveAndEntrance.objects.filter(cave = cave).filter(entrance_letter = ent_letter)[0]
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'entrance.html', {'cave': cave,
|
2011-07-11 02:10:22 +01:00
|
|
|
'entrance': cave_and_ent.entrance,
|
|
|
|
'letter': cave_and_ent.entrance_letter,})
|
|
|
|
|
|
|
|
def entranceSlug(request, slug):
|
2012-06-10 14:59:21 +01:00
|
|
|
entrance = Entrance.objects.get(entranceslug__slug = slug)
|
2021-04-07 21:53:17 +01:00
|
|
|
if entrance.non_public and not request.user.is_authenticated:
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'nonpublic.html', {'instance': entrance})
|
2011-07-11 02:10:22 +01:00
|
|
|
else:
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'entranceslug.html', {'entrance': entrance})
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
def surveyindex(request):
|
|
|
|
surveys=Survey.objects.all()
|
|
|
|
expeditions=Expedition.objects.order_by("-year")
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'survey.html',locals())
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
def get_entrances(request, caveslug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = caveslug)
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]})
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
def get_qms(request, caveslug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = caveslug)
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]})
|
2012-08-10 18:02:13 +01:00
|
|
|
|
2021-04-01 20:08:57 +01:00
|
|
|
AREANAMES = [
|
2019-06-26 20:57:24 +01:00
|
|
|
#('', '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')
|
|
|
|
]
|
2012-08-10 18:02:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
def prospecting(request):
|
2021-04-01 20:08:57 +01:00
|
|
|
#for key, name in AREANAMES:
|
|
|
|
#print(key, Area.objects.get(short_name = key))
|
2013-08-01 16:00:01 +01:00
|
|
|
areas = []
|
2021-04-01 20:08:57 +01:00
|
|
|
for key, name in AREANAMES:
|
|
|
|
a = Area.objects.get(short_name = key) # assumes unique
|
2013-08-01 16:00:01 +01:00
|
|
|
caves = list(a.cave_set.all())
|
2020-07-20 23:47:52 +01:00
|
|
|
caves.sort(key=caveKey)
|
2013-08-01 16:00:01 +01:00
|
|
|
areas.append((name, a, caves))
|
2019-03-30 17:02:07 +00:00
|
|
|
return render(request, 'prospecting.html', {"areas": areas})
|
2013-08-01 16:00:01 +01:00
|
|
|
|
|
|
|
# Parameters for big map and zoomed subarea maps:
|
|
|
|
# big map first (zoom factor ignored)
|
|
|
|
|
|
|
|
maps = {
|
2019-06-26 20:57:24 +01:00
|
|
|
# id left top right bottom zoom
|
|
|
|
# G&K G&K G&K G&K factor
|
|
|
|
"all": [33810.4, 85436.5, 38192.0, 81048.2, 0.35,
|
|
|
|
"All"],
|
|
|
|
"40": [36275.6, 82392.5, 36780.3, 81800.0, 3.0,
|
|
|
|
"Eishöhle"],
|
|
|
|
"76": [35440.0, 83220.0, 36090.0, 82670.0, 1.3,
|
|
|
|
"Eislufthöhle"],
|
|
|
|
"204": [36354.1, 84154.5, 37047.4, 83300, 3.0,
|
|
|
|
"Steinbrückenhöhle"],
|
|
|
|
"tc": [35230.0, 82690.0, 36110.0, 82100.0, 3.0,
|
|
|
|
"Near Top Camp"],
|
2013-08-01 16:00:01 +01:00
|
|
|
"grieß":
|
2019-06-26 20:57:24 +01:00
|
|
|
[36000.0, 86300.0, 38320.0, 84400.0, 4.0,
|
|
|
|
"Grießkogel Area"],
|
2013-08-01 16:00:01 +01:00
|
|
|
}
|
|
|
|
|
2020-05-24 13:31:38 +01:00
|
|
|
for n in list(maps.keys()):
|
2013-08-01 16:00:01 +01:00
|
|
|
L, T, R, B, S, name = maps[n]
|
|
|
|
W = (R-L)/2
|
|
|
|
H = (T-B)/2
|
|
|
|
for i in range(2):
|
2018-04-20 20:55:12 +01:00
|
|
|
for j in range(2):
|
|
|
|
maps["%s%i%i" % (n, i, j)] = [L + i * W, T - j * H, L + (i + 1) * W, T - (j + 1) * H, S, name]
|
2013-08-01 16:00:01 +01:00
|
|
|
# Keys in the order in which we want the maps output
|
|
|
|
mapcodes = ["all", "grieß","40", "76", "204", "tc"]
|
|
|
|
# Field codes
|
|
|
|
L = 0
|
|
|
|
T = 1
|
|
|
|
R = 2
|
|
|
|
B = 3
|
|
|
|
ZOOM = 4
|
|
|
|
DESC = 5
|
|
|
|
|
|
|
|
areacolours = {
|
2019-06-26 20:57:24 +01:00
|
|
|
'1a' : '#00ffff',
|
|
|
|
'1b' : '#ff00ff',
|
|
|
|
'1c' : '#ffff00',
|
|
|
|
'1d' : '#ffffff',
|
|
|
|
'2a' : '#ff0000',
|
|
|
|
'2b' : '#00ff00',
|
|
|
|
'2c' : '#008800',
|
|
|
|
'2d' : '#ff9900',
|
|
|
|
'3' : '#880000',
|
|
|
|
'4' : '#0000ff',
|
|
|
|
'6' : '#000000', # doubles for surface fixed pts, and anything else
|
|
|
|
'7' : '#808080'
|
|
|
|
}
|
2013-08-01 16:00:01 +01:00
|
|
|
|
|
|
|
for FONT in [
|
2019-06-26 20:57:24 +01:00
|
|
|
"/usr/share/fonts/truetype/freefont/FreeSans.ttf",
|
|
|
|
"/usr/X11R6/lib/X11/fonts/truetype/arial.ttf",
|
2020-02-22 00:04:41 +00:00
|
|
|
"/mnt/c/windows/fonts/arial.ttf",
|
2019-06-26 20:57:24 +01:00
|
|
|
"C:\WINNT\Fonts\ARIAL.TTF"
|
|
|
|
]:
|
|
|
|
if os.path.isfile(FONT): break
|
2013-08-01 16:00:01 +01:00
|
|
|
TEXTSIZE = 16
|
|
|
|
CIRCLESIZE =8
|
|
|
|
LINEWIDTH = 2
|
|
|
|
myFont = ImageFont.truetype(FONT, TEXTSIZE)
|
|
|
|
|
|
|
|
def mungecoord(x, y, mapcode, img):
|
2019-06-26 20:57:24 +01:00
|
|
|
# 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)
|
|
|
|
|
|
|
|
m = maps[mapcode]
|
|
|
|
factorX, factorY = img.size[0] / (m[R] - m[L]), img.size[1] / (m[T] - m[B])
|
|
|
|
return ((x - m[L]) * factorX, (m[T] - y) * factorY)
|
|
|
|
|
2013-08-01 16:00:01 +01:00
|
|
|
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("—","")
|
2020-05-24 13:31:38 +01:00
|
|
|
(x,y) = list(map(int, mungecoord(E, N, mapcode, img)))
|
2013-08-01 16:00:01 +01:00
|
|
|
#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):
|
2020-06-13 01:26:59 +01:00
|
|
|
# We should replace all this with something that exports an overlay for Google Maps and OpenStreetView
|
2013-08-01 16:00:01 +01:00
|
|
|
mainImage = Image.open(os.path.join(settings.SURVEY_SCANS, "location_maps", "pguidemap.jpg"))
|
2021-04-07 21:53:17 +01:00
|
|
|
if settings.PUBLIC_SITE and not request.user.is_authenticated:
|
2020-05-24 13:31:38 +01:00
|
|
|
mainImage = Image.new("RGB", mainImage.size, '#ffffff')
|
2013-08-01 16:00:01 +01:00
|
|
|
m = maps[name]
|
|
|
|
#imgmaps = []
|
|
|
|
if name == "all":
|
2020-05-24 13:31:38 +01:00
|
|
|
img = mainImage
|
2013-08-01 16:00:01 +01:00
|
|
|
else:
|
2020-05-24 13:31:38 +01:00
|
|
|
M = maps['all']
|
|
|
|
W, H = mainImage.size
|
|
|
|
l = int((m[L] - M[L]) / (M[R] - M[L]) * W)
|
|
|
|
t = int((m[T] - M[T]) / (M[B] - M[T]) * H)
|
|
|
|
r = int((m[R] - M[L]) / (M[R] - M[L]) * W)
|
|
|
|
b = int((m[B] - M[T]) / (M[B] - M[T]) * H)
|
|
|
|
img = mainImage.crop((l, t, r, b))
|
|
|
|
w = int(round(m[ZOOM] * (m[R] - m[L]) / (M[R] - M[L]) * W))
|
|
|
|
h = int(round(m[ZOOM] * (m[B] - m[T]) / (M[B] - M[T]) * H))
|
|
|
|
img = img.resize((w, h), Image.BICUBIC)
|
2013-08-01 16:00:01 +01:00
|
|
|
draw = ImageDraw.Draw(img)
|
|
|
|
draw.setfont(myFont)
|
|
|
|
if name == "all":
|
2020-05-24 13:31:38 +01:00
|
|
|
for maparea in list(maps.keys()):
|
|
|
|
if maparea == "all":
|
|
|
|
continue
|
|
|
|
localm = maps[maparea]
|
|
|
|
l,t = mungecoord(localm[L], localm[T], "all", img)
|
|
|
|
r,b = mungecoord(localm[R], localm[B], "all", img)
|
|
|
|
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")
|
|
|
|
#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)
|
|
|
|
draw.line([r, t, r, b], fill='#777777', width=LINEWIDTH)
|
|
|
|
draw.line([l, t, l+textlen, t], fill='#777777', width=LINEWIDTH)
|
|
|
|
draw.line([l, t+TEXTSIZE+2, l+textlen, t+TEXTSIZE+2], fill='#777777', width=LINEWIDTH)
|
|
|
|
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)
|
2013-08-01 16:00:01 +01:00
|
|
|
#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)
|
|
|
|
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')
|
2020-05-28 01:16:45 +01:00
|
|
|
|
|
|
|
for p in MapLocations.points():
|
|
|
|
surveypoint, number, point_type, label = p
|
|
|
|
plot(surveypoint, number, point_type, label, name, draw, img)
|
|
|
|
|
2020-05-24 13:31:38 +01:00
|
|
|
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
|
|
|
|
(35650.00, 82025.00, 50, "44"), # From Auer map
|
|
|
|
(36200.00, 82925.00, 50, "178"), # Calculated from bearings
|
|
|
|
(35232.64, 82910.37, 25, "181"), # Calculated from bearings
|
|
|
|
(35323.60, 81357.83, 50, "74") # From Auer map
|
2013-08-01 16:00:01 +01:00
|
|
|
]:
|
2020-05-24 13:31:38 +01:00
|
|
|
(N,E,D) = list(map(float, (N, E, D)))
|
2013-08-01 16:00:01 +01:00
|
|
|
maparea = Cave.objects.get(kataster_number = num).getArea().short_name
|
|
|
|
lo = mungecoord(N-D, E+D, name, img)
|
|
|
|
hi = mungecoord(N+D, E-D, name, img)
|
|
|
|
lpos = mungecoord(N-D, E, name, img)
|
|
|
|
draw.ellipse([lo,hi], outline="#000000")
|
|
|
|
draw.ellipse([lo[0]+1, lo[1]+1, hi[0]-1, hi[1]-1], outline=areacolours[maparea])
|
|
|
|
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")
|
|
|
|
response = HttpResponse(content_type = "image/png")
|
|
|
|
del draw
|
|
|
|
img.save(response, "PNG")
|
2020-05-28 01:16:45 +01:00
|
|
|
return response
|