def vincinv_utm(zone1, east1, north1, zone2, east2, north2, hemisphere1='south', hemisphere2='south', ellipsoid=grs80): # Convert utm to geographic pt1 = grid2geo(zone1, east1, north1, hemisphere1, ellipsoid) pt2 = grid2geo(zone2, east2, north2, hemisphere2, ellipsoid) # Use vincinv return vincinv(pt1[0], pt1[1], pt2[0], pt2[1], ellipsoid)
def test_geo_grid_transform_interoperability(self): abs_path = os.path.abspath(os.path.dirname(__file__)) test_geo_coords = np.genfromtxt(os.path.join( abs_path, 'resources/Test_Conversion_Geo.csv'), delimiter=',', dtype='S4,f8,f8', names=['site', 'lat', 'lon']) test_grid_coords = np.genfromtxt( os.path.join(abs_path, 'resources/Test_Conversion_Grid.csv'), delimiter=',', dtype='S4,i4,f8,f8', names=['site', 'zone', 'east', 'north']) geoed_grid = np.array( list( grid2geo(*x) for x in test_grid_coords[['zone', 'east', 'north']])) np.testing.assert_almost_equal( geoed_grid[:, :2], dms2dd_v(np.array(test_geo_coords[['lat', 'lon']].tolist())), decimal=8) gridded_geo = np.stack( geo2grid(*x) for x in dms2dd_v( np.array(test_geo_coords[['lat', 'lon']].tolist()))) np.testing.assert_almost_equal( gridded_geo[:, 2:4].astype(float), np.array(test_grid_coords[['east', 'north']].tolist()), decimal=3)
def vincdir_utm(zone1, east1, north1, azimuth1to2, ell_dist, hemisphere1='south', ellipsoid=grs80): # Convert utm to geographic pt1 = grid2geo(zone1, east1, north1, hemisphere1) # Use vincdir lat2, lon2, azimuth2to1 = vincdir(pt1[0], pt1[1], azimuth1to2, ell_dist, ellipsoid) # Convert geographic to utm hemisphere2, zone2, east2, north2, psf2, gc2 = geo2grid(lat2, lon2) return hemisphere2, zone2, east2, north2, azimuth2to1
def test_grid2geo(self): abs_path = os.path.abspath(os.path.dirname(__file__)) testdata = read_dnacoord(os.path.join(abs_path, 'resources/natadjust_rvs_example.dat')) for coord in testdata: coord.converthptodd() latcomp, longcomp, psf, grid_conv = grid2geo(coord.zone, coord.easting, coord.northing) assert (abs(latcomp - coord.lat) < 5e-9) assert (abs(longcomp - coord.long) < 5e-9)
def test_enu2xyz(self): MOBS_MGA2020 = (55, 321820.085, 5811181.510, 40.570) MOBS_MGA1994 = (55, 321819.594, 5811180.038, 40.659) # Convert UTM Projection Coordinates to Geographic Coordinates MOBS_GDA2020 = grid2geo(MOBS_MGA2020[0], MOBS_MGA2020[1], MOBS_MGA2020[2]) MOBS_GDA1994 = grid2geo(MOBS_MGA1994[0], MOBS_MGA1994[1], MOBS_MGA1994[2]) # Convert Geographic Coordinates to Cartesian XYZ Coordinates MOBS_GDA2020_XYZ = llh2xyz(MOBS_GDA2020[0], MOBS_GDA2020[1], MOBS_MGA2020[3]) MOBS_GDA1994_XYZ = llh2xyz(MOBS_GDA1994[0], MOBS_GDA1994[1], MOBS_MGA1994[3]) # Generate Vector Between UTM Projection Coordinates mga_vector = [MOBS_MGA2020[1] - MOBS_MGA1994[1], MOBS_MGA2020[2] - MOBS_MGA1994[2], MOBS_MGA2020[3] - MOBS_MGA1994[3]] # Generate Vector Between Cartesian XYZ Coordinates xyz_vector = (MOBS_GDA2020_XYZ[0] - MOBS_GDA1994_XYZ[0], MOBS_GDA2020_XYZ[1] - MOBS_GDA1994_XYZ[1], MOBS_GDA2020_XYZ[2] - MOBS_GDA1994_XYZ[2]) # Rotate UTM Projection Vector by Grid Convergence grid_dist, grid_brg = rect2polar(mga_vector[0], mga_vector[1]) local_east, local_north = polar2rect(grid_dist, grid_brg - MOBS_GDA2020[3]) local_vector = (local_east, local_north, mga_vector[2]) # Calculate XYZ Vector using Local Vector Components x, y, z = enu2xyz(MOBS_GDA2020[0], MOBS_GDA2020[1], *local_vector) self.assertAlmostEqual(x, xyz_vector[0], 4) self.assertAlmostEqual(y, xyz_vector[1], 4) self.assertAlmostEqual(z, xyz_vector[2], 4) # Calculate Local Vector using XYZ Vector Components e, n, u = xyz2enu(MOBS_GDA2020[0], MOBS_GDA2020[1], *xyz_vector) self.assertAlmostEqual(e, local_vector[0], 4) self.assertAlmostEqual(n, local_vector[1], 4) self.assertAlmostEqual(u, local_vector[2], 4)
def grid2geoio(fn, fn_out, easting, northing, utmzone, geotypeout): """ Input: The CSV data must have headers. Inputs passed the the function: :param fn: input file path :param fn_out: file output path :param easting: is the column name in the csv where the eastings are stored :param northing: is the column name in the csv where the northings are stored :param utmzone: is the column name in the csv where the UTM Zone is stored :param geotypeout: format of latitude and longitude output e.g. DD or DMS Output: Data in the file is output to the fn_out location as a CSV. """ # Check whether geotypeout value is from GUI or if function called within other code, then check that a valid # geotypeout value was provided if isinstance(geotypeout, ttk.StringVar): geotypeout = geotypeout.get() geotypeout_options = ["DD", "DMS"] if geotypeout not in geotypeout_options: raise ValueError("Invalid geotypeout. Expected one of: %s" % geotypeout_options) # Opens the CSV as a pandas dataframe csvdf = pd.read_csv(fn, low_memory=False) # Sends data to tf.grid2geo returned = csvdf.apply( lambda x: tf.grid2geo(x[utmzone], x[easting], x[northing]), axis=1) # Convert tuple returned to DafaFrame resultdf = pd.DataFrame(list(returned), columns=[ 'Latitude', 'Longitude', 'Point Scale Factor', 'Grid Convergence' ]) if geotypeout == 'DMS': resultdf['Latitude'] = resultdf['Latitude'].apply(cv.dd2dms) resultdf['Longitude'] = resultdf['Longitude'].apply(cv.dd2dms) # Adds the results to the original dataframe from the csv csvdf = pd.concat([csvdf, resultdf], axis=1) # Writes the dataframe to a csv csvdf.to_csv(fn_out, index=False)
def test_grid2geo(self): abs_path = os.path.abspath(os.path.dirname(__file__)) testdata = read_dnacoord( os.path.join(abs_path, 'resources/natadjust_rvs_example.dat')) for coord in testdata: coord.converthptodd() latcomp, longcomp, psf, grid_conv = grid2geo( coord.zone, coord.easting, coord.northing) self.assertLess(abs(latcomp - coord.lat), 5e-9) self.assertLess(abs(longcomp - coord.long), 5e-9) # Test North and South Hemisphere Output north_ex = (50, 573976.8747, 3867822.4539, 'North') south_ex = (50, 573976.8747, 6132177.5461, 'South') north_geo = grid2geo(*north_ex) south_geo = grid2geo(*south_ex) self.assertEqual(north_geo[0], -south_geo[0]) self.assertEqual(north_geo[1], south_geo[1]) self.assertEqual(north_geo[2], south_geo[2]) self.assertEqual(north_geo[3], -south_geo[3]) # Test Input Validation with self.assertRaises(ValueError): grid2geo(-1, 0, 500000) with self.assertRaises(ValueError): grid2geo(61, 0, 500000) with self.assertRaises(ValueError): grid2geo(0, -2830001, 500000) with self.assertRaises(ValueError): grid2geo(0, 3830001, 500000) with self.assertRaises(ValueError): grid2geo(0, 0, -1) with self.assertRaises(ValueError): grid2geo(0, 0, 10000001) with self.assertRaises(ValueError): grid2geo(0, 0, 500000, 'fail')