当前位置: 首页>>代码示例>>Python>>正文


Python haversine.haversine方法代码示例

本文整理汇总了Python中haversine.haversine方法的典型用法代码示例。如果您正苦于以下问题:Python haversine.haversine方法的具体用法?Python haversine.haversine怎么用?Python haversine.haversine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在haversine的用法示例。


在下文中一共展示了haversine.haversine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_distance_to

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def get_distance_to(self, dest):
        origin = (self.lat, self.lng)
        dest = (dest.lat, dest.lng)

        forward_key = origin + dest
        backward_key = dest + origin

        if forward_key in Gene.__distances_table:
            return Gene.__distances_table[forward_key]

        if backward_key in Gene.__distances_table:
            return Gene.__distances_table[backward_key]

        dist = int(haversine(origin, dest))
        Gene.__distances_table[forward_key] = dist

        return dist 
开发者ID:lccasagrande,项目名称:TSP-GA,代码行数:19,代码来源:tsp_ga.py

示例2: partial_location_distance

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def partial_location_distance(lat1, long1, lat2, long2, threshold):
    """Given two coordinates perform a matching based on its distance using the Haversine Formula.

    Args:
        lat1: Latitude value for first coordinate point.
        lat2: Latitude value for second coordinate point.
        long1: Longitude value for first coordinate point.
        long2: Longitude value for second coordinate point.
        threshold (float): A kilometer measurement for the threshold distance between these two points.

    Returns:
        float: Number between 0.0 and 1.0 depending on match.

    """
    from haversine import haversine, Unit
    distance = haversine((lat1, long1), (lat2, long2), unit=Unit.KILOMETERS)
    result = 1 - (distance / threshold)
    logger.debug(
        "--\t\tpartial_location_distance '%s' '%s' threshold: '%s'\tresult: '%s'",
        (lat1, long1), (lat2, long2), threshold, result,
    )
    return result


# default weights used for the semantic equivalence process 
开发者ID:oasis-open,项目名称:cti-python-stix2,代码行数:27,代码来源:environment.py

示例3: max_side

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def max_side(self):  # unit: m
        return max(haversine((self.lon_min, self.lat_min), (self.lon_min, self.lat_max)),
                   haversine((self.lon_min, self.lat_min), (self.lon_max, self.lat_min)),
                   haversine((self.lon_min, self.lat_max), (self.lon_max, self.lat_max))) * 1000 
开发者ID:yrjyrj123,项目名称:MobikeAgent,代码行数:6,代码来源:tile.py

示例4: getGPS_distance

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def getGPS_distance(prevGPS, curGPS):
    """ Returns the distance between two GPS coordinates(in Lat/Lon Coord System) in meters"""
    distance = haversine.haversine(prevGPS, curGPS) * 1000  # meters

    return distance 
开发者ID:Transportation-Inspection,项目名称:visual_odometry,代码行数:7,代码来源:GPS_VO.py

示例5: get_geometric_mean

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def get_geometric_mean(self, locations):
        """
        Locates the geometric mean of a list of locations, taken from David Jurgen's implementation,
        with less than three locations a random location is selected, else construct a geometric mean.
        """

        n = len(locations)

        # The geometric median is only defined for n > 2 points, so just return
        # an arbitrary point if we have fewer
        if n < 2:
            return locations[np.random.randint(0, n)]

        min_distance_sum = 10000000
        median = None  # Point type

        # Loop through all the points, finding the point that minimizes the
        # geodetic distance to all other points.  By construction median will
        # always be assigned to some non-None value by the end of the loop.
        for i in range(0, n):
            p1 = locations[i]
            dist_sum = 0
            for j in range(0, n):
                p2 = locations[j]
                # Skip self-comparison
                if i == j:
                    continue
                dist = haversine(p1, p2)
                dist_sum += dist

                # Short-circuit early if it's clear that this point cannot be
                # the median since it does not minimize the distance sum
                if dist_sum > min_distance_sum:
                    break

            if dist_sum < min_distance_sum:
                min_distance_sum = dist_sum
                median = p1

        return median 
开发者ID:networkdynamics,项目名称:geoinference,代码行数:42,代码来源:method.py

示例6: social_closeness

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def social_closeness(self):
        """
        The social tightness based model is based on the assumption
        that different friends hae different importance to a user.
        The social closeness between two users is measured via cosine similarly,
        then we estimate the probability of user i and user j located at a distance
        | l_i - l_j | with social closeness. Then we estimate the probability of user_i
        located at l_i and use the location with the top probability
        """
        pairs = 0
        #here we calculate social closeness
        logger.debug("Calcuating social closeness")
        for user in self.users_with_location:
            user_location = self.mention_network.node_data_(user)
            for friend in self.mention_network.neighbors_iter_(user):
                friend_location = self.mention_network.node_data_(friend)
                if not friend_location: continue

                pairs += 1
                social_closeness = round(self.cosine_similarity(user,friend),2)
                self.sij[user][friend] = social_closeness
                distance = round(haversine(user_location,friend_location),0)
                self.probability_distance_social_closeness[distance][social_closeness] += 1.0

        #the normalizing factor is the total number of social_closeness probabilities added above...
        normalizing_factor = pairs
        for distance in self.probability_distance_social_closeness:
            for social_closeness in self.probability_distance_social_closeness[distance]:
                self.probability_distance_social_closeness[distance][social_closeness] /= normalizing_factor
        logger.debug("Finished calculating the social closeness...") 
开发者ID:networkdynamics,项目名称:geoinference,代码行数:32,代码来源:method.py

示例7: most_likely_location

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def most_likely_location(self,user,location_set):
        """
        Returns the most likely location for a user of unknown locale,
        based on the social tightness model.
        """
        max_probability = float('-inf')
        best_location = None
        for neighbor_u in self.mention_network.neighbors_iter_(user):
            if neighbor_u not in location_set: continue

            location_of_neighbor_u = self.mention_network.node_data_(neighbor_u)
            probability = 0

            for neighbor_v in self.mention_network.neighbors_iter_(neighbor_u):
                if neighbor_v not in location_set: continue
                location_of_neighbor_v = self.mention_network.node_data_(neighbor_v)

                #to get the dict-lookup correct, we round to the nearest kilometer
                distance = round(haversine(location_of_neighbor_u,location_of_neighbor_v),0)

                # "" , round to two significant figures
                social_closeness = self.sij[neighbor_u][neighbor_v]
                probability += self.probability_distance_social_closeness[distance][social_closeness]

            #compare the probability of this neighbor with other possible neighbors
            #sets the highest-probability user as the most likely location
            if probability > max_probability:
                max_probability = probability
                best_location = location_of_neighbor_u
    
        return best_location 
开发者ID:networkdynamics,项目名称:geoinference,代码行数:33,代码来源:method.py

示例8: calculate_probability

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def calculate_probability(self, l_u, l_v):
        """
        Calculates the probability of the edge being present given the distance
        between user u and neighbor v, l_u indicates the location of user u and
        l_v indicates the location of user v (tuples containing latitude and
        longitude).
        """
        return self.a * (abs(haversine(l_u,l_v,miles=True)) + self.b)**(self.c) 
开发者ID:networkdynamics,项目名称:geoinference,代码行数:10,代码来源:method.py

示例9: distance

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def distance(loc1, loc2):
	if loc1 == None or loc2 == None:
		return -1
	return haversine(loc1, loc2, miles=True)

# get random coordinates 
开发者ID:networkdynamics,项目名称:geoinference,代码行数:8,代码来源:utils.py

示例10: location_error

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def location_error(true_loc, coord, LocRes):
	# we create location resolver in method.py because we don't want it to load every time we import this file
	if not true_loc: return 0.0
	# check if location field contains coordinates
	#coord = isCoord(text_loc)
	if coord: return haversine(true_loc, coord)
	# resolve to lat lon 
	res = LocRes.reverse_geocode(text_loc.split()[0],text_loc.split()[1])
	if not res: return 0.0
	res_val = map(float, res)
	return haversine(true_loc, res_val)

# create a vector 
# [ mention relationship, location error, post data, social triangles ] 
开发者ID:networkdynamics,项目名称:geoinference,代码行数:16,代码来源:utils.py

