ELSE ST_ClosestPoint(%3$L, coalesce(lp.geom, p.geom)) END
ELSE
CASE
WHEN ST_DWithin(ST_ClosestPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), coalesce(lp.geom, p.geom)), ST_StartPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154)), %5$s)
THEN st_lineinterpolatepoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), 0.1/st_length(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154)))
WHEN ST_DWithin(ST_ClosestPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), coalesce(lp.geom, p.geom)), ST_EndPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154)), %5$s)
THEN st_lineinterpolatepoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), 1-(0.1/st_length(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154))))
ELSE ST_ClosestPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), coalesce(lp.geom, p.geom)) END
WHEN ST_DWithin(ST_ClosestPoint(%3$L, coalesce(lp.geom, p.geom)), ST_StartPoint(%3$L), %5$s)
OR ST_DWithin(ST_ClosestPoint(%3$L, coalesce(lp.geom, p.geom)), ST_EndPoint(%3$L), %5$s) THEN
CASE
WHEN ST_DWithin(ST_ClosestPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), coalesce(lp.geom, p.geom)), ST_StartPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154)), %5$s)
THEN st_lineinterpolatepoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), 0.1/st_length(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154)))
WHEN ST_DWithin(ST_ClosestPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), coalesce(lp.geom, p.geom)), ST_EndPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154)), %5$s)
THEN st_lineinterpolatepoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), 1-(0.1/st_length(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154))))
ELSE ST_ClosestPoint(ST_SetSRID(St_GeomFromGeoJSON((tp->>''geom'')), 2154), coalesce(lp.geom, p.geom)) END
ELSE ST_ClosestPoint(%3$L, coalesce(lp.geom, p.geom)) END