+def _interpolated_position(table: SaFromClause) -> SaLabel:
+ fac = sa.cast(table.c.step, sa.Float) / (table.c.endnumber - table.c.startnumber)
+ rounded_pos = sa.func.round(table.c.position / fac) * fac
+ return sa.case(
+ (table.c.endnumber == table.c.startnumber, table.c.linegeo.ST_Centroid()),
+ else_=table.c.linegeo.ST_LineInterpolatePoint(rounded_pos)).label('centroid')
+
+
+def _locate_interpolation(table: SaFromClause, wkt: WKTElement) -> SaLabel:
+ """ Given a position, locate the closest point on the line.
+ """
+ return sa.case((table.c.linegeo.ST_GeometryType() == 'ST_LineString',
+ sa.func.ST_LineLocatePoint(table.c.linegeo, wkt)),
+ else_=0).label('position')
+
+