there is one thing I do not understand when using the following Query in geometries which are all SRID 4326.

WITH s AS (SELECT * FROM de_sim_points_start WHERE id = 6545)
SELECT e.*, ST_Distance(e.geom, s.geom, true) as distance FROM de_sim_points_end AS e, s
WHERE ST_DWithin(e.geom, s.geom, 10000) 
AND e.parent_geometry = s.parent_geometry
ORDER BY distance

Result looks like


As far as I understand, distance results in SRID 4326 are in meters (I'm totally fine with that). So how can a point be just centimetres away from each other, when in reality they are serval meters away from each other? Image below uses point with id 14033 (orange) Plot

EDIT: New Query with accepted answer looks like this and performs as expected

WITH s AS (SELECT * FROM de_sim_points_start WHERE id = 6545)
SELECT e.*, ST_Distance(e.geom::geography, s.geom::geography) as distance FROM de_sim_points_end AS e, s
WHERE ST_DWithin(e.geom::geography, s.geom::geography, 10000)
  AND e.parent_geometry = s.parent_geometry
  AND ST_Distance(e.geom::geography, s.geom::geography) > 2000

1 Answer 1


All the measurements are always returned in the units of chosen CRS. WGS84 is defined in degrees of latitude or longitutde, thus it returns results in degrees.

If you want to obtain results in meters, you have two options:

  1. Start using geography type
  2. Reproject your data into national coordinate system defined in meters
  • Number 1 is not an option. Number 2 might be possible, but comes at a cost. Also I need these Points later for routing (start and destination)
    – Benjamin
    Dec 1, 2014 at 17:43
  • Isn't there a library or anything, that can convert between meters and degrees? BTW Backend is python based, so anything that can do the calcs in python is fine
    – Benjamin
    Dec 1, 2014 at 17:54
  • 1
    I was wrong! Casting to geography works just fine. See updated Question.
    – Benjamin
    Dec 1, 2014 at 18:14
  • By the way if you are just measuring distance between points, I strongly recommend using geometry operators instead of ST_Distance as they are much, much faster (with spatial indexes). Dec 1, 2014 at 18:24
  • my goal is to find a random point which meets the condition more than 2000m and less than 10000m away from the start point. Also ST_DWithin already uses indexes and I do not know how to use ST_DWithin for the 2000m condition, thats why I use ST_Distance with an additional WHERE statement (updated Question)
    – Benjamin
    Dec 1, 2014 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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