3

I am buffering a point to create a circle in PostGIS like:

ST_Buffer(geo::geometry, .0002, 8)

However, when displaying the polygon in Bing maps it ends up a vertically oriented ellipse or elongated circle.

Since both the Geography datatype and Bing both use the WGS84 datum, this is unexpected.

4
  • 1
    Without a graphic it's hard to be sure, but this is the expected behavior (a geodetic circle should render as an ellipse in a geographic coordinate system); Web Mercator is unreliable preserving shape (it is not conformal)
    – Vince
    Commented Dec 9, 2015 at 22:08
  • Are you getting the same ellipse on equator too?? I don't think so... please check it out taking any point with latitude as 0. Commented Aug 2, 2016 at 14:11
  • @Amit, Sorry, I only have data in the US, so have never had the opportunity to try it at the equator. Commented Aug 2, 2016 at 22:50
  • Check out this image which displays buffer of 1000 km radius on equator as well as near poles. If you are getting this kind of shapes, then you are going right. geospatialearth.in/images/buffer1000.jpg Commented Aug 3, 2016 at 15:13

4 Answers 4

5

After little more research and testing I found a solution. I believe that converting from geography to geometry is what is messing it up. Geometry is a flat 2d surface, so when you draw a circle and then re-project back to WGS84, the polygon is getting stretched. rbrundritt does a better job of explaining why in his answer below.

I am using the circle as a highlight for a selected marker, so spatial accuracy was not the goal, aesthetics was.

My solution was to use a different overload of the ST_Buffer function:

geography ST_Buffer(geography g1, float radius_of_buffer_in_meters);

You cannot, unfortunately, specify the number of segments.

4

The ellipse shape is to be expected. Bing Maps uses a spherical Mercator projection to stretch the map into a nice square. As such the pixel distance between degrees of longitude increase as you approach the poles. A circle will thus look like an ellipse on a Mercator projected map, but the distance (in meters or similar units)from the center to any point on the circle will be equal, even though the pixel distance won't be. By creating circles that have equal pixel distances from the center of the circle, you are creating spatially inaccurate circles.

1
  • Yes, you are absolutely correct. I should have mentioned in my original question that I was using a circle as a kind of highlight of a selected marker so spatial accuracy was not a concern. Commented Aug 2, 2016 at 0:01
2

If you need number of segments, you could do this:

ST_Transform(ST_Buffer(ST_Transform(geo:geometry, _ST_BestSRID(geo)), buffer_in_meters, 8), 4326)

Behind the scenes, that's what geography does since ST_Buffer is a bit of a hack, not a native geography function, so it cheats and uses geometry buffer.

0

You can use below query to generate a circle.

SELECT ST_asgeojson(ST_Buffer(ST_GeographyFromText('POINT(-97.96989440917969 43.225692889144185)'), 3000)); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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