source: subversion/applications/routing/pyroute/geoPosition.py @ 5498

Last change on this file since 5498 was 5498, checked in by ojw, 12 years ago

reading geonames (gets XML from a file at the moment, instead of
downloading it)

File size: 1.5 KB
Line 
1#!/usr/bin/python
2#----------------------------------------------------------------
3# report "current position" (currently accepts replayed GPX
4# files from follow.py)
5#------------------------------------------------------
6# Usage:
7#   pos = geoPosition(filename_of_latlong_file)
8#   lat,lon = pos.get()
9#------------------------------------------------------
10# Copyright 2007, Oliver White
11#
12# This program is free software: you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation, either version 3 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program.  If not, see <http://www.gnu.org/licenses/>.
24#------------------------------------------------------
25import sys
26from time import sleep
27
28class geoPosition:
29  def __init__(self, filename):
30    self.filename = filename
31  def get(self):
32   
33    file = open(self.filename, 'r')
34    text = file.readline(50)
35    file.close()
36    try:
37      lat,lon = [float(i) for i in text.rstrip().split(",")]
38      return(lat,lon)
39    except ValueError:
40      return(0,0)
41   
42if __name__ == "__main__":
43  pos = geoPosition(sys.argv[1])
44  print pos.get()
Note: See TracBrowser for help on using the repository browser.