12

In QGIS I have a layer that contains ellipse-like polygons as in the image. I need to convert them to ellipses. They come from a different data sources. These are all actually regular shapes that originate from ellipses. Therefore, I think, somehow, an ellipse containing all vertices can be formed. But an approximate ellipse also works for me.

enter image description here

I applied "Smooth" tool using different parameter values. But it doesn't give expected ellipses (brown polygons in the next image). And they are not bounding ellipses. If all ellipses had the same size, the "Smooth" + "Buffer" tools combination or "outer (positive) then inner(negative) buffer" could be work.

enter image description here

How can I convert them to proper (bounding) ellipses?

7
  • 1
    Do you want an ellipse that goes through the vertex points of the polygons? In which case five vertex locations are sufficient to create a unique ellipse through them using planar geometry. See "Conic through 5 points" here: geogebra.org/classic
    – Spacedman
    May 2, 2021 at 17:48
  • @Spacedman An approximate result works for me. All shapes are actually well shaped like a simplified ellipse which has 16-20-24... vertices. Therefore, somehow an ellipse containing every vertices can be formed. May 2, 2021 at 18:01
  • @CyrilMikhalchenko This is a good approach. Thank you. However, I think of using Python as a future work. May 3, 2021 at 11:39
  • 1
    +10, that's a good question and a new geo-tool could come out of it... May 5, 2021 at 18:35
  • @CyrilMikhalchenko Babel's answer almost worked for the polygons in my data. Because they all have regular shapes as in the image. But I wait for another answer fitting irregular polygons, too. Actually, I couldn't understand your solution. May 5, 2021 at 18:56

2 Answers 2

18
  1. Apply the "Oriented minimum bounding box" (see documentation)

  2. From these, create ellipses with values from the attribute table calculated in the first step:

    make_ellipse(centroid($geometry), "height"/2, "width"/2 ,"angle")
    

Screenshot: here with segements=200 for a smooth ellipse (blue):

enter image description here

12

You could try something like:

make_ellipse(
    centroid($geometry),
    bounds_width($geometry)/2,
    bounds_height($geometry)/2,
    main_angle($geometry),
    45
    )

45 is the number of segments, change that to whatever smoothness you wish.

Or alternatively if the main_angle() does not match your needs, try something like:

make_ellipse(
    centroid($geometry),
    bounds_width($geometry)/2,
    bounds_height($geometry)/2,
    main_angle(
        make_line(
            centroid($geometry),
            closest_point(centroid($geometry),$geometry)
            )
        )-90,
    45
    )

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.