Fit Ellipse

This is a general example demonstrating how use fitEllipse method for a given geometry object.

plot fit ellipse
Eccentricity 0.6801608023223963 and Angle 135.8762664794922

import matplotlib.pyplot as plt

from tathu.geometry.constants import EXAMPLE_GEOMETRY
from tathu.geometry.utils import fitEllipse

def plot(geoms):
    plt.figure()
    for g in geoms:
        y = []; x = []
        points = g.GetGeometryRef(0).GetPoints()
        for p in points:
            y.append(p[0]); x.append(p[1])
        plt.plot(x, y)
    plt.show()

geom = EXAMPLE_GEOMETRY
ellipse, eccentricity, theta = fitEllipse(geom)
print('Eccentricity {} and Angle {}'.format(eccentricity, theta))
plot([geom, ellipse])

Total running time of the script: (0 minutes 2.003 seconds)

Gallery generated by Sphinx-Gallery