How to use the geopy.distance.distance function in geopy

To help you get started, we’ve selected a few geopy 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 milo2012 / osintstalker / geostalker.py View on Github external
doc = lxml.html.document_fromstring(content)
		photoLat = doc.xpath('//*[@id="main"]/div[2]/table[2]/tbody/tr[26]/td/text()')
		photoLng= doc.xpath('//*[@id="main"]/div[2]/table[2]/tbody/tr[27]/td/text()')

		if photoLat and 'deg' in str(photoLat[0]) and 'deg' in str(photoLng[0]):
			newPhotoLat = photoLat[0].replace('deg','').replace("'","").replace('"','').split(' ')
			newPhotoLng = photoLng[0].replace('deg','').replace("'","").replace('"','').split(' ')
			photoLatStr = str(float(newPhotoLat[0])+float(newPhotoLat[2])/60+float(newPhotoLat[3])/3600)
			photoLngStr = str(float(newPhotoLng[0])+float(newPhotoLng[2])/60+float(newPhotoLng[3])/3600)

			#photoLatStr = str(float(newPhotoLat[0])+float(newPhotoLat[2])/60+float(newPhotoLat[3])/3600)
			#photoLngStr = str(float(newPhotoLng[0])+float(newPhotoLng[2])/60+float(newPhotoLng[3])/3600)

			pt1 = geopy.Point(lat, lng)
			pt2 = geopy.Point(photoLatStr, photoLngStr)
			dist = geopy.distance.distance(pt1, pt2).meters

			outputStr = '[*] Found Matching Geocoordinates in Flickr Data: ('+str(photoLatStr)+','+str(photoLngStr)+')\t'+str(dist)+' meters'
			report += '\n'+outputStr
			#print geoLocUrl
		
			userName = soup.find('span',attrs={'class':'photo-name-line-1'})
			#print userName.text
			
			cameraModel = root.cssselect("html body.zeus div#main.clearfix div.photo-data table tbody tr.lookatme td a")
			if cameraModel:
				cameraModelText = cameraModel[0].text
			else:
				cameraModelText = ''
			
			#url #title #username #cameraModel #latitude #longitude
			url1 = 'http://www.flickr.com/photos/'+str(i.get('owner'))+'/'+str(i.get('id'))
github obeattie / django-geo / misc.py View on Github external
def base_cmp_by_proximity(current, previous, coords):
	"""Compare method for two objects with latitude and longitude in comparison to a lat/long pair."""
	from geopy import distance as dist
	
	current_distance = dist.distance(current.coords_tuple, coords).feet
	previous_distance = dist.distance(previous.coords_tuple, coords).feet
	if current_distance < previous_distance:
		return -1
	elif current_distance == previous_distance:
		return 0
	else:
		return 1
github vipyoung / kharita / anim_map / methods.py View on Github external
def partition_edge(edge, distance_interval):
	"""
	given an edge, creates holes every x meters (distance_interval)
	:param edge: a given edge
	:param distance_interval: in meters
	:return: list of holes
	"""

	# We always return the source node of the edge, hopefully the target will be added as the source of another edge.
	holes = []
	d = geopy.distance.VincentyDistance(meters=distance_interval)
	# make sure we are using lat,lon not lon,lat as a reference.
	startpoint = geopy.Point(edge[0].get_coordinates())
	endpoint = geopy.Point(edge[1].get_coordinates())
	initial_dist = geopy.distance.distance(startpoint, endpoint).meters
	if initial_dist < distance_interval:
		# return [], distance_interval - initial_dist
		return holes
	# compute the angle=bearing at which we need to be moving.
	bearing = calculate_bearing(startpoint[0], startpoint[1], endpoint[0], endpoint[1])
	last_point = startpoint
	diff_time = edge[1].last_seen - edge[0].last_seen
	delta_time = diff_time.days*24*3600 + diff_time.seconds
	time_increment = delta_time / (int(initial_dist) / distance_interval)
	for i in range(int(initial_dist) / distance_interval):
		new_point = geopy.Point(d.destination(point=last_point, bearing=bearing))
		str_timestamp = datetime.datetime.strftime(edge[0].last_seen + datetime.timedelta(seconds=time_increment), "%Y-%m-%d %H:%M:%S+03")
		holes.append(GpsPoint(lat=new_point.latitude, lon=new_point.longitude, angle=bearing,
		                      timestamp=str_timestamp))
		last_point = new_point
	# return holes, initial_dist - (initial_dist / distance_interval) * distance_interval
github Kneckter / SpawnpointClusterTool / cluster.py View on Github external
def get_new_coords(init_loc, distance, bearing):
    origin = geopy.Point(init_loc[0], init_loc[1])
    destination = geopy.distance.distance(kilometers=distance).destination(origin, bearing)
    return (destination.latitude, destination.longitude)
github michaeldavie / env_canada / env_canada / ec_hydro.py View on Github external
def site_distance(site):
            """Calculate distance to a site."""
            return distance.distance((lat, lon),
                                     (site['Latitude'], site['Longitude']))
github andrewyates / airbnb-listings / predict.py View on Github external
def metro_distance(self, lat, lng, topk=2):
        distances = [geopy.distance.distance((lat, lng), metrocoord).km for metrocoord in self.metro_coords]
        return sorted(distances)[:topk]
github Noctem / Monocle / utils.py View on Github external
def get_gains(dist=70):
    """Returns lat and lon gain

    Gain is space between circles.
    """
    start = Point(*MAP_CENTER)
    base = dist * sqrt(3)
    height = base * sqrt(3) / 2
    dis_a = distance(meters=base)
    dis_h = distance(meters=height)
    lon_gain = dis_a.destination(point=start, bearing=90).longitude
    lat_gain = dis_h.destination(point=start, bearing=0).latitude
    return abs(start.latitude - lat_gain), abs(start.longitude - lon_gain)
github vipyoung / kharita / anim_map / methods.py View on Github external
:param s:
	:param t:
	:param k_reach:
	:return:
	"""
	if s == -1 or t == -1 or s == t:
		return False

	edge_distance = geopy.distance.distance(geopy.Point(clusters[s].get_coordinates()), \
	                                        geopy.Point(clusters[t].get_coordinates())).meters
	if not nx.has_path(g, s, t):
		return True
	path = nx.shortest_path(g, source=s, target=t)
	path_length_meters = 0
	for i in range(1, len(path)):
		path_length_meters += geopy.distance.distance(geopy.Point(clusters[path[i - 1]].get_coordinates()),\
	                                        geopy.Point(clusters[path[i]].get_coordinates())).meters
	if path_length_meters >= alpha * edge_distance:
		return True
	return False