示例#1
0
def test_LatLon_tostring():
    '''
    Test LatLon method to_string
    '''
    palmyra = LatLon(5.8833, -162.0833) # test location is Palmyra Atoll
    # Built-in string conversion (calls to_string):
    assert str(palmyra) == '5.8833, -162.0833' # Failure of __str__ method
    # to_string method with decimal degrees:
    assert palmyra.to_string('D') == ('5.8833', '-162.0833') # Failure of degree decimal output
    # to_string method with degree minute seconds:
    assert palmyra.to_string('d%, %m%, %S%, %H') == ('5, 52, 59.88, N', '162, 4, 59.88, W')
    # to_string method with fancy separators:
    assert palmyra.to_string('H%_%d%deg %M%"') == ('N_5deg 52.998"', 'W_162deg 4.998"')
示例#2
0
            print(row[3])  #Lat DDMM.MMM
            print(row[4])  #Long DDDMM.MMM
            print(row[5])  #Height m
            print(str(uuid.uuid1()))
            latdeg = row[3][:2]
            print(latdeg)
            latmin = row[3][2:].replace('N', '')
            print(latmin)
            longdeg = row[4][:3]
            print(longdeg)
            longmin = row[4][3:].replace('E', '')
            print(longmin)

            latlonobj = LatLon(Latitude(degree=latdeg, minute=latmin),
                               Longitude(degree=longdeg, minute=longmin))
            print(latlonobj.to_string(
                'D'))  # Print coordinates to degree minute second

            lat = str(latlonobj.lat)
            long = str(latlonobj.lon)
            alt = float(row[5].replace('m', '')) * 0.1
            alt = str(alt)
            newline = "	<LandmarkLocation instanceId=\"{" + str(uuid.uuid1(
            )) + "}\" type=\"POI\" name=\"" + row[
                0] + "\" lat=\"" + lat + "\" lon=\"" + long + "\" alt=\"" + alt + "\"/>"
            with open('file.xml', 'a') as f:
                print(newline, file=f)
            f.close()
with open('file.xml', 'a') as f:
    print("</FSData>", file=f)
f.close()
"""
示例#3
0
class Location:
    """
    Parameters
    ----------
    lat : LatLon.lat
    lon : LatLon.lon

    Attributes
    ----------
    latlon : LatLon
    """

    def __init__(self, lat, lon):
        self.latlon = LatLon(Latitude(lat), Longitude(lon))

    def get_distance_in_km(self, snd_location):
        """
        Parameters
        ----------
        snd_location : Location

        Returns
        -------
        int
        """
        return self.latlon.distance(snd_location.latlon)

    def get_distance_in_m(self, snd_location):
        """
        Parameters
        ----------
        snd_location : Location

        Returns
        -------
        int
        """
        return self.get_distance_in_km(snd_location) * 1000

    def get_heading(self, snd_location):
        """
        Parameters
        ----------
        snd_location : Location

        Returns
        -------
        LatLon.heading
        """
        return self.latlon.heading_initial(snd_location.latlon)

    def get_lat_lon(self):
        """
        Returns
        -------
        LatLon
        """
        return self.latlon

    def lat_lon_to_string(self):
        """
        Returns
        -------
        String
        """
        return self.latlon.to_string('D')

    def offset_in_m(self, heading, distance):
        """
        Parameters
        ----------
        heading : LatLon.heading
        distance : int

        Returns
        -------
        Location
        """
        latlon = self.latlon.offset(heading, distance / 1000)
        return Location(latlon.to_string('D')[0], latlon.to_string('D')[1])