Beispiel #1
0
 def test_MGRS_to_UTM(self):
     point = points.MGRSPoint(12345, 12345, '33U', 'VP')
     p_1 = converter.convert_MGRS_to_UTM(point)
     self.assertEqual(p_1.zone_number, 33)
     self.assertEqual(p_1.hemisphere, Hemisphere.NORTH)
     self.assertEqual(p_1.easting, 412345)
     self.assertEqual(p_1.northing, 5312345)
Beispiel #2
0
    def __degree_to_mgrs(self, point):
        m = mgrs.MGRS()
        c = m.toMGRS(point.lat_deg, point.long_deg)
        zone = c[:3]
        square = c[3:5]
        easting = c[5:10]
        northing = c[10:]

        point = points.MGRSPoint(easting, northing, zone, square)
        return point
def convert_UTM_to_MGRS(point):
    degree_point = utm_to_degree(point)
    ltr2_low_value, ltr2_high_value, false_northing = __get_grid_values(
        point.zone_number)
    letter = __get_latitude_letter(float(degree_point.lat_deg))

    grid_northing = int(point.northing)
    if grid_northing == 1.E7:
        grid_northing -= 1.0

    while grid_northing >= 2000000.0:
        grid_northing -= 2000000.0

    grid_northing -= false_northing

    if grid_northing < 0.0:
        grid_northing += 2000000

    square_y = grid_northing / 100000.0

    if square_y > LETTER_VALUES['H']:
        square_y += 1

    if square_y > LETTER_VALUES['N']:
        square_y += 1

    grid_easting = int(point.easting)

    if letter == 'V' and point.zone == 31 and grid_easting == 500000.0:
        grid_easting -= 1.0

    square_x = ltr2_low_value + (grid_easting / 100000) - 1
    if ltr2_low_value == LETTER_VALUES['J'] and square_x > LETTER_VALUES['N']:
        square_x += 1

    zone = str(point.zone_number) + letter
    square = str(LETTER_VALUES.keys()[LETTER_VALUES.values().index(int(square_x))]) + \
             str(LETTER_VALUES.keys()[LETTER_VALUES.values().index(int(square_y))])
    easting = math.fmod(float(point.easting), 100000.0)
    northing = math.fmod(float(point.northing), 100000.0)
    return points.MGRSPoint(int(easting), int(northing), zone, square)
Beispiel #4
0
 def test_conversion_of_mgrs_5(self):
     mgrs_point = points.MGRSPoint(28166, 47695, '05Q', 'KB')
     utm_point = converter.convert_MGRS_to_UTM(mgrs_point)
     self.assertEqual(utm_point.zone_number, 5)
     self.assertEqual(int(utm_point.easting), 228166)
     self.assertEqual(int(utm_point.northing), 2147695)
     self.assertEqual(utm_point.hemisphere, Hemisphere.NORTH)
     degree_point = converter.utm_to_degree(utm_point)
     self.assertEqual(str(degree_point.long_deg)[:8], '-155.588')
     self.assertEqual(str(degree_point.lat_deg)[:8], '19.40511')
     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), -155)
     self.assertEqual(int(dms_point.long_min), 35)
     self.assertEqual(str(dms_point.long_sec)[:5], '18.20')
     self.assertEqual(int(dms_point.lat_deg), 19)
     self.assertEqual(int(dms_point.lat_min), 24)
     self.assertEqual(str(dms_point.lat_sec)[:5], '18.42')
