Thursday, 29 December 2016

postgis - ST_Buffer returns inaccurate results with radius of over 1 meter


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?



Answer



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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...