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.

2 Answers 2


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.

  • Thank you for your answer. I used the functions above and they indeed return meters but i can only use them to calculate a distance between two latlong geometries and I need to use it to calculate distance from polygon edges. I thought of a solution with the above info, I could use st_closestPoint() to my polygon and then st_distance_sphere() which will do the trick. Problem is I am using postgis 1.4 and st_closestPoint() is unavailable. Also, I would like to use minimum code because ST_WDistance() will return a simple true/false whilst the other alternatives need more coding.
    – Antony
    Sep 3, 2012 at 15:21

You need PostGIS 1.5 or greater to have the geography type. The older versions have the ST_Distance_Spher*() functions, but as you note, they only work for points.

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.