Beispiel #5
0
 def test_conversion_of_mgrs_4(self):
     mgrs_point = points.MGRSPoint(80363, 76750, '14S', 'MJ')
     utm_point = converter.convert_MGRS_to_UTM(mgrs_point)
     self.assertEqual(utm_point.zone_number, 14)
     self.assertEqual(int(utm_point.easting), 480363)
     self.assertEqual(int(utm_point.northing), 4376750)
     self.assertEqual(utm_point.hemisphere, Hemisphere.NORTH)
     degree_point = converter.utm_to_degree(utm_point)
     self.assertEqual(str(degree_point.long_deg)[:8], '-99.2285')
     self.assertEqual(str(degree_point.lat_deg)[:8], '39.54019')
     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), -99)
     self.assertEqual(int(dms_point.long_min), 13)
     self.assertEqual(str(dms_point.long_sec)[:5], '42.68')
     self.assertEqual(int(dms_point.lat_deg), 39)
     self.assertEqual(int(dms_point.lat_min), 32)
     self.assertEqual(str(dms_point.lat_sec)[:5], '24.69')
Beispiel #6
0
 def test_conversion_of_mgrs_3(self):
     mgrs_point = points.MGRSPoint(78917, 92398, '20J', 'NM')
     utm_point = converter.convert_MGRS_to_UTM(mgrs_point)
     self.assertEqual(utm_point.zone_number, 20)
     self.assertEqual(int(utm_point.easting), 578917)
     self.assertEqual(int(utm_point.northing), 6692398)
     self.assertEqual(utm_point.hemisphere, Hemisphere.SOUTH)
     degree_point = converter.utm_to_degree(utm_point)
     self.assertEqual(str(degree_point.long_deg)[:8], '-62.1826')
     self.assertEqual(str(degree_point.lat_deg)[:8], '-29.8965')
     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), -62)
     self.assertEqual(int(dms_point.long_min), 10)
     self.assertEqual(str(dms_point.long_sec)[:5], '57.44')
     self.assertEqual(int(dms_point.lat_deg), -29)
     self.assertEqual(int(dms_point.lat_min), 53)
     self.assertEqual(str(dms_point.lat_sec)[:5], '47.54')
Beispiel #7
0
 def test_conversion_of_mgrs_2(self):
     mgrs_point = points.MGRSPoint(16794, 10831, '37L', 'BM')
     utm_point = converter.convert_MGRS_to_UTM(mgrs_point)
     self.assertEqual(utm_point.zone_number, 37)
     self.assertEqual(int(utm_point.easting), 216794)
     self.assertEqual(int(utm_point.northing), 9110831)
     self.assertEqual(utm_point.hemisphere, Hemisphere.SOUTH)
     degree_point = converter.utm_to_degree(utm_point)
     self.assertEqual(str(degree_point.long_deg)[:8], '36.43065')
     self.assertEqual(str(degree_point.lat_deg)[:8], '-8.03602')
     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), 36)
     self.assertEqual(int(dms_point.long_min), 25)
     self.assertEqual(str(dms_point.long_sec)[:5], '50.36')
     self.assertEqual(int(dms_point.lat_deg), -8)
     self.assertEqual(int(dms_point.lat_min), 2)
     self.assertEqual(str(dms_point.lat_sec)[:5], '9.702')
Beispiel #8
0
 def test_conversion_of_mgrs_1(self):
     mgrs_point = points.MGRSPoint(55500, 72800, '33U', 'VP')
     utm_point = converter.convert_MGRS_to_UTM(mgrs_point)
     self.assertEqual(utm_point.zone_number, 33)
     self.assertEqual(int(utm_point.easting), 455500)
     self.assertEqual(int(utm_point.northing), 5372800)
     self.assertEqual(utm_point.hemisphere, Hemisphere.NORTH)
     degree_point = converter.utm_to_degree(utm_point)
     self.assertEqual(str(degree_point.long_deg)[:8], '14.39752')
     self.assertEqual(str(degree_point.lat_deg)[:8], '48.50673')
     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), 14)
     self.assertEqual(int(dms_point.long_min), 23)
     self.assertEqual(str(dms_point.long_sec)[:5], '51.08')
     self.assertEqual(int(dms_point.lat_deg), 48)
     self.assertEqual(int(dms_point.lat_min), 30)
     self.assertEqual(str(dms_point.lat_sec)[:5], '24.26')