4

I have a baselayer (.shp file), with bathymetric contours. I want to measure the distance from each grid square in a grid, to the nearest nominated depth (so was hoping to have a way to also nomate specifically to -120 m in the .shp file).

I generally have a basic understanding of the functions of QGIS, but have absolutely no idea where to start.

I'm using QGIS v3.2.1

I have tried the below answer from Kazuhito, but appear to be getting scores that are UTM figures. I've attached photos of where I am at now.

How the map looks when coloured by "distance" scores. i.e. not a true reflection of any distance to the 100 m contour.

The script I used

  • Thanks for the update, Joe. I am probably mistaken but the look of the picture shows the 100m layer (contour line shape) is in edit mode. Does it mean you are running the Field Calculator on this line attribute table? You need to do it on Grid layer attribute table. – Kazuhito Nov 18 '18 at 22:28
  • No problems, thanks for responding so soon. No, I did that in a desperate troubleshooting attempt, I thought perhaps they both needed to be in edit mode for the calculation to work. – Joe Nov 19 '18 at 2:13
3

With a simple test case:

enter image description here

An expression below calculated the shortest distance between each grid center to the contour at 3200m.

length(
 shortest_line(
    centroid($geometry), 
    closest_point(geometry(get_feature('Contours', 'ELEV', '3200')), $geometry)))

However, this example may be too simplistic. Please let me know if this expression works for your real case.

enter image description here

  • I couldn't quite get this to output a sensible score the way it did for you. Please see edits for my attempt. – Joe Nov 18 '18 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.