# Tag Info

85

Just look at the path on the sphere. Here it is in Google Earth: The path on your map is strongly curved because your map uses a projection with lots of distortion. (The distortion grows without bound towards the poles and this path is getting close to the north pole.) Edit The distortion is necessary to explain the curvature of this geodesic on the ...

60

In short, the distance can be in error up to roughly 22km or 0.3%, depending on the points in question. That is: The error can be expressed in several natural, useful ways, such as (i) (residual) error, equal to the difference between the two calculated distances (in kilometers), and (ii) relative error, equal to the difference divided by the "correct" (...

40

The problem is indicated by the word "well-conditioned." It's an issue of computer arithmetic, not mathematics. Here are the basic facts to consider: One radian on the earth spans almost 10^7 meters. The cosine function for arguments x near 0 is approximately equal to 1 - x^2/2. Double-precision floating point has about 15 decimal digits of precision. ...

29

This is tricky for two reasons: first, limiting the points to a circle instead of a square; second, accounting for distortions in the distance calculations. Many GISes include capabilities that automatically and transparently handle both complications. However, the tags here suggest that a GIS-independent description of an algorithm may be desirable. To ...

25

After some looking around at Wikipedia and the same question/answer at StackOverflow, I figured I would take a stab at it, and try to fill in the gaps. First off, Not sure where you got the output, but it appears to be wrong. I plotted the points in ArcMap, buffered them to the distances specified, ran intersect to on the buffers, and then captured the ...

21

I investigated exactly this question 20 years ago when designing a desktop GIS. We needed to find point-to-point distances interactively; our target was to do the computations in less than 1/2 second for thousands of points. Testing (on a 25 MHz 486 PC!) showed that we could compute all the distances, exactly as you describe (with the simple obvious ...

21

In this projection (Google Mercator), that's what the great circle arc between those two places looks like.

18

This is a perfect task for the linear referencing capabilities in ArcGIS. See the help for Locating Features Along Routes and probe from there. The tools include the ability to turn a layer of points near a route (the river reaches) into "point event" descriptors, which name the route (the reach) and the distance from the beginning of the route. That's ...

18

Using the Pythagorean formula on positions given in latitude and longitude makes as little sense as, say, computing the area of a circle using the formula for a square: although it produces a number, there is no reason to suppose it ought to work. Although at small scales any smooth surface looks like a plane, the accuracy of the Pythagorean formula depends ...

17

This is terrible code for general-purpose use because it can give erroneous results or even fail altogether for short distances. Use the Haversine Formula instead. (The formula on which your code is based converts two points on the sphere (not an ellipse) into their 3D Cartesian coordinates (xa,ya,za) and (xb,yb,zb) on the unit sphere and forms their dot ...

17

First, a little background to indicate why this is not a hard problem. The flow through a river guarantees that its segments, if correctly digitized, can always be oriented to form a directed acyclic graph (DAG). In turn, a graph can be linearly ordered if and only if it is a DAG, using a technique known as a topological sort. Topological sorting is fast: ...

16

Yes, you will get these kinds of errors with a global Mercator projection: it is accurate at the equator and the distortion increases exponentially with latitude away from the equator. The distance distortion is exactly 2 (100%) at 60 degrees latitude. At your test latitudes (64.14 degrees) I compute a distortion of 2.294, exactly agreeing with the ratio ...

16

You need to reference your table twice, giving it different aliases: SELECT ST_Distance(a.geom, b.geom) FROM points_table a, points_table b WHERE a.id='x' AND b.id='y';

15

I would recommend checking out: Spherical: http://www.movable-type.co.uk/scripts/latlong.html Great-Circle: http://www.movable-type.co.uk/scripts/gis-faq-5.1.html

15

WGS-what? WGS-84? Depending on what accuracy you need, you may need to know a lot more information - my guess is that's why you've been down voted, though no-one bothered to leave a comment saying why. Here are two ways: Inaccurate, but probably 'good enough' One degree of latitude is approximately 10001.965729/90 kilometres (distance from the equator ...

15

First, rasterize your vector layer. You can do it using Rasterize under Raster menu. Before rasterizing, I'd recommend to create an additional field and fill it with '1' and then select this field when rasterizing. Second, Raster\Analysis\Proximity Note that you should have GDALTools turned on in plugins.

15

Mapperz's answer is invalid. Sinus must be calculated from latitude and NOT from longitude. So corect SQL statement is: SELECT id, ( 3959 * acos ( cos ( radians(78.3232) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(65.3234) ) + sin ( radians(78.3232) ) * sin( radians( lat ) ) ) ) AS distance FROM ...

14

A fast and informative way is to create a distance grid based on the roads. This is usually done in a projected coordinate system, which necessarily introduces some error, but by choosing a good coordinate system the error will not be too great (and can be corrected). The following example defines a "road" as a US Interstate or US or state highway of ...

13

You are nearly there. There is a little trick which is to use Postgres's distinct operator, which will return the first match of each combination -- as you are ordering by ST_Distance, effectively it will return the closest point from each senal to each port. SELECT DISTINCT ON (senal.id) senal.id, port.id, ST_Distance(port."GEOMETRY", senal."GEOMETRY") ...

12

I'd be curious how results from this formula compare with Esri's pe.dll. (citation). A point {lat,lon} is a distance d out on the tc radial from point 1 if: lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc)) IF (cos(lat)=0) lon=lon1 // endpoint a pole ELSE lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi ENDIF This ...

12

Just a quick addition: Also, planes from Asia to US would travel almost over North Pole. In that direction, they will often use the jet stream. In the other direction they will indeed fly over/close to the poles. http://en.wikipedia.org/wiki/Jet_stream

12

ST_Distance only calculates the distance between two features "as the crow flies". pgRouting on the other hand calculates the actual distance along a network (e.g. road network). Those are two different things and it depends on your use case whether ST_Distance is sufficient or not.

12

I've explored this question recently. I think people want to know what spherical radius should I use? what is the resulting error? A reasonable metric for the quality of the approximation is the maximum absolute relative error in the great-circle distance err = |s_sphere - s_ellipsoid| / s_ellipsoid with the maximum evaluated over all possible pairs ...

11

The SQL statement that will find the closest 20 locations that are within a radius of 30 miles to the 78.3232, 65.3234 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude, and then asks for only rows where the distance value is less than 30 miles, orders the whole query by distance, and limits ...

10

You don't say what license or version you are using, but assuming you have ArcInfo, it is possible to use the "Near" geoprocessing tool to find the nearest object in the same layer. From the tool help page: The same dataset can be used as both Input Features and Near Features. When an input feature's nearest feature is itself (NEAR_DIST is 0), this ...

10

First, make sure you have an index on your geography column. It will speed up the spatial searches: CREATE INDEX geo_cities_geog_idx ON geo_cities USING GIST geog; VACUUM ANALYZE geo_cities(geog); Then, you can use ST_DWithin (with conversions from miles to metres) on a self-joined query: SELECT gc.*, ST_Distance(gc.geog, pt.geog)/1609.344 AS ...

10

According to Wikipedia, Vincenty's formula is slower but more accurate: Vincenty's formulae are two related iterative methods used in geodesy to calculate the distance between two points on the surface of a spheroid, developed by Thaddeus Vincenty (1975a) They are based on the assumption that the figure of the Earth is an oblate spheroid, and ...

10

Do a spatial join! First, set up your data frame in a projected coordinate system of your choice (whatever units you want your distances to show up in). So, say you're working in State Plane Feet, make sure all your layers are in State Plane Feet, so if they're not project them into it. From there, Right click on the points layer and click Joins & ...

10

You could use the Group Stats plugin from Plugins > Manage and Install Plugins. This calculates various data statistics for your attributes such as finding the minimum value in a group. I made an example of attributes from the data you gave: Then from the Group Stats interface, select and drag the toid field from the list into the Rows window; and repeat ...

9

Performing a Spatial Join will do this. Right click on the point layer and choose "Joins and Relates > "Join". In the Join Data dialog box, choose "Join data from another layer based on spatial location" in the drop down. Then choose the polygon layer you want joined. Then choose the radio button that says "is closest to it". (The selections are a little ...

Only top voted, non community-wiki answers of a minimum length are eligible