2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-13 10:28:35 +00:00

undropped caves code -> GPX

This commit is contained in:
2025-07-29 17:08:36 +02:00
parent 7564ce4d27
commit 959c358c09
7 changed files with 45 additions and 3 deletions

View File

@@ -302,7 +302,7 @@ class Entrance(TroggleModel):
def other_location(self):
return self.single(self.other_station)
def find_location(self):
r = {"": "To be entered ", "?": "To be confirmed:", "S": "", "L": "Lost:", "R": "Refindable:"}[self.findability]
if self.tag_station:

View File

@@ -113,7 +113,13 @@ class SurvexStation(models.Model):
return diff_str, ref
def gpx_location(s): # s == self
# <wpt lon="13.82093593" lat="47.69501184"><ele>1857.90</ele><name>tunnocks</name></wpt>
latitude, longitude = utmToLatLng(33, s.x, s.y, northernHemisphere=True)
if s.name:
return f'<wpt lon="{longitude:0.8f}" lat="{latitude:0.8f}"><ele>{s.z:0.0f}</ele><name>{s.name[5:]}</name></wpt>\n'
else:
return ""
def utmToLatLng(zone, easting, northing, northernHemisphere=True): # move this to utils.py ?

View File

@@ -5,6 +5,7 @@ import tempfile
import urllib
import zipfile
from pathlib import Path
from datetime import datetime, timezone
import django
from bs4 import BeautifulSoup
@@ -20,6 +21,7 @@ from troggle.core.forms import CaveForm, EntranceForm, EntranceLetterForm # Cav
from troggle.core.models.caves import Cave, CaveAndEntrance, Entrance, GetCaveLookup, get_cave_leniently
from troggle.core.models.logbooks import QM
from troggle.core.models.wallets import Wallet
from troggle.core.models.survex import SurvexStation
from troggle.core.utils import (
get_cookie_max_age,
WriteAndCommitError,
@@ -205,6 +207,32 @@ def getnotablecaves():
print(notablecaves)
return notablecaves
def caves_undropped_gpx(request):
caves1623 = Cave.objects.filter(areacode="1623",unexplored="True")
caves1626 = Cave.objects.filter(areacode="1626",unexplored="True")
allcaves = list(caves1623) + list(caves1626)
ent_locations = []
for cave in allcaves:
ces = CaveAndEntrance.objects.filter(cave=cave)
for ce in ces:
stations = SurvexStation.objects.filter(entrance=ce.entrance)
for station in stations:
if gpx := station.gpx_location():
ent_locations.append(gpx)
return render(
request,
"cavesundroppedgpx.html",
{"ent_locations": ent_locations,
"now" : datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"), # GPX format and UTC timezone
"year": current_expo()},
)
def caves_undropped(request):
caves1623 = list(Cave.objects.filter(areacode="1623",unexplored="True"))
caves1626 = list(Cave.objects.filter(areacode="1626",unexplored="True"))

View File

@@ -10,7 +10,8 @@
<p>
See <em><a href="/caves">All Caves</a></em> for all the caves in areas 1623, 1626, 1624, 1627 <br />
See <em><a href="/caves_recent">Recent Caves</a></em> for a full list of recent caves.
See <em><a href="/caves_recent">Recent Caves</a></em> for a full list of recent caves.<br />
Download <em><a href="/caves_undropped_gpx" download="undropped.gpx">Undropped GPX file</a></em> (This is only the subset which are fully located.)
<p style="text-align:right">
<a href="{% url "newcave" %}">New Cave</a><br>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.0" creator="troggle https://expo.survex.com/troggle" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
<name>Expo undropped caves</name>
<time>{{now}}</time>
{% for e in ent_locations %}{{e|safe}}{% endfor %}</gpx>

View File

@@ -12,6 +12,7 @@ from troggle.core.views.caves import (
cave_debug,
caves_recent,
caves_undropped,
caves_undropped_gpx,
cavesall,
cavepage,
caveQMs,
@@ -161,6 +162,7 @@ trogglepatterns = [
path('caveslist', caveslist, name="caveslist"),
path('caves_recent', caves_recent, name="caves_recent"),
path('caves_undropped', caves_undropped, name="caves_undropped"),
path('caves_undropped_gpx', caves_undropped_gpx, name="caves_undropped_gpx"),
path('entrances', entranceindex, name="entranceindex"),
path('enttags', entrancetags, name="entrancetags"),