Sunday, 6 September 2015

symbology - Shortening line geometry using expression dialog in QGIS?


I use the "Offset Point Symbol" tool and a geometry generator symbology to create dynamic leader lines. A sample file is available at http://hub.qgis.org/issues/15201 (Add snapping for 'Offset Point Symbol' tool).



Because I need a circle symbology without fill in some projects, I want to shorten the leader lines by the radius of the cirle symbology.


enter image description here


Can anyone help me with the expression? Symbology units are in meter ('Map units').


make_line (
make_point(
$x + regexp_substr("offset", '([^,]*)'),
$y - regexp_substr("offset", '([^,]*$)')
),
$geometry
)




Based on the answer posted by underdark I've created an expression that works properly:


-- radius = 2m

difference(
make_line (
make_point(
$x + regexp_substr("offset", '([^,]*)'),
$y - regexp_substr("offset", '([^,]*$)')

),
$geometry
),
buffer(make_point(
$x + regexp_substr("offset", '([^,]*)'),
$y - regexp_substr("offset", '([^,]*$)')
), 2)
)

Answer



Your requirements seem to be similar to the requirements I had for a flow map a while ago. To shorten the lines at the start and at the end, I used geometric difference functions as shown here:




difference(
difference(
$geometry,
buffer( start_point($geometry), 10000 )
),
buffer( end_point( $geometry), 10000 )
)

enter image description here



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...