I have some contour lines in raster format, I want to convert them vector. I tried with QGIS (version 3.4.6) I got the vector form. enter image description here But when I tried to select the contour lines to put the actual values those lines represent, I noticed that these lines are formed by rectangles as shown below. enter image description here Now the problem is I can't select the entire contour and put the required values. How can I get a line instead of these?

  • 1
    Buffer them, then debuffer them - or manually retrace them. Vectorizing contour lines is a pain in the... behind. – Erik Sep 3 '19 at 9:09
  • @Erik. what do you mean by buffer and debuffer? Can you elaborate? I'm new to this – bibinwilson Sep 3 '19 at 9:11
  • Create a positive buffer, then create a negative buffer. – Erik Sep 3 '19 at 9:19
  1. Use the Identify tool to click on one of the large polygons between contour lines. Find out what value this polygon has for its elevation value. It's probably NULL, but it might be 0 or 9999 or some other value that represents nodata.

  2. Next, use the Select by Value tool to select all the polygons with that elevation value. This should select all the large polygons.

    enter image description here

  3. Use the Delete holes tool to fill the hole in the center of each polygon.

  4. Use the Polygons to lines tool to convert the selected polygons into lines. Be sure to check the box for "selected features only."

Now you should have a line that represents each contour, with a slight offset towards the inner edge of the ring. The amount of offset is the width of 1-2 "pixels" or grid cells of the original raster.

Note: if that slight offset is unacceptable, skip step 3 (delete holes). Step 4 will give you a pair of lines for each contour. Now you need a way to fill in "centerlines" between the pair of lines. See this question: "Average" of two lines. There are a few tools that supposedly do this, including the HCMGIS plugin and the GRASS tool v.centerline. (I couldn't get the centerline tool in HCMGIS to work, and my version of QGIS seems to be missing v.centerline. But perhaps you will have better luck.)

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.