Skip to main content
edited body
Source Link
swiss_knight
  • 10.9k
  • 9
  • 50
  • 132

In the expression builder (QGIS 3.38) attached to the "Default" value"Default value" setting of the Attribute Form, I'd like to assign (i.e. fill/update) an attribute of the entities of a "feature" layer the name of the nearest feature in a 2 km radius of either the closest airport or the closest harbor:

enter image description here

To this end, I'm trying to use the overlay_nearest function, something like this, just to grab the idea:

array_first(
  array_sort(
    array_cat(
      overlay_nearest(
        layer:='airports',
        expression:="name",
        limit:=1,
        max_distance:=5000
      ),
      overlay_nearest(
        layer:='harbors',
        expression:="name",
        limit:=1,
        max_distance:=5000
      )
    )
  )
) 

map sample

But this code sorts the results alphabetically by their names, not by their corresponding distances to the layer's current feature.

I guess I have to aggregate in a structure like a nested array, the names with their corresponding distances to the feature of the third layer but then how to sort those based on the distance and assign the corresponding name to the feature?

I wish the overlay_nearest would have a way to expose the computed distance (because at some point, it has to be computed in the background) but that's not the case.

Does anybody have an efficient and easy-to-maintain solution to achieve that?

In the expression builder (QGIS 3.38) attached to the "Default" value setting of the Attribute Form, I'd like to assign (i.e. fill/update) an attribute of the entities of a "feature" layer the name of the nearest feature in a 2 km radius of either the closest airport or the closest harbor:

enter image description here

To this end, I'm trying to use the overlay_nearest function, something like this, just to grab the idea:

array_first(
  array_sort(
    array_cat(
      overlay_nearest(
        layer:='airports',
        expression:="name",
        limit:=1,
        max_distance:=5000
      ),
      overlay_nearest(
        layer:='harbors',
        expression:="name",
        limit:=1,
        max_distance:=5000
      )
    )
  )
) 

map sample

But this code sorts the results alphabetically by their names, not by their corresponding distances to the layer's current feature.

I guess I have to aggregate in a structure like a nested array, the names with their corresponding distances to the feature of the third layer but then how to sort those based on the distance and assign the corresponding name to the feature?

I wish the overlay_nearest would have a way to expose the computed distance (because at some point, it has to be computed in the background) but that's not the case.

Does anybody have an efficient and easy-to-maintain solution to achieve that?

In the expression builder (QGIS 3.38) attached to the "Default value" setting of the Attribute Form, I'd like to assign (i.e. fill/update) an attribute of the entities of a "feature" layer the name of the nearest feature in a 2 km radius of either the closest airport or the closest harbor:

enter image description here

To this end, I'm trying to use the overlay_nearest function, something like this, just to grab the idea:

array_first(
  array_sort(
    array_cat(
      overlay_nearest(
        layer:='airports',
        expression:="name",
        limit:=1,
        max_distance:=5000
      ),
      overlay_nearest(
        layer:='harbors',
        expression:="name",
        limit:=1,
        max_distance:=5000
      )
    )
  )
) 

map sample

But this code sorts the results alphabetically by their names, not by their corresponding distances to the layer's current feature.

I guess I have to aggregate in a structure like a nested array, the names with their corresponding distances to the feature of the third layer but then how to sort those based on the distance and assign the corresponding name to the feature?

I wish the overlay_nearest would have a way to expose the computed distance (because at some point, it has to be computed in the background) but that's not the case.

Does anybody have an efficient and easy-to-maintain solution to achieve that?

added 198 characters in body
Source Link
swiss_knight
  • 10.9k
  • 9
  • 50
  • 132

In the expression builder (QGIS 3.38) attached to the "Default" value setting of the Attribute Form, I'd like to assign (i.e. fill/update) an attribute of the entities of a "feature" layer the name of the nearest feature in a 2 km radius of either the closest airport or the closest harbor.:

enter image description here

To this end, I'm trying to use the overlay_nearest function, something like this, just to grab the idea:

array_first(
  array_sort(
    array_cat(
      overlay_nearest(
        layer:='airports',
        expression:="name",
        limit:=1,
        max_distance:=5000
      ),
      overlay_nearest(
        layer:='harbors',
        expression:="name",
        limit:=1,
        max_distance:=5000
      )
    )
  )
) 

map sample

But this code sorts the results alphabetically by their names, not by their corresponding distances to the layer's current feature.

I guess I have to aggregate in a structure like a nested array, the names with their corresponding distances to the feature of the third layer but then how to sort those based on the distance and assign the corresponding name to the feature?

I wish the overlay_nearest would have a way to expose the computed distance (because at some point, it has to be computed in the background) but that's not the case.

Does anybody have an efficient and easy-to-maintain solution to achieve that?

In the expression builder (QGIS 3.38), I'd like to assign entities of a layer the name of the nearest feature in a 2 km radius of either the closest airport or the closest harbor.

To this end, I'm trying to use the overlay_nearest function, something like this, just to grab the idea:

array_first(
  array_sort(
    array_cat(
      overlay_nearest(
        layer:='airports',
        expression:="name",
        limit:=1,
        max_distance:=5000
      ),
      overlay_nearest(
        layer:='harbors',
        expression:="name",
        limit:=1,
        max_distance:=5000
      )
    )
  )
) 

map sample

But this code sorts the results alphabetically by their names, not by their corresponding distances to the layer's current feature.

I guess I have to aggregate in a structure like a nested array, the names with their corresponding distances to the feature of the third layer but then how to sort those based on the distance and assign the corresponding name to the feature?

