Tag Info

Hot answers tagged

74

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


44

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


26

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


19

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


18

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


18

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


16

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


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

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


14

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


14

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


13

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.


12

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


12

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


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

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


11

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


10

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


10

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';


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


9

If you're only concerned with calculating distances between two points on the Earth's surface, you don't really need to work this out through maps and map projections. What you need is a formula for calculating geographical distances: http://en.wikipedia.org/wiki/Geographical_distance If you need high accuracy, look for ...


9

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


9

Since you have quite a lot of parcels that you want to test you should look for a software that uses spatial indexes for this type of calculations. And also be sure to use a method in that software that really uses the indexes. If you import your data into PostGIS you should use the ST_Dwithin function. Many people use buffer in combination with ...


8

That is a nice piece of code, but not nearly as nice as (assuming your table is in geographic coordinates, if not just remove the casts to geography) CREATE TABLE mytable_distances AS SELECT a.id, b.id, ST_Distance(a.geom::geography, b.geom::geography) as distance FROM mytable a, mytable b; Have I mentioned that spatial databases rock? They do. Oh, they ...


8

If you don't have this capability built into your GIS, but you can perform some basic grid operations ("map algebra"), there is still a solution. The calculation comes down to finding the slope of the route at every point. If you knew this exactly, with no discretization error, you would integrate the secant of the slope. On a grid, the integral is ...


8

The Mercator projection distorts at the poles http://en.wikipedia.org/wiki/Mercator_projection more info Tissot's Indicatrix So the steepness is more acute in the latter poles http://en.wikipedia.org/wiki/Tissot%27s_Indicatrix


8

For short distances, you could multiply the calculated distance with cos(lat), since the scale of the mercator projection is proportional to the secant of the latitude (secant is 1/cos). http://en.wikipedia.org/wiki/Mercator_projection#Mathematics_of_the_projection


8

Geographic distance can be described in a number of ways, depending on the surface abstraction used: For flat surface models, Euclidean distance is appropriate. For spherical surface models, you would probably use great-circle distance. For ellipsoidal surface models geodesic distance may be more appropriate, as the shortest distance between two points on ...


8

One class of solutions uses Multidimensional scaling. This addresses exactly your question: given a set of distances (often obtained among points in a high dimensional space), find an embedding in one, two, or three dimensions that preserves the distances as closely as possible. This figure is an MDS rendering of distances among all 183 top-ten Hollywood ...


8

Given a list of point locations (preferably in projected coordinates, so that distances are easy to compute), this problem can be solved with five simpler operations: Compute point-point distances. For each point i, i = 1, 2, ..., identify the indexes of those points at distances less than the buffer radius (such as 1500). Restrict those indexes to be i ...



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