Refacoring
This commit is contained in:
44
gsc.py
44
gsc.py
@@ -13,55 +13,47 @@ class GPSConverter(object):
|
|||||||
'''
|
'''
|
||||||
# Convert CH y/x/h to WGS height
|
# Convert CH y/x/h to WGS height
|
||||||
def CHtoWGSheight(self, y, x, h):
|
def CHtoWGSheight(self, y, x, h):
|
||||||
# Converts militar to civil and to unit = 1000km
|
|
||||||
# Axiliary values (% Bern)
|
# Axiliary values (% Bern)
|
||||||
y_aux = (y - 600000) / 1000000
|
y_aux = (y - 600000) / 1000000
|
||||||
x_aux = (x - 200000) / 1000000
|
x_aux = (x - 200000) / 1000000
|
||||||
# Process height
|
|
||||||
h = (h + 49.55) - (12.60 * y_aux) - (22.64 * x_aux)
|
h = (h + 49.55) - (12.60 * y_aux) - (22.64 * x_aux)
|
||||||
return h
|
return h
|
||||||
|
|
||||||
# Convert CH y/x to WGS lat
|
# Convert CH y/x to WGS lat
|
||||||
def CHtoWGSlat(self, y, x):
|
def CHtoWGSlat(self, y, x):
|
||||||
# Converts militar to civil and to unit = 1000km
|
|
||||||
# Axiliary values (% Bern)
|
# Axiliary values (% Bern)
|
||||||
y_aux = (y - 600000) / 1000000
|
y_aux = (y - 600000) / 1000000
|
||||||
x_aux = (x - 200000) / 1000000
|
x_aux = (x - 200000) / 1000000
|
||||||
# Process lat
|
|
||||||
lat = (16.9023892 + (3.238272 * x_aux)) + \
|
lat = (16.9023892 + (3.238272 * x_aux)) + \
|
||||||
- (0.270978 * pow(y_aux, 2)) + \
|
- (0.270978 * pow(y_aux, 2)) + \
|
||||||
- (0.002528 * pow(x_aux, 2)) + \
|
- (0.002528 * pow(x_aux, 2)) + \
|
||||||
- (0.0447 * pow(y_aux, 2) * x_aux) + \
|
- (0.0447 * pow(y_aux, 2) * x_aux) + \
|
||||||
- (0.0140 * pow(x_aux, 3))
|
- (0.0140 * pow(x_aux, 3))
|
||||||
# Unit 10000" to 1 " and converts seconds to degrees (dec)
|
# Unit 10000" to 1" and convert seconds to degrees (dec)
|
||||||
lat = (lat * 100) / 36
|
lat = (lat * 100) / 36
|
||||||
return lat
|
return lat
|
||||||
|
|
||||||
# Convert CH y/x to WGS long
|
# Convert CH y/x to WGS long
|
||||||
def CHtoWGSlng(self, y, x):
|
def CHtoWGSlng(self, y, x):
|
||||||
# Converts militar to civil and to unit = 1000km
|
|
||||||
# Axiliary values (% Bern)
|
# Axiliary values (% Bern)
|
||||||
y_aux = (y - 600000) / 1000000
|
y_aux = (y - 600000) / 1000000
|
||||||
x_aux = (x - 200000) / 1000000
|
x_aux = (x - 200000) / 1000000
|
||||||
# Process long
|
|
||||||
lng = (2.6779094 + (4.728982 * y_aux) + \
|
lng = (2.6779094 + (4.728982 * y_aux) + \
|
||||||
+ (0.791484 * y_aux * x_aux) + \
|
+ (0.791484 * y_aux * x_aux) + \
|
||||||
+ (0.1306 * y_aux * pow(x_aux, 2))) + \
|
+ (0.1306 * y_aux * pow(x_aux, 2))) + \
|
||||||
- (0.0436 * pow(y_aux, 3))
|
- (0.0436 * pow(y_aux, 3))
|
||||||
# Unit 10000" to 1 " and converts seconds to degrees (dec)
|
# Unit 10000" to 1" and convert seconds to degrees (dec)
|
||||||
lng = (lng * 100) / 36
|
lng = (lng * 100) / 36
|
||||||
return lng
|
return lng
|
||||||
|
|
||||||
# Convert decimal angle (degrees) to sexagesimal angle (degrees, minutes
|
# Convert decimal angle (° dec) to sexagesimal angle (dd.mmss,ss)
|
||||||
# and seconds dd.mmss,ss)
|
|
||||||
def DecToSexAngle(self, dec):
|
def DecToSexAngle(self, dec):
|
||||||
degree = int(math.floor(dec))
|
degree = int(math.floor(dec))
|
||||||
minute = int(math.floor((dec - degree) * 60))
|
minute = int(math.floor((dec - degree) * 60))
|
||||||
second = (((dec - degree) * 60) - minute) * 60
|
second = (((dec - degree) * 60) - minute) * 60
|
||||||
# Output: dd.mmss(,)ss
|
|
||||||
return degree + (float(minute) / 100) + (second / 10000)
|
return degree + (float(minute) / 100) + (second / 10000)
|
||||||
|
|
||||||
# Convert sexagesimal angle (degrees, minutes and seconds dd.mmss,ss) to seconds
|
# Convert sexagesimal angle (dd.mmss,ss) to seconds
|
||||||
def SexAngleToSeconds(self, dms):
|
def SexAngleToSeconds(self, dms):
|
||||||
degree = 0
|
degree = 0
|
||||||
minute = 0
|
minute = 0
|
||||||
@@ -69,49 +61,39 @@ class GPSConverter(object):
|
|||||||
degree = math.floor(dms)
|
degree = math.floor(dms)
|
||||||
minute = math.floor((dms - degree) * 100)
|
minute = math.floor((dms - degree) * 100)
|
||||||
second = (((dms - degree) * 100) - minute) * 100
|
second = (((dms - degree) * 100) - minute) * 100
|
||||||
# Result in degrees sex (dd.mmss)
|
|
||||||
return second + (minute * 60) + (degree * 3600)
|
return second + (minute * 60) + (degree * 3600)
|
||||||
|
|
||||||
# Convert sexagesimal angle (degrees, minutes and seconds "dd.mmss") to decimal angle (degrees)
|
# Convert sexagesimal angle (dd.mmss) to decimal angle (degrees)
|
||||||
def SexToDecAngle(self, dms):
|
def SexToDecAngle(self, dms):
|
||||||
# Extract DMS
|
|
||||||
# Input: dd.mmss(,)ss
|
|
||||||
degree = 0
|
degree = 0
|
||||||
minute = 0
|
minute = 0
|
||||||
second = 0
|
second = 0
|
||||||
degree = math.floor(dms)
|
degree = math.floor(dms)
|
||||||
minute = math.floor((dms - degree) * 100)
|
minute = math.floor((dms - degree) * 100)
|
||||||
second = (((dms - degree) * 100) - minute) * 100
|
second = (((dms - degree) * 100) - minute) * 100
|
||||||
# Result in degrees dec (dd.dddd)
|
|
||||||
return degree + (minute / 60) + (second / 3600)
|
return degree + (minute / 60) + (second / 3600)
|
||||||
|
|
||||||
# Convert WGS lat/long (° dec) and height to CH h
|
# Convert WGS lat/long (° dec) and height to CH h
|
||||||
def WGStoCHh(self, lat, lng, h):
|
def WGStoCHh(self, lat, lng, h):
|
||||||
# Converts degrees dec to sex
|
|
||||||
lat = self.DecToSexAngle(lat)
|
lat = self.DecToSexAngle(lat)
|
||||||
lng = self.DecToSexAngle(lng)
|
lng = self.DecToSexAngle(lng)
|
||||||
# Converts degrees to seconds (sex)
|
|
||||||
lat = self.SexAngleToSeconds(lat)
|
lat = self.SexAngleToSeconds(lat)
|
||||||
lng = self.SexAngleToSeconds(lng)
|
lng = self.SexAngleToSeconds(lng)
|
||||||
# Axiliary values (% Bern)
|
# Axiliary values (% Bern)
|
||||||
lat_aux = (lat - 169028.66) / 10000
|
lat_aux = (lat - 169028.66) / 10000
|
||||||
lng_aux = (lng - 26782.5) / 10000
|
lng_aux = (lng - 26782.5) / 10000
|
||||||
# Process h
|
|
||||||
h = (h - 49.55) + (2.73 * lng_aux) + (6.94 * lat_aux)
|
h = (h - 49.55) + (2.73 * lng_aux) + (6.94 * lat_aux)
|
||||||
return h
|
return h
|
||||||
|
|
||||||
# Convert WGS lat/long (° dec) to CH x
|
# Convert WGS lat/long (° dec) to CH x
|
||||||
def WGStoCHx(self, lat, lng):
|
def WGStoCHx(self, lat, lng):
|
||||||
# Converts degrees dec to sex
|
|
||||||
lat = self.DecToSexAngle(lat)
|
lat = self.DecToSexAngle(lat)
|
||||||
lng = self.DecToSexAngle(lng)
|
lng = self.DecToSexAngle(lng)
|
||||||
# Converts degrees to seconds (sex)
|
|
||||||
lat = self.SexAngleToSeconds(lat)
|
lat = self.SexAngleToSeconds(lat)
|
||||||
lng = self.SexAngleToSeconds(lng)
|
lng = self.SexAngleToSeconds(lng)
|
||||||
# Axiliary values (% Bern)
|
# Axiliary values (% Bern)
|
||||||
lat_aux = (lat - 169028.66) / 10000
|
lat_aux = (lat - 169028.66) / 10000
|
||||||
lng_aux = (lng - 26782.5) / 10000
|
lng_aux = (lng - 26782.5) / 10000
|
||||||
# Process X
|
|
||||||
x = ((200147.07 + (308807.95 * lat_aux) + \
|
x = ((200147.07 + (308807.95 * lat_aux) + \
|
||||||
+ (3745.25 * pow(lng_aux, 2)) + \
|
+ (3745.25 * pow(lng_aux, 2)) + \
|
||||||
+ (76.63 * pow(lat_aux,2))) + \
|
+ (76.63 * pow(lat_aux,2))) + \
|
||||||
@@ -121,16 +103,13 @@ class GPSConverter(object):
|
|||||||
|
|
||||||
# Convert WGS lat/long (° dec) to CH y
|
# Convert WGS lat/long (° dec) to CH y
|
||||||
def WGStoCHy(self, lat, lng):
|
def WGStoCHy(self, lat, lng):
|
||||||
# Converts degrees dec to sex
|
|
||||||
lat = self.DecToSexAngle(lat)
|
lat = self.DecToSexAngle(lat)
|
||||||
lng = self.DecToSexAngle(lng)
|
lng = self.DecToSexAngle(lng)
|
||||||
# Converts degrees to seconds (sex)
|
|
||||||
lat = self.SexAngleToSeconds(lat)
|
lat = self.SexAngleToSeconds(lat)
|
||||||
lng = self.SexAngleToSeconds(lng)
|
lng = self.SexAngleToSeconds(lng)
|
||||||
# Axiliary values (% Bern)
|
# Axiliary values (% Bern)
|
||||||
lat_aux = (lat - 169028.66) / 10000
|
lat_aux = (lat - 169028.66) / 10000
|
||||||
lng_aux = (lng - 26782.5) / 10000
|
lng_aux = (lng - 26782.5) / 10000
|
||||||
# Process Y
|
|
||||||
y = (600072.37 + (211455.93 * lng_aux)) + \
|
y = (600072.37 + (211455.93 * lng_aux)) + \
|
||||||
- (10938.51 * lng_aux * lat_aux) + \
|
- (10938.51 * lng_aux * lat_aux) + \
|
||||||
- (0.36 * lng_aux * pow(lat_aux, 2)) + \
|
- (0.36 * lng_aux * pow(lat_aux, 2)) + \
|
||||||
@@ -160,12 +139,15 @@ class GPSConverter(object):
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
class GPRMC(object):
|
class GPRMC(object):
|
||||||
''' Data object to store the nmea string.
|
''' Object to store the nmea strings data.
|
||||||
|
|
||||||
|
Explenation of the GPRMC NMEA data string:
|
||||||
|
|
||||||
Explenation of the GPRMC NMEA Data string:
|
$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W,*70
|
||||||
$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70
|
0 1 2 3 4 5 6 7 8 9 10 11 12
|
||||||
1 2 3 4 5 6 7 8 9 10 11 12
|
|
||||||
1 220516 Time Stamp
|
0 $GPRMC Name
|
||||||
|
1 220516 Time Stamp
|
||||||
2 A validity - A-ok, V-invalid
|
2 A validity - A-ok, V-invalid
|
||||||
3 5133.82 current Latitude
|
3 5133.82 current Latitude
|
||||||
4 N North/South
|
4 N North/South
|
||||||
|
|||||||
Reference in New Issue
Block a user