Commit 0a9090b6 authored by Jean-Benoist Leger's avatar Jean-Benoist Leger

Add GPX generation and download

parent b516e83c
......@@ -38,7 +38,7 @@ function load_map() {
var osmfrUrl = 'http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png';
var osmfr = new L.TileLayer(osmfrUrl, {maxZoom: 18, attribution: osmAttribution});
herve.map.setView(new L.LatLng(47.25, 1.8), 6);
herve.map.setView(new L.LatLng(40.845165, -77.483849), 8);
var baseLayers = {
"OpenStreetMap": osm,
......@@ -403,6 +403,7 @@ function compute()
$('#status').html('<p>Routage en cours…</p>');
$('#global_results').html('');
$('#links').html('');
herve.displaytimer = window.setInterval("updateRoutingStatus()",500);
}
......@@ -495,9 +496,30 @@ function updateResults(data)
redraw(42);
herve.map.fitBounds(data.bounds);
txt='<p>Routage terminé.</p>'
+'<p>Cliquez sur le trajet pour obtenir des infos détaillés</p>'
+'<p><a href="#' + herve.jid + '">Lien vers l\'itinéraire</a></p>';
+'<p>Cliquez sur le trajet pour obtenir des infos détaillés</p>';
$('#status').html(txt);
showLinks()
}
function showLinks()
{
txt='<p><a href="#' + herve.jid + '">Lien vers l\'itinéraire</a> '
+'<a href="#" onclick="showGpx(); return false;">Route au format GPX</a>'
+'</p>'
+'<hr />';
$('#links').html(txt);
}
function showGpx()
{
txt='<ul>'
+'<li><a href="/py/getGPX.py?jid=' + herve.jid + '&minimal=0&step=0&nptsmax=0">GPX avec tous les pts</a></li>'
+'<li><a href="/py/getGPX.py?jid=' + herve.jid + '&minimal=1&step=0&nptsmax=0">GPX avec uniquement les pts d\'itersection</a></li>'
+'<li><a href="/py/getGPX.py?jid=' + herve.jid + '&minimal=0&step=200&nptsmax=50">GPX pour Garmin (50 pt max)</a></li>'
+'</ul>'
+'<p><a href="#" onclick="showLinks(); return false;">Retour</a></p>'
+'<hr />';
$('#links').html(txt);
}
function updateGlobalResults(results)
......
......@@ -4,8 +4,10 @@ import psycopg2
import sys
import numpy as np
import colorsys
import gpxpy
import gpxpy.gpx
from secret import dbstr
from secret import *
class Node:
"""node with routing information
......@@ -121,6 +123,78 @@ def getPoints(jid):
return lPoints
def getGPX(jid,minimal=True,step=0,nptsmax=0):
db = psycopg2.connect(dbstr)
cur = db.cursor()
cur.execute("SELECT ST_X(geom),ST_Y(geom),height,way_id,dist FROM rv_results WHERE jid=%s ORDER BY rank;",(jid,))
if cur.rowcount<1:
return None
Lpts = []
for ligne in cur:
lon=ligne[0]
lat=ligne[1]
height=ligne[2]
way_id=ligne[3]
dist=ligne[4]
Lpts.append( [lon,lat,height,way_id,dist] )
cur.close()
db.close()
total_dist = Lpts[-1][4]
if nptsmax>0:
if total_dist>step*nptsmax:
step = total_dist*1.0/nptsmax
for i in range(1,len(Lpts)):
if Lpts[i-1][3] == 0:
Lpts[i-1][3]=Lpts[i][3]
gpx_route = gpxpy.gpx.GPXRoute()
current_way_id=0
current_dist=0
for i in range(len(Lpts)):
we_use_it = False
if minimal:
if Lpts[i][3]!=current_way_id:
we_use_it=True
else:
if Lpts[i][4]-current_dist > step:
we_use_it=True
if i==0 or i==len(Lpts)-1:
we_use_it=True
if we_use_it:
current_dist = Lpts[i][4]
current_way_id=Lpts[i][3]
gpx_route.points.append(
gpxpy.gpx.GPXRoutePoint(
longitude=Lpts[i][0],
latitude=Lpts[i][1],
elevation=Lpts[i][2]
)
)
gpx = gpxpy.gpx.GPX()
gpx.name='RV result %d' % jid
gpx_route.name='RV result %d' % jid
gpx.author='RV routing engine'
gpx.creator='RV routing engine'
gpx.url= url_jid % jid
gpx.routes.append(gpx_route)
return gpx.to_xml()
def getFeatColl(lPoints_ref,pas,simplify=False):
lPoints = lPoints_ref[:]
......
......@@ -111,8 +111,7 @@ print json.dumps({'jid':jid})
sys.stdout.flush()
with daemon.DaemonContext():
subprocess.Popen(["nohup", "/home/rv/rv/route/rv_route", dbstr, ("%d"%jid)])
subprocess.Popen(["/sbin/start-stop-daemon",'-S','-b','-p','/tmp/does-not-exists','--exec',"/home/rv/rv/route/rv_route",'--', dbstr, ("%d"%jid)])
......@@ -73,7 +73,7 @@ void database::write_results(std::list<instant> lI, double puissance)
char z_req[1024];
for(std::list<instant>::iterator it=lI.begin(); it!=lI.end(); it++)
{
snprintf(z_req,1024,"INSERT INTO rv_results (jid,rank,height,speed,dist,cum_elev,energy,time,geom) VALUES (%u,%u,%f,%f,%f,%f,%f,%f,'SRID=4326;POINT(%.8f %.8f)'::geometry);",
snprintf(z_req,1024,"INSERT INTO rv_results (jid,rank,height,speed,dist,cum_elev,energy,time,node_id,way_id,geom) VALUES (%u,%u,%f,%f,%f,%f,%f,%f,%u,%u,'SRID=4326;POINT(%.8f %.8f)'::geometry);",
jid,
rank++,
it->d_height,
......@@ -82,6 +82,8 @@ void database::write_results(std::list<instant> lI, double puissance)
it->d_deniv_pos,
it->d_ET,
it->d_ET/puissance,
it->ull_id,
it->ull_way_from_id,
it->d_lon,
it->d_lat);
txnw.exec(z_req);
......
......@@ -32,7 +32,9 @@ BEGIN;
dist FLOAT,
cum_elev FLOAT,
energy FLOAT,
time FLOAT
time FLOAT,
node_id BIGINT,
way_id BIGINT
);
......
......@@ -69,8 +69,6 @@ BEGIN
rv_ways
WHERE
cc IS NULL
AND
NOT isolated
LIMIT 1
) AS sub
WHERE rv_ways.id=sub.id;
......@@ -79,7 +77,7 @@ BEGIN
UPDATE rv_ways SET cc=n, ccprov=NULL WHERE cc IS NULL AND NOT ccprov IS NULL;
GET DIAGNOSTICS updated = ROW_COUNT;
PERFORM id FROM rv_ways WHERE cc IS NULL AND NOT isolated;
PERFORM id FROM rv_ways WHERE cc IS NULL;
GET DIAGNOSTICS count = ROW_COUNT;
RAISE INFO 'Connected component % with % ways, % ways left', n, updated, count;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment