Here I am going to use approach similar to those described in post. In other words I will treat x, y coordinates and information about axes orientation as point with offset against reference point - origin of the local coordinates in this case.
LocalCartesianPoint is a class that will calculate latitude and longitude point
Constructor of LocalCartesianPoint class:
class LocalCartesianPoint: def __init__(self, origin_point: BasePoint, x_axis_brng: Bearing, y_axis_brng: Bearing, x: Distance, y: Distance): self.origin_point = origin_point self.x_axis_brng = x_axis_brng self.y_axis_brng = y_axis_brng self.x = x self.y = y self._calc_dd_lat = None self._calc_dd_lon = None
Method that calculates 'reverse' bearings of axes - for negative x, y coordinates:
@staticmethod def calc_reverse_axis_brng(axis_brng): reverse_axis_brng = axis_brng - 180 if reverse_axis_brng < 0: reverse_axis_brng += 360 elif reverse_axis_brng > 360: reverse_axis_brng -= 360 return reverse_axis_brng
Methods that calculates latitude and longitude:
def calc_latlon(self): self.x_axis_brng.calc_tbrng(self.origin_point.mag_var.dd_value) self.y_axis_brng.calc_tbrng(self.origin_point.mag_var.dd_value) reverse_x_axis_brng = self.calc_reverse_axis_brng(self.x_axis_brng.dd_tbrng) reverse_y_axis_brng = self.calc_reverse_axis_brng(self.y_axis_brng.dd_tbrng) x_m = self.x.get_meters() y_m = self.y.get_meters() if x_m >= 0: # Normal x axis azimuth if y_m >= 0: # Normal y axis azimuth self._calc_dd_lat, self._calc_dd_lon = dist_azm_orth_offset2latlon2(self.origin_point.dd_lat, self.origin_point.dd_lon, self.x_axis_brng.dd_tbrng, self.y_axis_brng.dd_tbrng, x_m, y_m) elif y_m < 0: self._calc_dd_lat, self._calc_dd_lon = dist_azm_orth_offset2latlon2(self.origin_point.dd_lat, self.origin_point.dd_lon, self.x_axis_brng.dd_tbrng, reverse_y_axis_brng, x_m, math.fabs(y_m)) elif x_m < 0: if y_m >= 0: # Normal y axis azimuth self._calc_dd_lat, self._calc_dd_lon = dist_azm_orth_offset2latlon2(self.origin_point.dd_lat, self.origin_point.dd_lon, reverse_x_axis_brng, self.y_axis_brng.dd_tbrng, math.fabs(x_m), y_m) elif y_m < 0: self._calc_dd_lat, self._calc_dd_lon = dist_azm_orth_offset2latlon2(self.origin_point.dd_lat, self.origin_point.dd_lon, reverse_x_axis_brng, reverse_y_axis_brng, math.fabs(x_m), math.fabs(y_m))
No comments:
Post a Comment