[GIS] How to use st_dwithin with meters

postgis

I am trying to follow PostGIS ST_Buffer Radius Help to use a 50 meter distance but postgis is returning an error.

I am trying the following SQL,

SELECT id FROM table 
WHERE ST_DWithin(ST_GeogFromText('SRID=4326;POINT(-3.165356 55.926665)'), 
      geography(geometry), 50);

The hints indicated at ST_GeogFromText are,

  • function st_geogfromtext(unknown) does not exist at character 92
  • No function matches the given name and argument types. You might need to add explicit type casts.

Any help/alternatives would be appreciated.

Best Answer

As mentioned in docs:

For Geometries: The distance is specified in units defined by the spatial reference system of the geometries.

If your data is in SRID=4326 the distance you are specifying is in radians.

You either have to use ST_Transform and meter based coordinate system, or one of the two functions: ST_Distance_Sphere (faster, less accurate) or ST_Distance_Spheroid.

Related Question