2

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.

  • 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 Dec 9 '15 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. – GeoSpatialEarth.in Aug 2 '16 at 14:11
  • @Amit, Sorry, I only have data in the US, so have never had the opportunity to try it at the equator. – Brad Mathews Aug 2 '16 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 – GeoSpatialEarth.in Aug 3 '16 at 15:13
4

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.

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.

2

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.

  • 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. – Brad Mathews Aug 2 '16 at 0:01

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.