예제 #1
0
    def handle(self):
        data = 'dummy'
        while data:
            data = self.request.recv(1024)
            #self.request.send(data)
            inizio = data.find(',A')+3
            fine = inizio+24
	    
            if data.find(',A') != -1: 
		print data[inizio:fine]
		data = data[inizio:fine]
		LatiG = data[0:2]
		print 'LatiG: ' + LatiG
		LatiM = data[2:9]
		print 'LatiM: ' + LatiM
		#LatiS = data[5:9]
		#LatiS = LatiS[:2] + "."+ LatiS[2:5]
		#print 'LatiS: ' + LatiS
		

		LongG = data[13:15]
		print 'LongG: ' + LongG
		LongM = data[15:22]
		print 'LongM: ' + LongM
		#LongS = data[18:22]
		#LongS = LongS[:2] + "."+ LongS[2:5]
		#print 'LongS: ' + LongS

		# Input coordinate in DMS format
		#coord = { "degrees": 121, "minutes": 8, "seconds": 6 }

		# Convert coordinate from DMS to DD
		Latitudine = dd.dms2decimal(LatiG, LatiM, 0)
		print Latitudine	
		Longitudine = dd.dms2decimal(LongG, LongM, 0)
		print Longitudine	
		conn = MySQLdb.connect(host="localhost",
		user="******",
		passwd="yourpasswordhere",
		db="tracker"
		)


		cursore = conn.cursor()

		cursore.execute('INSERT INTO positions (lat, lon) VALUES('+ str(Latitudine) +','+ str(Longitudine) +')')

	    if data.strip() == 'bye':
                return
# -*- coding: utf-8 -*-
"""
Example of PyDecimalDegrees usage.

Created by Mateusz Łoskot <*****@*****.**>
Altered by Evan Wheeler <*****@*****.**>

"""

import decimaldegrees as dd

# Input coordinate in DMS format
coord = { "degrees": 121, "minutes": 8, "seconds": 6 }

# Convert coordinate from DMS to DD
d = dd.dms2decimal(coord["degrees"], coord["minutes"], coord["seconds"])
print d

# Convert coordinate DD to DM
dm = dd.decimal2dm(d)
print dm

# Convert coordinate from DD to back to DMS
dms = dd.decimal2dms(d)
print dms

예제 #3
0
 def dms_to_dd(self, dms):
     d = dms[0].num  / dms[0].den
     m = dms[1].num  / dms[1].den
     s = dms[2].num  / dms[2].den
     return dms2decimal(d,m,s) * self.scale