[QGIS-Developer] line_substring start- and end distance

Nyall Dawson nyall.dawson at gmail.com
Thu Mar 7 17:35:14 PST 2019


On Thu, 7 Mar 2019 at 19:12, Simon Gröchenig
<simon.groechenig at salzburgresearch.at> wrote:
>
> Hi all,
>
> I have a question concerning the line_substring and recently updated $length expressions. I have a linestring (EPSG:4326) and a relative start- and end-offset (in %) and I want to create the sub linestring. The start- and end distances at the line_substring expression should be set in projection units (e.g. degrees in EPSG:4326). With the previous behaviour of $length, I multiplied the relative offset (in %) with the (planimetric) length to calculate those distances. See the following example:
>
> geom_to_wkt(line_substring( geom_from_wkt('LINESTRING(13 46, 15 46)'),  0.4* $length, 0.6* $length))  // $length => 2.0
>
> results in
>
> LINESTRING(13.8 46, 14.2 46)
>
> With the latest release (3.6.0-1 und 3.4.5-1), the $length expression correctly calculates the ellipsoidal length (https://issues.qgis.org/issues/19355) and I cannot use the above expression. Is there a way to use relative distances in the line_substring function? Or is there an alternative to calculate the planimetric length (without implementing my own function)?

Yes -- the "length(...)" function always gives a purely Cartesian
length for a geometry. Using "length($geometry)" should give you what
you want.

Nyall


More information about the QGIS-Developer mailing list