示例11: cached_polyline

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def cached_polyline(origin, destination, speed, google_map_api_key=None):
        '''
        Google API has limits, so we can't generate new Polyline at every tick...
        '''

        # Absolute offset between bot origin and PolyLine get_last_pos() (in meters)
        if PolylineObjectHandler._cache and PolylineObjectHandler._cache.get_last_pos() != (None, None):
            abs_offset = haversine.haversine(tuple(origin), PolylineObjectHandler._cache.get_last_pos())*1000
        else:
            abs_offset = float("inf")
        is_old_cache = lambda : abs_offset > 8 # Consider cache old if we identified an offset more then 8 m
        new_dest_set = lambda : tuple(destination) != PolylineObjectHandler._cache.destination

        if PolylineObjectHandler._run and (not is_old_cache()):
            # bot used to have struggle with making a decision.
            PolylineObjectHandler._instability -= 1
            if PolylineObjectHandler._instability <= 0:
                PolylineObjectHandler._instability = 0
                PolylineObjectHandler._run = False
            pass # use current cache
        elif None == PolylineObjectHandler._cache or is_old_cache() or new_dest_set():
            # no cache, old cache or new destination set by bot, so make new polyline
            PolylineObjectHandler._instability += 2
            if 10 <= PolylineObjectHandler._instability:
                PolylineObjectHandler._run = True
                PolylineObjectHandler._instability = 20 # next N moves use same cache

            PolylineObjectHandler._cache = Polyline(origin, destination, speed, google_map_api_key)
        else:
            # valid cache found
            PolylineObjectHandler._instability -= 1
            PolylineObjectHandler._instability = max(PolylineObjectHandler._instability, 0)
            pass # use current cache
        return PolylineObjectHandler._cache 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot-Backup,代码行数:36,代码来源:polyline_generator.py

示例12: _get_steps_dict

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def _get_steps_dict(self):
        walked_distance = 0.0
        steps_dict = {}
        for step in self._get_walk_steps():
            walked_distance += haversine.haversine(*step) * 1000
            steps_dict[walked_distance] = step
        return steps_dict 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot-Backup,代码行数:9,代码来源:polyline_generator.py

示例13: get_alt

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def get_alt(self):
        closest_sample = None
        best_distance = float("inf")
        for point in self._elevation_at_point.keys():
            local_distance = haversine.haversine(self._last_pos, point)*1000
            if local_distance < best_distance:
                closest_sample = point
                best_distance = local_distance
        if closest_sample in self._elevation_at_point:
            return self._elevation_at_point[closest_sample]
        else:
            return None 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot-Backup,代码行数:14,代码来源:polyline_generator.py

示例14: get_pos

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def get_pos(self):
        if self.speed > self.get_total_distance():
            self._last_pos = self.destination
            self._last_step = len(self._step_keys)-1
        if self.get_last_pos() == self.destination:
            return self.get_last_pos()
        distance = self.speed
        origin = Point(*self._last_pos)
        ((so_lat, so_lng), (sd_lat, sd_lng)) = self._step_dict[self._step_keys[self._last_step]]
        bearing = self._calc_bearing(so_lat, so_lng, sd_lat, sd_lng)
        while haversine.haversine(self._last_pos, (sd_lat, sd_lng))*1000 < distance:
            distance -= haversine.haversine(self._last_pos, (sd_lat, sd_lng))*1000
            self._last_pos = (sd_lat, sd_lng)
            if self._last_step < len(self._step_keys)-1:
                self._last_step += 1
                ((so_lat, so_lng), (sd_lat, sd_lng)) = self._step_dict[self._step_keys[self._last_step]]
                bearing = self._calc_bearing(so_lat, so_lng, sd_lat, sd_lng)
                origin = Point(so_lat, so_lng)
                lat, lng = self._calc_next_pos(origin, distance, bearing)
                if haversine.haversine(self._last_pos, (lat, lng))*1000 < distance:
                    distance -= haversine.haversine(self._last_pos, (lat, lng))*1000
                    self._last_pos = (lat, lng)
            else:
                return self.get_last_pos()
        else:
            lat, lng = self._calc_next_pos(origin, distance, bearing)
            self._last_pos = (lat, lng)
            return self.get_last_pos() 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot-Backup,代码行数:30,代码来源:polyline_generator.py

示例15: get_total_distance

# 需要导入模块: import haversine [as 别名]
# 或者: from haversine import haversine [as 别名]
def get_total_distance(self):
        return math.ceil(sum([haversine.haversine(*x) * 1000 for x in self._get_walk_steps()])) 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot-Backup,代码行数:4,代码来源:polyline_generator.py


注:本文中的haversine.haversine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。