4

I am searching distance between point and nearest road (OSM data). I wrote next SQL request:

SELECT osm_id, st_astext(geometry),  ST_DISTANCE(geometry::geography, ST_SetSRID(ST_POINT(37.72308, 55.47957), 4326), true) AS dist, roads.geometry::geography <-> ST_SetSRID(ST_MakePoint(37.72308, 55.47957),4326)  as op_dist
FROM roads ORDER BY ST_SetSRID(roads.geometry, 4326)::geography <-> ST_SetSRID(ST_MakePoint(37.72308, 55.47957),4326) ASC LIMIT 1;

result dist is: 27.830223659

I added this data to the QGIS and calculated distance with the meter instrument and it's show that the distance is 34.3 meters. enter image description here

What can be wrong and why?

PostGIS 2.2

5
  • 1
    Probably you do nothing wrong but you are not measuring the same thing. ST_Distance postgis.net/docs/ST_Distance.html with geography and use_spheroid=true is measuring the distance by following the surface of the spheroid. The QGIS tool measures the Cartesian distance between the points in the coordinate system that is used on the map window of QGIS.
    – user30184
    Apr 12, 2017 at 13:20
  • 4
    @user30184 Not necessarily. QGIS measures distance according to your project settings. You can use one CRS for projection and choose a different ellipsoid (or even planimetric reference) for distance and area measuring. Apr 12, 2017 at 13:50
  • What coordinate system is your QGIS map in? It should be the same as the coordinate system in your PostGIS query Apr 12, 2017 at 15:00
  • Right @fabio.avigo. None/planimetric seems to be the default when OTF is off and when OTF is on there are 124 ellipsoids to select from. I suppose that at least 123 of the alternatives give different result than PostGIS geography.
    – user30184
    Apr 12, 2017 at 15:04
  • qgis connection string show "srid=4326" Apr 13, 2017 at 8:31

1 Answer 1

2

According to this post QGIS uses a very rough estimate to go from degrees to meters and this explains why your result is pretty far off. You are better of to project your data on a local grid (32637 would do for UTM in your case). I tested with your data and then it gives the same distance as postgis ST_Distance gives.

1
  • 1
    The linked post offers a much more complete answer. there are more options than having to reproject the data. Actually, QGIS only use degree to meters conversion in a very specific situation. Apr 14, 2017 at 16:33

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.