# Calculating the straight distance of non-straight polyline in QGIS

I have a GIS layer of bus stops (MultiLineString), which contain the paint lines that are painted on the asphalt.

The complete bus stop element is in a single MultiLine element. If I select it:

I need to know the length of the bus stop to know the total number of meters to act on the adjacent curb. Is there a method to achieve this?

I have 100+ bus stops. Some examples:

• Longest side of the fitting oriented BBOX would suffice?
– Erik
Jul 3 at 13:42
• What about Minimum Oriented Rectangle, see: gis.stackexchange.com/a/265233/16530 Jul 3 at 13:43
• Oriented minimum bounding box, but in some of your case, it will approximate the length : docs.qgis.org/3.28/en/docs/user_manual/processing_algs/qgis/… Jul 3 at 13:44
• distance between the first and last point might work too Jul 3 at 16:08
• Yes, longest side of the fitting oriented BBOX should work in my case I don't need max precision Jul 4 at 8:54

The query I was able to make with the hints in the comments above and that worked for me:

``````WITH
bbox AS (
SELECT id, ST_OrientedEnvelope(the_geom) as geom
FROM mytable
),
corners AS (
SELECT id,(ST_DumpPoints(geom)).geom AS geom
FROM bbox
),
distances AS (
SELECT a.id, ST_Distance(a.geom, b.geom) AS distance
FROM corners a, corners b
WHERE NOT ST_Equals(a.geom, b.geom) AND a.id=b.id
)

SELECT id, MAX(distance) as distance
FROM distances
GROUP BY id;
``````