def notation(self, notation): if type(self.lat) == float: # Decimal Degrees (float) # Use functions to convert from Decimal Degrees (float) if notation == float: pass elif notation == DECAngle: new_lat = DECAngle(self.lat) new_lon = DECAngle(self.lon) elif notation == HPAngle: new_lat = dec2hpa(self.lat) new_lon = dec2hpa(self.lon) elif notation == GONAngle: new_lat = dec2gona(self.lat) new_lon = dec2gona(self.lon) elif notation == DMSAngle: new_lat = dec2dms(self.lat) new_lon = dec2dms(self.lon) elif notation == DDMAngle: new_lat = dec2ddm(self.lat) new_lon = dec2ddm(self.lon) else: raise ValueError( f'CoordGeo.notation() notation requires class float or ' f'class from geodepy.angles module. ' f'Supplied: {notation}') elif type( self.lat) in [DECAngle, HPAngle, GONAngle, DMSAngle, DDMAngle]: # Use methods to convert from geodepy.angles classes if notation == float: new_lat = self.lat.dec() new_lon = self.lon.dec() elif notation == DECAngle: new_lat = self.lat.deca() new_lon = self.lon.deca() elif notation == HPAngle: new_lat = self.lat.hpa() new_lon = self.lon.hpa() elif notation == GONAngle: new_lat = self.lat.gona() new_lon = self.lon.gona() elif notation == DMSAngle: new_lat = self.lat.dms() new_lon = self.lon.dms() elif notation == DDMAngle: new_lat = self.lat.ddm() new_lon = self.lon.ddm() else: raise ValueError( f'CoordGeo.notation() notation requires class float or ' f'class from geodepy.angles module. ' f'Supplied: {notation}') return CoordGeo(new_lat, new_lon, self.ell_ht, self.orth_ht)
def geo(self, ellipsoid=grs80, notation=DECAngle): """ Convert coordinates to Geographic Note: If no N Value, no Orthometric Height set. :param ellipsoid: geodepy.constants.Ellipsoid Object (default: grs80) :param notation: Latitude and Longitude Angle Notation format :type notation: geodepy.angle class or float :return: Geographic Coordinate :rtype: CoordGeo """ lat, lon, ell_ht = xyz2llh(self.xaxis, self.yaxis, self.zaxis, ellipsoid) if notation is DECAngle: lat = DECAngle(lat) lon = DECAngle(lon) elif notation is HPAngle: lat = DECAngle(lat).hpa() lon = DECAngle(lon).hpa() elif notation is GONAngle: lat = DECAngle(lat).gona() lon = DECAngle(lon).gona() elif notation is DMSAngle: lat = DECAngle(lat).dms() lon = DECAngle(lon).dms() elif notation is DDMAngle: lat = DECAngle(lat).ddm() lon = DECAngle(lon).ddm() elif notation is float: pass # geodepy.convert.grid2geo returns float dec degrees else: raise ValueError( f'CoordCart.geo() notation requires class float or' f' class from geodepy.angles module. ' f'Supplied: {notation}') if self.nval is None: return CoordGeo(lat, lon, ell_ht) else: return CoordGeo(lat, lon, ell_ht, ell_ht - self.nval)
def geo(self, ellipsoid=grs80, notation=DECAngle): """ :param ellipsoid: geodepy.constants.Ellipsoid Object (default: grs80) :param notation: Latitude and Longitude Angle Notation format :type notation: geodepy.angle class or float :return: """ if self.hemi_north: hemi_str = 'north' else: hemi_str = 'south' lat, lon, psf, grid_conv = grid2geo(self.zone, self.east, self.north, hemi_str, ellipsoid) if notation is DECAngle: lat = DECAngle(lat) lon = DECAngle(lon) elif notation is HPAngle: lat = DECAngle(lat).hpa() lon = DECAngle(lon).hpa() elif notation is GONAngle: lat = DECAngle(lat).gona() lon = DECAngle(lon).gona() elif notation is DMSAngle: lat = DECAngle(lat).dms() lon = DECAngle(lon).dms() elif notation is DDMAngle: lat = DECAngle(lat).ddm() lon = DECAngle(lon).ddm() elif notation is float: pass # geodepy.convert.grid2geo returns float dec degrees else: raise ValueError(f'CoordTM.geo() notation requires class float or ' f'class from geodepy.angles module. ' f'Supplied: {notation}') return CoordGeo(lat, lon, self.ell_ht, self.orth_ht)
def test_DECAngle(self): # Test DECAngle Methods for num, ex in enumerate(deca_exs): self.assertEqual(ex.rad(), rad_exs[num]) self.assertEqual(-ex.rad(), -rad_exs[num]) self.assertEqual(ex.dec(), dec_exs[num]) self.assertEqual(-ex.dec(), -dec_exs[num]) self.assertEqual(round(ex.hpa(), 13), hpa_exs[num]) self.assertEqual(round(-ex.hpa(), 13), -hpa_exs[num]) self.assertEqual(ex.hp(), hp_exs[num]) self.assertEqual(-ex.hp(), -hp_exs[num]) self.assertAlmostEqual(ex.gon(), gon_exs[num], 13) self.assertAlmostEqual(-ex.gon(), -gon_exs[num], 13) self.assertEqual(round(ex.gona(), 13), round(gona_exs[num], 13)) self.assertEqual(round(-ex.gona(), 13), round(-gona_exs[num], 13)) self.assertEqual(round(ex.dms(), 10), dms_exs[num]) self.assertEqual(round(-ex.dms(), 10), -dms_exs[num]) self.assertEqual(round(ex.ddm(), 12), ddm_exs[num]) self.assertEqual(round(-ex.ddm(), 12), -ddm_exs[num]) self.assertEqual(str(ex), str(dec_exs[num])) self.assertEqual(DECAngle(str(ex)), ex) self.assertEqual(int(ex), int(dec_exs[num])) self.assertEqual(float(ex), dec_exs[num]) self.assertEqual(round(ex), DECAngle(round(dec_exs[num]))) # Test HPAngle Representation self.assertEqual(repr(deca_ex), '{DECAngle: +123.74875}') self.assertEqual(repr(deca_ex3), '{DECAngle: -12.575}') # Test DECAngle Overloads self.assertEqual(dec_ex + dec_ex2, (deca_ex + deca_ex2).dec()) self.assertEqual(dec_ex2 + dec_ex, (deca_ex2 + deca_ex).dec()) self.assertEqual(dec_ex - dec_ex2, (deca_ex - deca_ex2).dec()) self.assertEqual(dec_ex2 - dec_ex, (deca_ex2 - deca_ex).dec()) self.assertEqual(dec_ex * 5, (deca_ex * 5).dec()) self.assertEqual(5 * dec_ex, (5 * deca_ex).dec()) self.assertEqual(dec_ex / 3, (deca_ex / 3).dec()) self.assertEqual(abs(-deca_ex), deca_ex) self.assertEqual(-deca_ex2, deca_ex3) self.assertEqual(deca_ex2, abs(deca_ex3)) self.assertTrue(deca_ex == deca_ex) self.assertFalse(deca_ex == deca_ex2) self.assertTrue(deca_ex != deca_ex2) self.assertFalse(deca_ex != deca_ex) self.assertTrue(deca_ex > deca_ex2) self.assertFalse(deca_ex2 > deca_ex) self.assertTrue(deca_ex2 < deca_ex) self.assertFalse(deca_ex < deca_ex2) with self.assertRaises(TypeError): deca_ex * 'a' with self.assertRaises(TypeError): 'a' * deca_ex with self.assertRaises(TypeError): deca_ex / 'a' with self.assertRaises(TypeError): deca_ex + 'a' with self.assertRaises(TypeError): 'a' + deca_ex with self.assertRaises(TypeError): deca_ex - 'a' with self.assertRaises(TypeError): 'a' - deca_ex
rad_exs = [ radians(123.74875), radians(12.575), radians(-12.575), radians(0.0525), radians(0.005) ] dec_ex = 123.74875 dec_ex2 = 12.575 dec_ex3 = -12.575 dec_ex4 = 0.0525 dec_ex5 = 0.005 dec_exs = [dec_ex, dec_ex2, dec_ex3, dec_ex4, dec_ex5] deca_ex = DECAngle(123.74875) deca_ex2 = DECAngle(12.575) deca_ex3 = DECAngle(-12.575) deca_ex4 = DECAngle(0.0525) deca_ex5 = DECAngle(0.005) deca_exs = [deca_ex, deca_ex2, deca_ex3, deca_ex4, deca_ex5] hp_ex = 123.44555 hp_ex2 = 12.3430 hp_ex3 = -12.3430 hp_ex4 = 0.0309 hp_ex5 = 0.0018 hp_exs = [hp_ex, hp_ex2, hp_ex3, hp_ex4, hp_ex5] hpa_ex = HPAngle(123.44555) hpa_ex2 = HPAngle(12.3430)