source: subversion/applications/routing/pyroutelib2/routeAsCSV.py @ 34645

Last change on this file since 34645 was 8120, checked in by ojw, 11 years ago

CSV output (id,lat,lon on each line)

File size: 1.7 KB
Line 
1#!/usr/bin/python
2#----------------------------------------------------------------
3# routeAsCSV - routes with OSM data, and generates a
4# CSV file containing the result
5#
6#------------------------------------------------------
7#------------------------------------------------------
8# Copyright 2007-2008, Oliver White
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22#------------------------------------------------------
23from route import *
24
25def routeToCSV(lat1,lon1,lat2,lon2, transport):
26  """Format a route (as list of nodes)"""
27  data = LoadOsm(transport)
28
29  node1 = data.findNode(lat1,lon1)
30  node2 = data.findNode(lat2,lon2)
31
32  router = Router(data)
33  result, route = router.doRoute(node1, node2)
34  if result != 'success':
35    return("Fail")
36
37  output = ''
38  for i in route:
39    node = data.rnodes[i]
40    output = output + "%d,%f,%f\n" % ( \
41      i,
42      node[0],
43      node[1])
44  return(output)
45
46def routeToCSVFile(lat1,lon1,lat2,lon2, transport, filename):
47  f = open(filename,'w')
48  f.write(routeToCSV(lat1,lon1,lat2,lon2, transport))
49  f.close()
50
51
52if __name__ == "__main__":
53  print routeToCSV(
54    52.2181,
55    0.1162,
56    52.2184,
57    0.1427,
58    "cycle")
Note: See TracBrowser for help on using the repository browser.