Skip to content

Instantly share code, notes, and snippets.

@pigreco
Created March 19, 2021 12:55
Show Gist options
  • Save pigreco/f1705597c3515c21d81c64df1b46db09 to your computer and use it in GitHub Desktop.
Save pigreco/f1705597c3515c21d81c64df1b46db09 to your computer and use it in GitHub Desktop.
here is the expression used in the Default widget
if (
distance(
overlay_nearest(
layer:='poligono',
expression:= $geometry )[0], $geometry) <
distance(
overlay_nearest(
layer:='linea',
expression:= $geometry )[0], $geometry),overlay_nearest(
layer:='poligono',
expression:= "nomePoly" )[0],
overlay_nearest(
layer:='linea',
expression:= "nomeLinea" )[0])
@pigreco
Copy link
Author

pigreco commented Mar 21, 2021

dist_layer_feature

geometry generator:

shortest_line(
overlay_nearest(layer:=
with_variable('in_layer',array('punti','line','poligono'), -- three layers
with_variable('in_dist',
        array_foreach(@in_layer,distance(overlay_nearest(@element,$geometry)[0], $geometry)),
array_get(@in_layer, array_find(@in_dist, array_min(@in_dist)))))
,expression:= $geometry )[0],
$geometry)

default widgets

overlay_nearest(layer:=
with_variable('in_layer',array('punti','line','poligono'),
with_variable('in_dist',
        array_foreach(@in_layer,distance(overlay_nearest(@element,$geometry)[0], $geometry)),
array_get(@in_layer, array_find(@in_dist, array_min(@in_dist)))))
,expression:= "name" )[0]

in collaboration with Giulio Fattori

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment