Exemplo n.º 1
0
def convert_MGRS_to_UTM(point):
    lat_zone = ord(point.zone[2].upper())
    if lat_zone >= ord('N'):
        hemisphere = Hemisphere.NORTH
    else:
        hemisphere = Hemisphere.SOUTH

    zone_fields = ['STUVWXYZ', 'ABCDEFGH', 'JKLMNPQR']
    zone_fields_lat = 'ABCDEFGHJKLMNPQRSTUV'
    zone_temp = int(point.zone[0:2])
    square = point.square.upper()
    square_x = zone_fields[zone_temp % 3].index(square[0])
    square_y = zone_fields_lat.index(square[1])

    square_x += 1
    easting_temp = square_x * 100000

    if zone_temp % 2 == 0:
        square_y = (square_y - 5) % 20

    min_lat = __get_min_northing(chr(lat_zone))
    while square_y < min_lat:
        square_y += 20

    if square_y > min_lat + 15:
        square_y -= 20

    northing_temp = square_y * 100000

    result_easting = easting_temp + int(point.easting)
    result_northing = northing_temp + int(point.northing)

    return points.UTMPoint(result_easting, result_northing, zone_temp, '',
                           hemisphere)
Exemplo n.º 2
0
 def test_ghi(self):
     point = points.UTMPoint(123456, 1, 33, 'L', Hemisphere.NORTH)
     point = converter.utm_to_degree(point)
     print(point.to_string(CoordinateSystemString.WGS84_Degrees.value))
     long_deg, long_min, long_sec = converter.convert_degree_to_DMS(
         point.long_deg)
     lat_deg, lat_min, lat_sec = converter.convert_degree_to_DMS(
         point.lat_deg)
     print(str(long_deg))
     print(str(lat_deg))
Exemplo n.º 3
0
 def test_conversion_of_utm_5(self):
     utm_point = points.UTMPoint(500000, 2000000, 31, '', Hemisphere.NORTH)
     degree_point = converter.utm_to_degree(utm_point)
     self.assertEqual(str(degree_point.long_deg)[:9], '3')
     self.assertEqual(str(degree_point.lat_deg)[:9], '18.088708')
     long_deg, long_min, long_sec = converter.convert_degree_to_DMS(
         degree_point.long_deg)
     lat_deg, lat_min, lat_sec = converter.convert_degree_to_DMS(
         degree_point.lat_deg)
     dms_point = points.WGSPoint(long_deg, long_min, long_sec, lat_deg,
                                 lat_min, lat_sec)
     self.assertEqual(int(dms_point.long_deg), 3)
     self.assertEqual(int(dms_point.long_min), 0)
     self.assertEqual(str(dms_point.long_sec)[:5], '0.0')
     self.assertEqual(int(dms_point.lat_deg), 18)
     self.assertEqual(int(dms_point.lat_min), 5)
     self.assertEqual(str(dms_point.lat_sec)[:5], '19.35')
     mgrs_point = converter.convert_UTM_to_MGRS(utm_point)
     self.assertEqual(mgrs_point.zone, '31Q')
     self.assertEqual(mgrs_point.square, 'EA')
     self.assertEqual(mgrs_point.easting, 0)
     self.assertEqual(mgrs_point.northing, 0)
Exemplo n.º 4
0
 def test_conversion_of_utm_4(self):
     utm_point = points.UTMPoint(654321, 7654321, 45, '', Hemisphere.SOUTH)
     degree_point = converter.utm_to_degree(utm_point)
     self.assertEqual(str(degree_point.long_deg)[:9], '88.486799')
     self.assertEqual(str(degree_point.lat_deg)[:9], '-21.20607')
     long_deg, long_min, long_sec = converter.convert_degree_to_DMS(
         degree_point.long_deg)
     lat_deg, lat_min, lat_sec = converter.convert_degree_to_DMS(
         degree_point.lat_deg)
     dms_point = points.WGSPoint(long_deg, long_min, long_sec, lat_deg,
                                 lat_min, lat_sec)
     self.assertEqual(int(dms_point.long_deg), 88)
     self.assertEqual(int(dms_point.long_min), 29)
     self.assertEqual(str(dms_point.long_sec)[:5], '12.47')
     self.assertEqual(int(dms_point.lat_deg), -21)
     self.assertEqual(int(dms_point.lat_min), 12)
     self.assertEqual(str(dms_point.lat_sec)[:5], '21.86')
     mgrs_point = converter.convert_UTM_to_MGRS(utm_point)
     self.assertEqual(mgrs_point.zone, '45K')
     self.assertEqual(mgrs_point.square, 'XS')
     self.assertEqual(mgrs_point.easting, 54321)
     self.assertEqual(mgrs_point.northing, 54321)
Exemplo n.º 5
0
 def test_conversion_of_utm_3(self):
     utm_point = points.UTMPoint(654321, 7654321, 45, '', Hemisphere.NORTH)
     degree_point = converter.utm_to_degree(utm_point)
     self.assertEqual(str(degree_point.long_deg)[:9], '90.853072')
     self.assertEqual(str(degree_point.lat_deg)[:9], '68.956178')
     long_deg, long_min, long_sec = converter.convert_degree_to_DMS(
         degree_point.long_deg)
     lat_deg, lat_min, lat_sec = converter.convert_degree_to_DMS(
         degree_point.lat_deg)
     dms_point = points.WGSPoint(long_deg, long_min, long_sec, lat_deg,
                                 lat_min, lat_sec)
     self.assertEqual(int(dms_point.long_deg), 90)
     self.assertEqual(int(dms_point.long_min), 51)
     self.assertEqual(str(dms_point.long_sec)[:5], '11.06')
     self.assertEqual(int(dms_point.lat_deg), 68)
     self.assertEqual(int(dms_point.lat_min), 57)
     self.assertEqual(str(dms_point.lat_sec)[:5], '22.24')
     mgrs_point = converter.convert_UTM_to_MGRS(utm_point)
     self.assertEqual(mgrs_point.zone, '45W')
     self.assertEqual(mgrs_point.square, 'XS')
     self.assertEqual(mgrs_point.easting, 54321)
     self.assertEqual(mgrs_point.northing, 54321)
Exemplo n.º 6
0
 def test_conversion_of_utm_2(self):
     utm_point = points.UTMPoint(123456, 1234567, 5, '', Hemisphere.SOUTH)
     degree_point = converter.utm_to_degree(utm_point)
     self.assertEqual(str(degree_point.long_deg)[:9], '-170.0987')
     self.assertEqual(str(degree_point.lat_deg)[:9], '-78.46254')
     long_deg, long_min, long_sec = converter.convert_degree_to_DMS(
         degree_point.long_deg)
     lat_deg, lat_min, lat_sec = converter.convert_degree_to_DMS(
         degree_point.lat_deg)
     dms_point = points.WGSPoint(long_deg, long_min, long_sec, lat_deg,
                                 lat_min, lat_sec)
     self.assertEqual(int(dms_point.long_deg), -170)
     self.assertEqual(int(dms_point.long_min), 5)
     self.assertEqual(str(dms_point.long_sec)[:5], '55.62')  #TODO: check
     self.assertEqual(int(dms_point.lat_deg), -78)
     self.assertEqual(int(dms_point.lat_min), 27)
     self.assertEqual(str(dms_point.lat_sec)[:5], '45.17')
     mgrs_point = converter.convert_UTM_to_MGRS(utm_point)
     self.assertEqual(mgrs_point.zone, '5C')
     self.assertEqual(mgrs_point.square, 'JO')  #TODO: check
     self.assertEqual(mgrs_point.easting, 23456)
     self.assertEqual(mgrs_point.northing, 34567)
Exemplo n.º 7
0
 def test_conversion_of_utm_1(self):
     utm_point = points.UTMPoint(123456, 1234567, 5, '', Hemisphere.NORTH)
     degree_point = converter.utm_to_degree(utm_point)
     self.assertEqual(str(degree_point.long_deg)[:9], '-156.4466')
     self.assertEqual(str(degree_point.lat_deg)[:8], '11.14828')
     long_deg, long_min, long_sec = converter.convert_degree_to_DMS(
         degree_point.long_deg)
     lat_deg, lat_min, lat_sec = converter.convert_degree_to_DMS(
         degree_point.lat_deg)
     dms_point = points.WGSPoint(long_deg, long_min, long_sec, lat_deg,
                                 lat_min, lat_sec)
     self.assertEqual(int(dms_point.long_deg), -156)
     self.assertEqual(int(dms_point.long_min), 26)
     self.assertEqual(str(dms_point.long_sec)[:5], '47.86')  #TODO: check
     self.assertEqual(int(dms_point.lat_deg), 11)
     self.assertEqual(int(dms_point.lat_min), 8)
     self.assertEqual(str(dms_point.lat_sec)[:5], '53.81')
     mgrs_point = converter.convert_UTM_to_MGRS(utm_point)
     self.assertEqual(mgrs_point.zone, '5P')
     self.assertEqual(mgrs_point.square, 'JO')  #TODO: check
     self.assertEqual(mgrs_point.easting, 23456)
     self.assertEqual(mgrs_point.northing, 34567)
Exemplo n.º 8
0
def degree_to_utm(point):
    """Algorithm for the conversion of coordinate from the geographic coordinate system to UTM.

    Authors
    -------
    * Bart van Andel <*****@*****.**>
    * Tobias Bieniek <*****@*****.**>
    * Torstein I. Bo
    """
    longitude = point.long_deg
    latitude = point.lat_deg
    force_zone_number = None

    # if not -80.0 <= latitude <= 84.0:
    #     raise exceptions.ParseException('latitude out of range (must be between 80 deg S and 84 deg N)')
    # if not -180.0 <= longitude <= 180.0:
    #     raise exceptions.ParseException('longitude out of range (must be between 180 deg W and 180 deg E)')

    lat_rad = math.radians(latitude)
    lat_sin = math.sin(lat_rad)
    lat_cos = math.cos(lat_rad)

    lat_tan = lat_sin / lat_cos
    lat_tan2 = lat_tan * lat_tan
    lat_tan4 = lat_tan2 * lat_tan2

    if force_zone_number is None:
        zone_number = latlon_to_zone_number(latitude, longitude)
    else:
        zone_number = force_zone_number

    zone_letter = latitude_to_zone_letter(latitude)

    lon_rad = math.radians(longitude)
    central_lon = zone_number_to_central_longitude(zone_number)
    central_lon_rad = math.radians(central_lon)

    n = R / math.sqrt(1 - E * lat_sin**2)
    c = E_P2 * lat_cos**2

    a = lat_cos * (lon_rad - central_lon_rad)
    a2 = a * a
    a3 = a2 * a
    a4 = a3 * a
    a5 = a4 * a
    a6 = a5 * a

    m = R * (M1 * lat_rad - M2 * math.sin(2 * lat_rad) +
             M3 * math.sin(4 * lat_rad) - M4 * math.sin(6 * lat_rad))

    easting = K0 * n * (
        a + a3 / 6 * (1 - lat_tan2 + c) + a5 / 120 *
        (5 - 18 * lat_tan2 + lat_tan4 + 72 * c - 58 * E_P2)) + 500000

    northing = K0 * (m + n * lat_tan *
                     (a2 / 2 + a4 / 24 *
                      (5 - lat_tan2 + 9 * c + 4 * c**2) + a6 / 720 *
                      (61 - 58 * lat_tan2 + lat_tan4 + 600 * c - 330 * E_P2)))

    if latitude < 0:
        northing += 10000000

    if latitude >= 0:
        hemisphere = Hemisphere.NORTH
    else:
        hemisphere = Hemisphere.SOUTH
    point = points.UTMPoint(easting, northing, zone_number, zone_letter,
                            hemisphere)
    return point
Exemplo n.º 9
0
 def test_utm_to_degree(self):
     point = points.UTMPoint(456331, 1562000, 33, None, Hemisphere.NORTH)
     p_1 = converter.utm_to_degree(point)
     self.assertEqual(format(p_1.lat_deg, '.4f'), '14.1287')
     self.assertEqual(format(p_1.long_deg, '.4f'), '14.5954')