I have a specific location: lat, lng and accuracy(meters) I want to return a geography object that will represent a polygon that surrounds this point with a given radius that will be equivalent to accuracy (I don't want to use a circle)

postgis code:

SELECT ST_AsText(CAST(ST_Buffer(ST_SetSRID(ST_Point(-74.005847, 40.716862),4326),10) As geography));

returns an object with points such as: (-64.005847 40.71.6862) That are on a huge radius and not 10 meters as requested.

What am I doing wrong here?


You need to cast it as Geography before buffering it, not after. As you have it, it's being buffered by 10 map units (degrees) instead of meters because the value returned from ST_SetSRID is a geometry.

SELECT ST_AsText(ST_Buffer(CAST(ST_SetSRID(ST_Point(-74.005847, 40.716862),4326) AS geography),10));

  • Thanks.What about this: ST_AsText(ST_Buffer(ST_MakePoint(longitude, latitude)::geography, accuracy)) . Can you tell which one is better? – Orr Apr 8 '14 at 12:07
  • @Orr Both should be equivalent, the :: notation is just a PostgreSQL specific shorthand. If you use other databases frequently you may wish to stick with CAST – Evil Genius Apr 8 '14 at 12:16
  • what is the difference between using ST_SetSRID(ST_Point as you wrote and using ST_MakePoint directly? – Orr Apr 8 '14 at 13:33
  • 1
    @Orr Honestly, I'm not sure :). I could assume that in your example the SRID is being defaulted when you cast (with ::), but I don't really know. – Evil Genius Apr 8 '14 at 13:38

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.