Skip to content

Instantly share code, notes, and snippets.

@pigreco
Created March 19, 2021 12:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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 19, 2021

image

@pigreco
Copy link
Author

pigreco commented Mar 19, 2021

overlay_nearest(
map_akeys( 
with_variable('liv',array('linea','poligoni','edifici'),
with_variable('indice',
array_find(
array_foreach(@liv,
distance(
overlay_nearest(@element,$geometry)[0],
$geometry)),
array_sort(array_foreach(@liv,
distance(
overlay_nearest(@element,$geometry)[0],
$geometry)))[0]),
map(@liv[@indice],
array_sort(array_foreach(@liv,
distance(
overlay_nearest(@element,$geometry)[0],
$geometry)))[0])
)))[0],"name")[0]

image

@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