haversine

MySQL geospacial search using haversine formula returns null on same point

删除回忆录丶 提交于 2019-12-06 07:56:02
I'm trying to implement a geospacial search in a php application. Currently, I'm using the following query to find points within 10km of a given latitude and longitude: SELECT * FROM ( SELECT *, (6378.1 * ACOS( COS(RADIANS(48.856614)) * COS(RADIANS(latitude)) * COS(RADIANS(2.3522219) - RADIANS(longitude)) + SIN(RADIANS(48.856614)) * SIN(RADIANS(latitude))) ) AS distance FROM `destinations_info` WHERE latitude BETWEEN 48.856614 - (10 / 69) AND 48.856614 + (10 / 69) AND longitude BETWEEN 2.3522219 - (10 / (69 * COS(RADIANS(48.856614)))) AND 2.3522219 + (10 / (69 * COS(RADIANS(48.856614)))) ) d

Join operation in Haversine formula

与世无争的帅哥 提交于 2019-12-04 13:33:23
问题 I am implementing Haversine formula in PHP as the follows $result=mysqli_query($mysqli,"SELECT *,( 6371 * acos( cos( radians({$lat}) ) * cos( radians( `latitude` ) ) * cos( radians( `longitude` ) -radians({$lon}) ) +sin( radians({$lat}) ) * sin( radians( `latitude` ) ) ) ) AS distance FROM `places` HAVING distance <= {$radius} ORDER BY distance ASC") or die(mysqli_error($mysqli)); And Inside the Haversine fetch loop, I have the query that iterates through the results of haversine to select

Spring Query: Haversine formula with pageable

心不动则不痛 提交于 2019-12-04 11:25:16
问题 I'm trying to use the Haversine formula to find entities near to a location in a Spring Data JPA Query with Pageable but I dont get it done. My first approach looks like this @Query("SELECT m, (6371 * acos(cos(radians(:latitude)) * cos(radians(m.latitude)) * cos(radians(m.longitude) - radians(:longitude)) + sin(radians(:latitude)) * sin(radians(m.latitude)))) as dist FROM Entity m WHERE dist < :distance ORDER BY dist DESC") public List<Entity> findEntitiesByLocation(@Param("latitude") final

Pairwise haversine distance calculation

妖精的绣舞 提交于 2019-12-04 09:58:36
I have two arrays with lat and long. I want to calculate distance between every pair of lat and long with every other pair of lat and long in the array. Here are my two arrays. lat_array array([ 0.33356456, 0.33355585, 0.33355585, 0.33401788, 0.33370132, 0.33370132, 0.33370132, 0.33371075, 0.33371075, 0.33370132, 0.33370132, 0.33370132, 0.33356488, 0.33356488, 0.33370132, 0.33370132, 0.33370132, 0.33401788, 0.33362632, 0.33362632, 0.33364007, 0.33370132, 0.33401788, 0.33401788, 0.33358399, 0.33358399, 0.33358399, 0.33370132, 0.33370132, 0.33362632, 0.33370132, 0.33370132, 0.33370132, 0

Join operation in Haversine formula

隐身守侯 提交于 2019-12-03 09:13:59
I am implementing Haversine formula in PHP as the follows $result=mysqli_query($mysqli,"SELECT *,( 6371 * acos( cos( radians({$lat}) ) * cos( radians( `latitude` ) ) * cos( radians( `longitude` ) -radians({$lon}) ) +sin( radians({$lat}) ) * sin( radians( `latitude` ) ) ) ) AS distance FROM `places` HAVING distance <= {$radius} ORDER BY distance ASC") or die(mysqli_error($mysqli)); And Inside the Haversine fetch loop, I have the query that iterates through the results of haversine to select records that matches the IDs returned by the haversine formula. The Query is as follows. while($row =

How to transform a distance from degrees to metres?

瘦欲@ 提交于 2019-12-03 09:03:11
问题 I'm using OpenLayers with an ordinary mercator map and I'm trying to sample a bounding box by finding a grid of points in latlong. The bbox is expressed in latlon, e.g. 48.1388,-15.3616,55.2057,-3.9359 I can define a distance in degrees (e.g. x: 2.5, y: 2.4) and work out the points from there. But I'd like to express this distance in metres (e.g. 50000) in order to relate it to the user mindset (people understand metres, not degrees). How can I convert this distance? I know how to reproject a

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

元气小坏坏 提交于 2019-12-03 06:33:04
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 the distance between two location coordinates. Below is the equation I found: import math def distance

Python calculate lots of distances quickly

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 04:06:51
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,cutoff_km=0): below_cut = [] counter = 0 for x in lower_triangle_mat(points): dist_km = vincenty(x[0]

Querying MySQL for latitude and longitude coordinates that are within a given mile radius

一个人想着一个人 提交于 2019-12-03 03:58:23
I currently have a MySQL table that is structured as follows: id name lon lat ----- ----- ----------- ----------- 1 Mark -76.316528 40.036027 2 John -95.995102 41.25716 3 Paul -82.337036 29.645095 4 Dave -82.337036 29.645095 5 Chris -76.316528 40.036027 The way I currently query the DB to see if a user's location is within a certain mile radius of a given location is by doing this. function Haversine($lat_from, $lon_from, $lat_to, $lon_to) { $radius = 6371000; $delta_lat = deg2rad($lat_to-$lat_from); $delta_lon = deg2rad($lon_to-$lon_from); $a = sin($delta_lat/2) * sin($delta_lat/2) + cos

Calculate distance between 2 lat longs

末鹿安然 提交于 2019-12-02 08:30:18
问题 I have 4 columns in my data frame lat1,long1...lat2,long2. I need to calculate distance between these pairs. I am trying to use Distm function. When I try to use distm (c(mydata2$lst_upd_longitude,mydata2$lst_upd_latitude), c(mydata2$long,mydata2$lat), fun = distHaversine) R throws up an error "Error in .pointsToMatrix(x) : Wrong length for a vector, should be 2" For now I am using the below code to calculate distance for every point. But I am sure there should be a better solution. Also this