I wish the overlay_nearest would have a way to expose the computed distance (because at some point, it has to be computed in the background) but that's not the case.

Does anybody have an efficient and easy-to-maintain solution to achieve that?

In the expression builder (QGIS 3.38) attached to the "Default" value setting of the Attribute Form, I'd like to assign (i.e. fill/update) an attribute of the entities of a "feature" layer the name of the nearest feature in a 2 km radius of either the closest airport or the closest harbor:

enter image description here

To this end, I'm trying to use the overlay_nearest function, something like this, just to grab the idea:

array_first(
  array_sort(
    array_cat(
      overlay_nearest(
        layer:='airports',
        expression:="name",
        limit:=1,
        max_distance:=5000
      ),
      overlay_nearest(
        layer:='harbors',
        expression:="name",
        limit:=1,
        max_distance:=5000
      )
    )
  )
) 

map sample

But this code sorts the results alphabetically by their names, not by their corresponding distances to the layer's current feature.

I guess I have to aggregate in a structure like a nested array, the names with their corresponding distances to the feature of the third layer but then how to sort those based on the distance and assign the corresponding name to the feature?

I wish the overlay_nearest would have a way to expose the computed distance (because at some point, it has to be computed in the background) but that's not the case.

Does anybody have an efficient and easy-to-maintain solution to achieve that?

added 89 characters in body; edited tags; edited title
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

Get Getting the name of the closest feature from two different layers in the expression builderwith QGIS Expression

In the expression builder (QGIS 3.38), I'd like to assign entities of a layer the name of the nearest feature in a 2 km radius of either the closest airport or the closest harbor.

To this end, I'm trying to use the overlay_nearestoverlay_nearest function, something like this, just to grab the idea:

array_first(
  array_sort(
    array_cat(
      overlay_nearest(
        layer:='airports',
        expression:="name",
        limit:=1,
        max_distance:=5000
      ),
      overlay_nearest(
        layer:='harbors',
        expression:="name",
        limit:=1,
        max_distance:=5000
      )
    )
  )
) 
array_first(
  array_sort(
    array_cat(
      overlay_nearest(
        layer:='airports',
        expression:="name",
        limit:=1,
        max_distance:=5000
      ),
      overlay_nearest(
        layer:='harbors',
        expression:="name",
        limit:=1,
        max_distance:=5000
      )
    )
  )
) 

map sample

But this code sorts the results alphabetically by their names, not by their corresponding distances to the layer's current feature.

I guess I have to aggregate in a structure like a nested array, the names with their corresponding distances to the feature of the third layer but then how to sort those based on the distance and assign the corresponding name to the feature?

I wish the overlay_nearest would have a way to expose the computed distance (because at some point, it has to be computed in the background) but it's apparentlythat's not the case.

Does anybody have an efficient and easy to maintain-to-maintain solution to achieve that?

Get the name of the closest feature from two different layers in the expression builder

In the expression builder (QGIS 3.38), I'd like to assign entities of a layer the name of the nearest feature in a 2 km radius of either the closest airport or the closest harbor.

To this end, I'm trying to use the overlay_nearest function, something like this, just to grab the idea:

array_first(
  array_sort(
    array_cat(
      overlay_nearest(
        layer:='airports',
        expression:="name",
        limit:=1,
        max_distance:=5000
      ),
      overlay_nearest(
        layer:='harbors',
        expression:="name",
        limit:=1,
        max_distance:=5000
      )
    )
  )
) 

map sample

But this code sorts the results alphabetically by their names, not by their corresponding distances to the layer's current feature.

I guess I have to aggregate in a structure like a nested array, the names with their corresponding distances to the feature of the third layer but then how to sort those based on the distance and assign the corresponding name to the feature?

I wish the overlay_nearest would have a way to expose the computed distance (because at some point, it has to be computed in the background) but it's apparently not the case.

Does anybody have an efficient and easy to maintain solution to achieve that?

Getting the name of the closest feature from two different layers with QGIS Expression

In the expression builder (QGIS 3.38), I'd like to assign entities of a layer the name of the nearest feature in a 2 km radius of either the closest airport or the closest harbor.

To this end, I'm trying to use the overlay_nearest function, something like this, just to grab the idea:

array_first(
  array_sort(
    array_cat(
      overlay_nearest(
        layer:='airports',
        expression:="name",
        limit:=1,
        max_distance:=5000
      ),
      overlay_nearest(
        layer:='harbors',
        expression:="name",
        limit:=1,
        max_distance:=5000
      )
    )
  )
) 

map sample

But this code sorts the results alphabetically by their names, not by their corresponding distances to the layer's current feature.

I guess I have to aggregate in a structure like a nested array, the names with their corresponding distances to the feature of the third layer but then how to sort those based on the distance and assign the corresponding name to the feature?

I wish the overlay_nearest would have a way to expose the computed distance (because at some point, it has to be computed in the background) but that's not the case.

Does anybody have an efficient and easy-to-maintain solution to achieve that?

added 80 characters in body
Source Link
swiss_knight
  • 10.9k
  • 9
  • 50
  • 132
Loading
edited tags
Link
swiss_knight
  • 10.9k
  • 9
  • 50
  • 132
Loading
deleted 1 character in body
Source Link
swiss_knight
  • 10.9k
  • 9
  • 50
  • 132
Loading
Source Link
swiss_knight
  • 10.9k
  • 9
  • 50
  • 132
Loading