2

I'm trying to get my head around how ST_ShortestLine (and ST_Distance and ST_LineLocatePoint) work with different projections. The result for the shortest line differs depending on which projection I use (either 4326 or 900913).

This is the result visualised as 4326 (pink is ST_ShortestLine on geometry left at 4326, blue is ST_ShortestLine on geometry transformed to 900913)

enter image description here

And this is the same result visualised as 900913 (pink is ST_ShortestLine on geometry left at 4326, blue is ST_ShortestLine on geometry transformed to 900913)

enter image description here

As you can see, they are both the shortest line depending on the projection you visualise in. So which one is actually the correct 'shortest line' in reality? The actual thing I'm visualising here is the nearest point on a road to a bus stop – the small difference in output is actually a big deal for geographic accuracy.

If it helps, the final output for this data will be in the 900913 projection (D3.js). I'm happy to go with the transformed 900913 output, I just want to understand what's happening and which one is actually truly shortest.

Thank you!

2

As Mike says it's best to use a local projection system, as over short distances(less than 20 km) the earth is nearly flat. So measurements made on the projection plane are very precise.

Just bear in mind that for longer distances various corrections need to be made. This is due to the earth being somewhat ellipsoidal in shape.

A good way to think of if is;

If an airplane flies from London to Tokyo, it will fly the shortest distance between the two points. This 'shortest distance' will be along an arc (following the earth's curvature).

Shortest distance between two points

In the image above I used a sphere to demonstrate the idea. It's the same if you use an ellipsoid, i.e WGS84 Ellipsoid commonly used for projections.

When the airplanes path is projected it will be projected to a plane it will be as a curved line. This curved line is in fact the shortest distance between the two points and not the straight line distance between the two points on the plane projection.

This difference in the projection shortest distance(straight line) and the actual shortest distance(curved line) will be governed by some scale factor. The scale factor is highly dependent on the distance between the two points, the ellipsoid used for the projection, the projection itself and the distance of the points from the central meridian (e.g Greenwich meridian, or whichever one your local system uses.).

UTM projection

In the above image the central meridian is the one which coincides with the red line on the right. (This is an image of the UTM projection)

The scale factor here is smaller at the central meridian than at the far sides of the projection especially near the poles.

1

Also take a look at the lengths of the lines from the two projections with ST_Length, and you will see entirely different numbers, as the units of measure are different (degrees vs metres).

The more approximate physical distance-based calculation is with the spherical Mercator projection, 900913.

  • Aha, that begins to make a little more sense. So if I were to go outside and find the GPS coordinates of the nearest physical point on the road (from a bus stop) then it should match up with the blue line (900913) rather than the pink one. Correct? – Robin Hawkes Oct 13 '13 at 22:21
  • 900913 is an attempt to flatten the entire Earth to a 2D Cartesian plane, so there are some distortions (notably towards the poles). However, the Mercator projection attempts to conserve angles, which is a good thing for your requirements. – Mike T Oct 13 '13 at 23:02
  • If your calculations are within a small part of the world, use a local projection system, such as UTM or other regional projection. Accuracy always gets better with a smaller-defined projection system. – Mike T Oct 13 '13 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.