haversine

Django Sort By Calculated Field

旧巷老猫 提交于 2020-01-01 07:01:46
问题 Using the distance logic from this SO post, I'm getting back a properly-filtered set of objects with this code: class LocationManager(models.Manager): def nearby_locations(self, latitude, longitude, radius, max_results=100, use_miles=True): if use_miles: distance_unit = 3959 else: distance_unit = 6371 from django.db import connection, transaction cursor = connection.cursor() sql = """SELECT id, (%f * acos( cos( radians(%f) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(

How to write NamedQuery haversine formula in NamedQuery?

扶醉桌前 提交于 2019-12-31 04:57:06
问题 I want to run below query of haversine formula as NamedQuery but I don't know how to correct it. set @orig_lat = 37.334542; set @orig_lon = -121.890821; set @dist = 10; select *, 3956 * 2 * ASIN(SQRT(POWER(SIN((@orig_lat - abs(mlatitude)) * pi() / 180 / 2), 2) + COS(@orig_lat * pi() / 180) * COS(abs(mlatitude) * pi() / 180) * POWER(SIN((@orig_lon - mlogitude) * pi() / 180 / 2), 2))) as distance from user_gps_location having distance < @dist ORDER BY distance I run this query into mysql and it

Calculating distance and velocity between time ordered coordinates

∥☆過路亽.° 提交于 2019-12-30 03:36:11
问题 I have a csv containing locations ( latitude , longitude ) for a given user denoted by the id field, at a given time ( timestamp ). I need to calculate the distance and the velocity between a point and the successive point for each user. For example, for ID 1 I need to find the distance and velocity between point 1 and point 2, point 2 and point 3, point 3 and point 4, and so on. Given I am working with coordinates on the Earth, I understand the Haversine metric will be used for distance

Using the Haversine formula with PostgreSQL and PDO

▼魔方 西西 提交于 2019-12-30 03:29:09
问题 On my site I'm trying to get locations nearby. I'm trying to use the Haversine formula for this. http://en.wikipedia.org/wiki/Haversine_formula MySQL Great Circle Distance (Haversine formula) Calculate zipcodes in range I'm using the following query to get all the locations within a 25km radius. SELECT id, ( 6371 * acos( cos( radians(51.8391) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(4.6265) ) + sin( radians(51.8391) ) * sin( radians( lat ) ) ) ) AS distance FROM shops HAVING

Codeigniter and SQL/Haversine Formula

ぃ、小莉子 提交于 2019-12-24 05:01:49
问题 I am using Codeigniter for a project and have some locations with latitude and longitude inputs on the database. I'm trying to get points within a certain distance (50km), and attempting it with the Haversine Formula. However, on my controller and view it doesn't print out the results. What I need to know is if there's any adjustments I need to make to get the model function working. Note: The DB table has the column names location_latitude and location_longitude. //base function to compare

Is there an efficient way to group nearby locations based on longitude and latitude?

房东的猫 提交于 2019-12-24 03:45:10
问题 I'm trying to figure out a way to cluster multiple addresses based on proximity. I have latitude and longitude, which in this case is ideal, as some of the clusters would cross City/Zip boundaries. What I would have as a starting point is similar to this, but up to 10,000 rows within the table: Hospital.Addresses <- tibble(Hospital_Name = c("Massachusetts General Hospital","MGH - Blake Building","Shriners Hospitals for Children — Boston","Yale-New Haven Medical Center", "Memorial Sloan

How to filter a django model with latitude and longitude coordinates that fall within a certain radius

坚强是说给别人听的谎言 提交于 2019-12-20 14:21:32
问题 I have the following model. class Location(models.Model): name = models.CharField(max_length = 128, blank = True) address =models.CharField(max_length = 200, blank= True) latitude = models.DecimalField(max_digits=6, decimal_places=3) longitude = models.DecimalField(max_digits=6, decimal_places=3) def __unicode__(self): return self.name If my current latitude & longitude is: current_lat = 43.648 current_long = 79.404 I did some research and came across the Haversine Equation which calculates

Python calculate lots of distances quickly

大兔子大兔子 提交于 2019-12-20 14:01:43
问题 I have an input of 36,742 points which means if I wanted to calculate the lower triangle of a distance matrix (using the vincenty approximation) I would need to generate 36,742*36,741*0.5 = 1,349,974,563 distances. I want to keep the pair combinations which are within 50km of each other. My current set-up is as follows shops= [[id,lat,lon]...] def lower_triangle_mat(points): for i in range(len(shops)-1): for j in range(i+1,len(shops)): yield [shops[i],shops[j]] def return_stores_cutoff(points

Vectorize haversine distance computation along path given by list of coordinates

China☆狼群 提交于 2019-12-19 22:12:33
问题 I have a list of coordinates and can calculate a distance matrix among all points using the haversine distance metric. Coordinates come a as numpy.array of shape (n, 2) of (latitude, longitude) pairs: [[ 16.34576887 -107.90942116] [ 12.49474931 -107.76030036] [ 27.79461514 -107.98607881] ... [ 12.90258404 -107.96786569] [ -6.29109889 -107.88681145] [ -2.68531605 -107.72796034]] I can also extract the distance along the path implied by the sequence of coordinates like so: coordinates = np

Vectorize haversine distance computation along path given by list of coordinates

十年热恋 提交于 2019-12-19 22:12:12
问题 I have a list of coordinates and can calculate a distance matrix among all points using the haversine distance metric. Coordinates come a as numpy.array of shape (n, 2) of (latitude, longitude) pairs: [[ 16.34576887 -107.90942116] [ 12.49474931 -107.76030036] [ 27.79461514 -107.98607881] ... [ 12.90258404 -107.96786569] [ -6.29109889 -107.88681145] [ -2.68531605 -107.72796034]] I can also extract the distance along the path implied by the sequence of coordinates like so: coordinates = np