4

I have a vector contour data(polyline). I want to add values to each contour lines. Means I want to digitize my contour lines with proper values. Those values are with me in a paper. I'm adding those (z values) in the "id" column in the attribute table after selecting each line separately. it's taking a lot of time since there are around 20000 lines. Actually I created these contours after digitizing my raster map. (raster to vector conversion after scanning those maps)

Is there any way to add values automatically in between lines, if I select two extreme lines (contour is varying by an interval of 1 unit) or is it possible to create a GUI like that, or can I program like that in QGIS?

I'm new to this.

enter image description here

I'm adding my contour values to the "id" table.

Is there any way to program for this in pyqgis or any other way to do it?

2
3

I would suggest Add autoincremental field tool in the QGIS Processing Toolbox > Vector table.

[Step 1] Draw a dummy line

Create a new line shapefile (in this example I have created a Lines layer, with only one line, which starts at the lowest point and ends at the highest point [a1]. [a2]. I have an id field, called fid (and it has only 1 line; i.e. "fid"= 1).

[Step 1.5] Choose contours which intersects the dummy line

enter image description here

(Expression)

intersects($geometry, geometry(get_feature('Lines', 'fid', '1')))

This expression returns new layer Matching features

[Step 2] Start Add autoincremental field tool

enter image description here

Make sure that the Input layer is your [Edit] selected contour layer, not the dummy line layer. Start value (1 m in the above example) should be the height of the first contour line it intersects.

(Expression)...[a3]

line_locate_point(geometry:=geometry(get_feature('Lines', 'fid', '1')),
 point:= intersection($geometry, geometry(get_feature('Lines', 'fid', '1'))))

[Step 3]

Open the attribute table of newly created Incremented layer and check the AUTO field. It seems your contour interval is 1, so you would not need further calculation. (If interval is 10m, then use the Field Calculator to multiply 10).

enter image description here

[Step 4] Repeat this process to cover whole area, then merge all output layers.


[a1] If you have already drawn the dummy line starting from the mountain top, then change the Sorting to descending. (Just tick off Sort ascending checkbox).

[a2] This line does not have to be straight.

[a3] This is just calculating the distance of intersecting contours, from the starting point of the line (along the line).

6
  • Thank you so much. I'm very thankful for your efforts. For the selected lines, the contour is increasing perfectly. But the new Incremented layer is considering the entire "contour" shapefile and for the entire contour lines, it's randomly giving values after the "Lines" selected contours. Can you please help? (means it's giving values to all the lines(20000 lines) – bibinwilson Nov 2 '19 at 12:31
  • 1
    @bibinwilson I should have been more careful...my apologies. Added an intermediate step Step 1.5 to select contours before the main process. Hope you don't mind increased burden. – Kazuhito Nov 2 '19 at 13:24
  • Thank you so much........... You are lifesaver.... Thank you... Thank you.... Thank you.... – bibinwilson Nov 2 '19 at 13:46
  • ? I was trying to implement it using modeler. But I can't do Extract by Expression since it can't take 2 inputs. So tried with join attributes. But autoincrement is giving values randomly. Can you kindly give any suggestion? – bibinwilson Nov 10 '19 at 7:56
  • Hi @bibinwilson I see the other post of yours and am aware my answer had not brought you to the goal. (I am sorry). As Gabriel De Luca has extended his help, rest assured you are in good hands. – Kazuhito Nov 10 '19 at 8:41
2

I could be wrong about the success of this approach, but I would think something like this would work:

  1. Identify an area of the map where contours are of even slope, ie they evenly spaced apart.

  2. Create a new line layer with just the boundary contours and give them their correct values

  3. Interpolate a grid with these boundary contours. Because they are evenly spaced, you should get a generally good surface. This may be a mess in some areas.

  4. Drape the contours to the grid.

  5. Round the values of the contour to an integer. You final output should be "good enough".

You can increase the resolution of the grid by feeding the interpolation method more contours.

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.