1

I use postgis and I want to calculate minimum bounding circle for my geometry.

My points are:

Geometry

I use ST_MinimumBoundingCircle function, but it shows the ellipse instead of a circle (see enter image description here).

The following sample is to reproduce:

select ST_Centroid(collection), ST_MinimumBoundingCircle(collection) from (
select ST_COLLECT(point) as collection from (
    select ST_SetSRID(ST_MakePoint(20.513371, 54.720205),4326) as point
    UNION ALL
    select ST_SetSRID(ST_MakePoint(20.493725, 54.717761),4326) as point
    UNION ALL
    select ST_SetSRID(ST_MakePoint(20.495189, 54.726808),4326) as point
    UNION ALL
    select ST_SetSRID(ST_MakePoint(20.501414, 54.716445),4326) as point
    UNION ALL
    select ST_SetSRID(ST_MakePoint(20.509221, 54.719836),4326) as point
    ) a
)b  

I could not understand what I did wrong.

MaSEL
  • 505
  • 1
  • 5
  • 20
  • I think it's a projection issue - the circle is in EPSG 4326, but the background map is, I guess EPSG 3857 so it is getting distorted. – mlinth Feb 08 '21 at 13:14

2 Answers2

2

You're not doing anything wrong. You might see the buffer as an ellipse because the points you used to create it are pretty far from the equator (Kaliningrad). Keep in mind that you're projecting an ellipsoid into a 2D flat structure, therefore such distortions are just normal.

WITH j (geom) AS (
  VALUES 
    ('SRID=4326;POINT(20.513371 54.720205)'),
    ('SRID=4326;POINT(20.493725 54.717761)'),
    ('SRID=4326;POINT(20.495189 54.726808)'),
    ('SRID=4326;POINT(20.501414 54.716445)'),
    ('SRID=4326;POINT(20.509221 54.719836)')
) 
SELECT ST_MinimumBoundingCircle(ST_Collect(geom::geometry)) 
FROM j;

enter image description here

But if you draw a similar buffer closer to the equator the distortion won't be so visible. See example bellow (north of Brazil):

WITH j (geom) AS (
  VALUES 
    ('SRID=4326;POINT(-56.30 1.55)'),
    ('SRID=4326;POINT(-56.63 1.14)'),
    ('SRID=4326;POINT(-55.95 0.70)'),
    ('SRID=4326;POINT(-55.57 1.38)')
) 
SELECT ST_MinimumBoundingCircle(ST_Collect(geom::geometry)) 
FROM j;

enter image description here

Further reading: Buffers (Circle) in PostGIS

Jim Jones
  • 18,404
  • 3
  • 35
  • 44
1

In order to avoid the distortion, transform to a coordinate system that represents lenghts more correctly before creating the buffer.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263