distance

Django Sort By Calculated Field

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_uni...

SQL Server distance search

I have a Microsoft SQL Server database with a table of Locations. Each location has its address and latitude and longitude coordinates. In my application, the user can input a zipcode and we return a list of close by locations. This is my approach. a) Using a zipcode DB I search the lat,lon for the zipcode (this is the center point). b)...

Distance Math in JavaScript and Implementing it in loop?

Hi! I'm having the difficulties with calculating distance between several points on the map: I have an array of coordinats where the first coord ["30.327547", "59.919676"] is the begining of the trip and other are pit stops: var J = [ ["30.327547", "59.919676"], ["29.84964", "58.737619"], ["28.250252", "57.785994"], ["3...

Objective c string formatter for distances

I have a distance as a float and I'm looking for a way to format it nicely for human readers. Ideally, I'd like it to change from m to km as it gets bigger, and to round the number nicely. Converting to miles would be a bonus. I'm sure many people have had a need for one of these and I'm hoping that there's some code floating around some...

Simple Google map distance tool for my site.

Hi There, I'm looking to develop/obtain a simple GMaps app for my site that lets the user plot two points and get the distance between the two. Here is an app that would be perfect for me. http://www.daftlogic.com/projects-google-maps-distance-calculator.htm I suppose "as the crow flies" could suffice but "suggested route" measurement...

MySQL PHP zip code comparison specifically distance

Hi everyone! I'm trying to figure out what would be the most efficient (with respect to load time) to compare the distance between one zip code (which the user provides) and a whole bunch of other zip codes (there's approximately 200 zip codes right now, but its subject to increase over time). I don't need anything exact just in the bal...

Using Numpy to find the average distance in a set of points

I have an array of points in unknown dimensional space, such as: data=numpy.array( [[ 115, 241, 314], [ 153, 413, 144], [ 535, 2986, 41445]]) and I would like to find the average euclidean distance between all points. Please note that I have over 20,000 points, so I would like to do this as efficiently as possible. Thanks. ...

Calculating the maximum distance between elements of vector in MATLAB

Let's assume that we have a vector like x = -1:0.05:1; ids = randperm(length(x)); x = x(ids(1:20)); I would like to calculate the maximum distance between the elements of x in some idiomatic way. It would be easy to just iterate over all possible combinations of x's elements but I feel like there could be a way to do it with MATLAB's ...

finding distance between two UK addresses

Hello; I need to write an application which is to calculate the estimated driving distance between two UK addresses; I think I can use Google as following: http://maps.google.com/maps/nav?q=from:London%20to:Dover However, anyone knows what is the daily/monthly limit of querying the database from a single IP address? I need to impleme...

Edit Distance in Python

I'm programming a spellcheck program in Python. I have a list of valid words (the dictionary) and I need to output a list of words from this dictionary that have an edit distance of 2 from a given invalid word. I know I need to start by generating a list with an edit distance of one from the invalid word(and then run that again on all ...

Google Maps API V3 not equal to Google Maps site on distance between two zipcodes

Hello, I have put together some code to calculate distances between two zip codes. When I enter the zip codes through the api I get a different distance than I do with the actual google maps site. Anyone have an idea on why this is occurring? A few ideas I have are: I am not centering to the zip code -> I was looking around to see how...

Distance by sea calculator, intermediate coordinates?

How do I calculate distance between 2 coordinates by sea? I also want to be able to draw a route between the two coordinates. Only solution I found so far is to split a map into pixels, identify each pixel as LAND or SEA and then try to find the path using A* algorithm. Then transform pixels to relative coordinates. There are some soft...

How to calculate short & long distance via Haversine?

Hi, I am looking for a way to calculate the distance between 2 points on the globe. We've been told to use Haversine, which works fine to calculate the shortest distance between the 2 points. Now, I'd like to calculate the "long distance" between to points. So suppose you have 2 cities, A in the west and B in the east. I want to know t...

Find cosine similarity in R

I'm wondering if there is a built in function in R that can find the cosine similarity (or cosine distance) between two arrays? Currently, I implemented my own function, but I can't help but think that R should already come with one :) Thanks, Derek ...

For each element A[i] of array A, find the closest j such that A[j] > A[i]

Hi everyone. Given : An array A[1..n] of real numbers. Goal : An array D[1..n] such that D[i] = min{ distance(i,j) : A[j] > A[i] } or some default value (like 0) when there is no higher-valued element. I would really like to use Euclidean distance here. Example : A = [-1.35, 3.03, 0.73, -0.06, 0.71, -0.21, -0.12, 1.49, 1.41, 1...

Calculate the distance between a point and a line segment on an ellipsoid (or WGS84 coordinates)?

Hi, I have a line segment AB between two WGS84 coordinates on the earth's surface (or, alternatively, on an ellipsoid), and need to calculate the distance between a point P and the point nearest to P that is on line segment AB. How can I do this? Any help is greatly appreciated. Regards, Jochen ...

SQL Average Data Based on Distance

I'm pretty new to SQL. I have a database with records based on road/milepoints. My goal is to get an average value every 52.8 ft along the road. My related table has data every 15 ft, this table of course has a foreign key relating it to the primary table. If I wanted to pull out the average value every 52.8 ft, along a given milepost, ...

What is an algorithm for minimizing some D distances between N items?

A classmate printed out a diagram of a database for class, the kind with lines representing relationships between tables. However, his lines crossed all over the place and it looked ugly. So I got to thinking about a way to move the tables to minimize the total line distance, and I couldn't think of a way to do it, other than just movin...

Fastest way to find the closest point to a given point in 3D, in Python.

So lets say I have 10,000 points in A and 10,000 points in B and want to find out the closest point in A for every B point. Currently, I simply loop through every point in B and A to find which one is closest in distance. ie. B = [(.5, 1, 1), (1, .1, 1), (1, 1, .2)] A = [(1, 1, .3), (1, 0, 1), (.4, 1, 1)] C = {} for bp in B: closest...

What webservices are available to obtain miles between two addresses?

Hi, I need to find a way to get miles (not a straight line) between two locations by passing the post addresses. If you consider the simplicity of implementation, efficiency and stability, which webservice(s) you can suggest? I would appreciate if you know any possible comparison list of relevant web-services. Thanks ...