Beispiel #1
0
    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)
Beispiel #2
0
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_geo2grid(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()
            hem, zonecomp, eastcomp, northcomp, psf, grid_conv = geo2grid(coord.lat, coord.long)
            assert (zonecomp == coord.zone)
            assert (abs(eastcomp - coord.easting) < 4e-4)
            assert (abs(northcomp - coord.northing) < 4e-4)
Beispiel #4
0
def geo2gridio(fn, fn_out, latitude, longitude, geotypein):
    """
        Input:
        The CSV data must have headers.

         Inputs passed the the function:
         :param fn: input file path
         :param fn_out: file output path
         :param latitude: is the column name in the csv where the latitudes are stored
         :param longitude: is the column name in the csv where the longitudes are stored
         :param geotypein: format of latitude and longitude e.g. DD or DMS

        Output:
        Data in the file is output to the fn_out location as a CSV.
        """

    # Check whether geotypein value is from GUI or if function called within other code, then check that a valid
    # geotypein value was provided
    if isinstance(geotypein, ttk.StringVar):
        geotypein = geotypein.get()
    geotypein_options = ["DD", "DMS"]
    if geotypein not in geotypein_options:
        raise ValueError("Invalid geotypein. Expected one of: %s" %
                         geotypein_options)

    # Opens the CSV as a pandas dataframe
    csvdf = pd.read_csv(fn, low_memory=False)

    # Converts DMS lat and long to Decimal Degrees if required
    if geotypein == 'DMS':
        csvdf['LatitudeDD'] = csvdf[latitude].apply(cv.dms2dd)
        csvdf['LongitudeDD'] = csvdf[longitude].apply(cv.dms2dd)
        latitude = 'LatitudeDD'
        longitude = 'LongitudeDD'

    # Sends data to tf.geo2grid
    returned = csvdf.apply(lambda x: tf.geo2grid(x[latitude], x[longitude]),
                           axis=1)
    # Convert tuple returned from tf.gepo2grid into DafaFrame
    resultdf = pd.DataFrame(list(returned),
                            columns=[
                                'Hemisphere', 'UTMZone', 'Easting', 'Northing',
                                'Point Scale Factor', 'Grid Convergence'
                            ])
    # 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)
Beispiel #5
0
def stn2xml(skiasciifile):
    # Create dynaxml root object
    stnroot = dnaxmlroot('stn')
    # Read ski-ascii text, list stations and separate variables by ':'
    stnlines = []
    with open(skiasciifile) as myfile:
        for line in myfile.readlines():
            stnlines.append(line)
    for num, i in enumerate(stnlines):
        stnlines[num] = i.split(' ')
        stnlines[num] = list(filter(None, stnlines[num]))
    # Write station list components to xml
    linebatchdict = {}
    linebatch = 0
    namelist = []
    # Station constants
    constraint = 'FFF'
    coordtype = 'LLH'
    for line in stnlines:
        linetype = line[0][0:2]
        if line[0] == "@%Coordinate":
            outputformat = line[2].rstrip()
        if linetype == '@#':
            # Start of data & station coordinates
            name = line[0][2:]
            llh = xyz2llh(float(line[1]), float(line[2]), float(line[3]))
            xaxis = str(dec2hp(float(llh[0])))
            yaxis = str(dec2hp(float(llh[1])))
            height = str(round(llh[2], 4))
            gridcoords = geo2grid(llh[0], llh[1])
            zone = gridcoords[0][0] + str(gridcoords[1])
            desc = line[0][2:] + ', ?, ?'
            linebatch += 1
            # Add station coordinates, takes only one approximate coordinate
            # Code will only take if output format is Cartesian
            if linebatch >= 1:
                if outputformat == 'Cartesian' and name not in namelist:
                    stnroot = addstnrecord(stnroot, name, constraint,
                                           coordtype, xaxis, yaxis, height,
                                           zone, desc)
                    namelist.append(line[0][2:])
        if linebatch in linebatchdict:
            linebatchdict[linebatch].append(line)
        else:
            linebatchdict[linebatch] = [line]

    return stnroot
Beispiel #6
0
    def test_geo2grid(self):
        abs_path = os.path.abspath(os.path.dirname(__file__))

        # Test various coordinates in Australia
        testdata = read_dnacoord(
            os.path.join(abs_path, 'resources/natadjust_rvs_example.dat'))
        for coord in testdata:
            coord.converthptodd()
            hem, zonecomp, eastcomp, northcomp, psf, grid_conv = geo2grid(
                coord.lat, coord.long)
            self.assertEqual(zonecomp, coord.zone)
            self.assertLess(abs(eastcomp - coord.easting), 4e-4)
            self.assertLess((northcomp - coord.northing), 4e-4)

        # Test North and South Hemisphere Output
        north_ex = (DMSAngle(34, 57,
                             00.79653).dec(), DMSAngle(117, 48,
                                                       36.68783).dec())
        south_ex = (DMSAngle(-34, 57,
                             00.79653).dec(), DMSAngle(117, 48,
                                                       36.68783).dec())
        north_grid = geo2grid(north_ex[0], north_ex[1])
        south_grid = geo2grid(south_ex[0], south_ex[1])
        self.assertEqual(north_grid[0], 'North')
        self.assertEqual(south_grid[0], 'South')
        self.assertEqual(north_grid[1], south_grid[1])  # Zone
        self.assertEqual(north_grid[2], south_grid[2])  # Easting
        self.assertEqual(north_grid[3], 10000000 - south_grid[3])  # Northing
        self.assertEqual(north_grid[4], south_grid[4])  # PSF
        self.assertEqual(north_grid[5], -south_grid[5])  # Grid Convergence

        # Test Input Validation
        with self.assertRaises(ValueError):
            geo2grid(0, 45, -1)
        with self.assertRaises(ValueError):
            geo2grid(0, 45, 61)
        with self.assertRaises(ValueError):
            geo2grid(-81, 45, 0)
        with self.assertRaises(ValueError):
            geo2grid(85, 45, 0)
        with self.assertRaises(ValueError):
            geo2grid(0, -181, 0)
        with self.assertRaises(ValueError):
            geo2grid(0, 181, 0)