Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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) this postgis code

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

returns an object with ponts such as: (-64.005847 40.71.6862) That are on a huge radius and not 10 meters as requested. What am I dong wrong here?

Thanks

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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));

share|improve this answer
    
Thanks.What about this: ST_AsText(ST_Buffer(ST_MakePoint(longitude, latitude)::geography, accuracy)) . Can you tell which one is better? –  Orr Apr 8 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 at 12:16
    
what is the difference between using ST_SetSRID(ST_Point as you wrote and using ST_MakePoint directly? –  Orr Apr 8 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 at 13:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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