Geographic Information Systems Asked by ILya Kuzmin on October 3, 2021
I Need to get a midpoint from a line layer.
Property layer -> Style -> Simple symbol -> Generator geometry (line)
I have code #1:
x(line_interpolate_point($geometry, $length / 2)
this code return NULL
I have code #2:
point = $geometry.interpolate($geometry.length() / 2).asPoint()
make_line(make_point(point.x(), point.y()),
make_point( "auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony"))
this code return NULL
What is my mistake? I am using QGIS 3.8.3
Answer eurojam:
Edit code result:
make_line(
make_point(x(transform(line_interpolate_point(transform($geometry,'EPSG: my geographic','EPSG: my project')),'EPSG: my project','EPSG: my geographic')), y(transform(line_interpolate_point(transform($geometry,'EPSG: my geographic','EPSG: my project')),'EPSG: my project','EPSG: my geographic'))),
make_point( "auxiliary_storage_labeling_positionx",
"auxiliary_storage_labeling_positiony")
)
I suppose that your data CRS (linelayer) is 4326 (WGS84), so $length will result something in Meters and line_interpolate expects something in lat/lon values because your $geometry object is in WGS84. You can use a transform within your statement:
line_interpolate_point(transform($geometry,'EPSG:4326', 'EPSG:3857'),$length/2)
This will transform your line geometry first in something cartesic, so the line_interpolation will result in a valid point. At the end you have to transform your point back into your original CRS:
transform(line_interpolate_point(transform($geometry,'EPSG:4326', 'EPSG:3857'),$length/2), 'EPSG:3857', 'EPSG:4326')
Correct answer by eurojam on October 3, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP