How to use the geographiclib.geodesic.Geodesic.WGS84.Inverse function in geographiclib

To help you get started, we’ve selected a few geographiclib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github echolite / ANTS / measr_asym.py View on Github external
hitcnt +=1
        avgwin += int(float(entry[5]))
        
        if lat1 == -12345 or lat2 == -12345: continue
        # write station coordinates to file
        #ofid2.write("%8.3f %8.3f \n" %(lon1,lat1))
        #ofid2.write("%8.3f %8.3f \n" %(lon2,lat2))
        stas.append((lon1,lat1))
        stas.append((lon2,lat2))
        
        # find midpoint
        mp = gl.get_midpoint(lat1,lon1,lat2,lon2)
        # find antipode of midpoint
        ap = gl.get_antipode(mp[0],mp[1])
        #find distance to antipode of midpoint
        dist = geodesic.Geodesic.WGS84.Inverse(ap[0],ap[1],lat1,lon1)\
        ['s12']/1000.
        dist2 = geodesic.Geodesic.WGS84.Inverse(ap[0],ap[1],lat2,lon2)\
        ['s12']/1000.
        # (half) Nr of segments
        numseg = int(dist/minp.segper)
        if numseg == 0:
            print 'Warning! Zero segments! Setting to 1'
            numseg = 1
        
        # get segments station 1 to antipode
        seg1 = gl.get_gcsegs(lat1,lon1,ap[0],ap[1],numseg,minp.num_max,True,\
        sta_dist,\
        minp.f_centr,minp.q,minp.g_speed)
        # get segments station 2 to antipode
        seg2 = gl.get_gcsegs(lat2,lon2,ap[0],ap[1],numseg,minp.num_max,True,\
        sta_dist,\
github echolite / ANTS / KERNELS / gc_visual.py View on Github external
ofid2=open('example_seg2.txt','w')
    for (lat,lon) in zip(lat,lon):
        ofid1.write("%7.2f %7.2f \n" %(lat,lon))
        # get midpoint
        mp = gc.get_midpoint(rome[0],rome[1],lat,lon)
        # get antipode
        ap = gc.get_antipode(mp[0],mp[1])
        ofid0.write("%7.2f %7.2f \n" %(ap[0],ap[1]))
        # first station to antipode
        segs1 = gc.get_gcsegs(rome[0],rome[1],ap[0],ap[1],20)
        # second station to antipode
        segs2 = gc.get_gcsegs(lat,lon,ap[0],ap[1],20)
        # write to file
        for seg in segs1[1:]:
            # distance midpoint - segment
            dist = geodesic.Geodesic.WGS84.Inverse(mp[0],mp[1],seg[0],seg[1])['s12']/1000
            ofid2.write("%7.2f %7.2f  %7.2f\n" %(seg[0],seg[1],dist))
        for seg in segs2[1:]:
            dist = geodesic.Geodesic.WGS84.Inverse(mp[0],mp[1],seg[0],seg[1])['s12']/1000
            ofid2.write("%7.2f %7.2f  %7.2f \n" %(seg[0],seg[1],dist)) 
    ofid0.close() 
    ofid1.close()
    ofid2.close()
    os.system('bash KERNELS/segments_example.gmt; rm example_seg?.txt')
github favll / pogom / pogom / scan.py View on Github external
lat = scan_location["latitude"]
            lng = scan_location["longitude"]
            radius = scan_location["radius"]

            d = math.sqrt(3) * 70
            points = [[{'lat2': lat, 'lon2': lng, 's': 0}]]

            # The lines below are magic. Don't touch them.
            for i in xrange(1, maxint):
                oor_counter = 0

                points.append([])
                for j in range(0, 6 * i):
                    p = points[i - 1][(j - j / i - 1 + (j % i == 0))]
                    p_new = Geodesic.WGS84.Direct(p['lat2'], p['lon2'], (j+i-1)/i * 60, d)
                    p_new['s'] = Geodesic.WGS84.Inverse(p_new['lat2'], p_new['lon2'], lat, lng)['s12']
                    points[i].append(p_new)

                    if p_new['s'] > radius:
                        oor_counter += 1

                if oor_counter == 6 * i:
                    break

            cover.extend({"lat": p['lat2'], "lng": p['lon2']}
                         for sublist in points for p in sublist if p['s'] < radius)

        self.COVER = cover
github PokemonGoF / PokemonGo-Bot / pokemongo_bot / walkers / step_walker.py View on Github external
def is_arrived(self):
        inverse = Geodesic.WGS84.Inverse(self.bot.position[0], self.bot.position[1], self.dest_lat, self.dest_lng)
        return inverse["s12"] <= self.precision + self.epsilon
github PokemonGoF / PokemonGo-Bot / pokemongo_bot / walkers / step_walker.py View on Github external
def get_next_position(self, origin_lat, origin_lng, origin_alt, dest_lat, dest_lng, dest_alt, distance):
        inverse = Geodesic.WGS84.Inverse(origin_lat, origin_lng, dest_lat, dest_lng)
        total_distance = inverse["s12"]

        if total_distance == 0:
            total_distance = self.precision or self.epsilon

        if distance == 0:
            if not self.saved_location:
                self.saved_location = origin_lat, origin_lng, origin_alt

            dest_lat, dest_lng, dest_alt = self.saved_location
            travel = self.precision
        else:
            self.saved_location = None
            travel = min(total_distance, distance)

        direct = Geodesic.WGS84.Direct(origin_lat, origin_lng, inverse["azi1"], travel)
github obspy / obspy / trunk / obspy.core / obspy / core / util.py View on Github external
:return: (Great circle distance in m, azimuth A->B in degrees,
        azimuth B->A in degrees)

    .. note::
        This function will check if you have installed the Python module
        `geographiclib `_ - a very fast module
        for converting between geographic, UTM, UPS, MGRS, and geocentric
        coordinates, for geoid calculations, and for solving geodesic problems.
        Otherwise the locally implemented Vincenty's Inverse formulae
        (:func:`~obspy.core.util.calcVincentyInverse`) is used which has known
        limitations for two nearly antipodal points and is ca. 4x slower.
    """
    try:
        # try using geographiclib
        from geographiclib.geodesic import Geodesic
        result = Geodesic.WGS84.Inverse(lat1, lon1, lat2, lon2)
        return (result['s12'], result['azi1'], result['azi2'] + 180)
    except ImportError:
        pass
    try:
        values = calcVincentyInverse(lat1, lon1, lat2, lon2)
        if np.alltrue(np.isnan(values)):
            raise StopIteration
        return values
    except StopIteration:
        msg = "Catching unstable calculation on antipodes. " + \
              "The currently used Vincenty's Inverse formulae " + \
              "has known limitations for two nearly antipodal points. " + \
              "Install the Python module 'geographiclib' to solve this issue."
        warnings.warn(msg)
        return (20004314.5, 0.0, 0.0)
    except ValueError, e:
github PokeHunterProject / pogom-updated / pogom / scan.py View on Github external
lat = scan_location["latitude"]
            lng = scan_location["longitude"]
            radius = scan_location["radius"]

            d = math.sqrt(3) * 70
            points = [[{'lat2': lat, 'lon2': lng, 's': 0}]]

            # The lines below are magic. Don't touch them.
            for i in xrange(1, maxint):
                oor_counter = 0

                points.append([])
                for j in range(0, 6 * i):
                    p = points[i - 1][(j - j / i - 1 + (j % i == 0))]
                    p_new = Geodesic.WGS84.Direct(p['lat2'], p['lon2'], (j+i-1)/i * 60, d)
                    p_new['s'] = Geodesic.WGS84.Inverse(p_new['lat2'], p_new['lon2'], lat, lng)['s12']
                    points[i].append(p_new)

                    if p_new['s'] > radius:
                        oor_counter += 1

                if oor_counter == 6 * i:
                    break

            cover.extend({"lat": p['lat2'], "lng": p['lon2']}
                         for sublist in points for p in sublist if p['s'] < radius)

        self.COVER = cover
github obspy / obspy / trunk / obspy.core / obspy / core / util / geodetics.py View on Github external
azimuth B->A in degrees)

    .. note::
        This function will check if you have installed the Python module
        `geographiclib `_ - a very fast module
        for converting between geographic, UTM, UPS, MGRS, and geocentric
        coordinates, for geoid calculations, and for solving geodesic problems.
        Otherwise the locally implemented Vincenty's Inverse formulae
        (:func:`obspy.core.util.geodetics.calcVincentyInverse`) is used which
        has known limitations for two nearly antipodal points and is ca. 4x
        slower.
    """
    try:
        # try using geographiclib
        from geographiclib.geodesic import Geodesic
        result = Geodesic.WGS84.Inverse(lat1, lon1, lat2, lon2)
        azim = result['azi1']
        if azim < 0:
            azim += 360
        bazim = result['azi2'] + 180
        return (result['s12'], azim, bazim)
    except ImportError:
        pass
    try:
        values = calcVincentyInverse(lat1, lon1, lat2, lon2)
        if np.alltrue(np.isnan(values)):
            raise StopIteration
        return values
    except StopIteration:
        msg = "Catching unstable calculation on antipodes. " + \
              "The currently used Vincenty's Inverse formulae " + \
              "has known limitations for two nearly antipodal points. " + \
github sagost / VideoUavTracker / NewProject.py View on Github external
PreviousLatitude = GpxPartition[Counter-1][1][0]
                PreviousLongitude = GpxPartition[Counter-1][1][1]
                GeodesicCalcolus = Geodesic.WGS84.Inverse(PreviousLatitude, PreviousLongitude, ActualLatitude, ActualLongitude)
                Speed = GeodesicCalcolus['s12'] /1
                Course = GeodesicCalcolus['azi2']
                if Course < 0:
                    Course += 360
                Ele = x[1][2]
                Time = x[1][3]
                Counter = Counter + 1
            else:
                ActualLatitude = x[1][0]
                ActualLongitude = x[1][1]
                PreviousLatitude = GpxPartition[Counter+1][1][0]
                PreviousLongitude = GpxPartition[Counter+1][1][1]
                GeodesicCalcolus = Geodesic.WGS84.Inverse(ActualLatitude, ActualLongitude, PreviousLatitude, PreviousLongitude)
                Speed = GeodesicCalcolus['s12'] * 1
                Course = GeodesicCalcolus['azi2']
                if Course < 0:
                    Course += 360
                Ele = x[1][2]
                Time = x[1][3]
                Counter = Counter + 1  
            outputFile.write(str(ActualLatitude)+' '+str(ActualLongitude)+' '+str(Ele)+' '+str(Speed)+' '+str(Course)+' '+str(Time)+'\n')    
        outputFile.close() 
        self.Main.LoadProjFromNew(self.projectfile)
        if os.name == 'nt':
            os.remove (self.tmp)
        self.close()