3

enter image description here

I have a set of contour lines in shape format that I have labeled in QGIS. Now I'd like to export these labels as point features with attribute data containing the text of the label, preferably in shape format. Is this possible?

Also, if there is another open source tool to do the labelling which makes it easier to create a point layer from I could use that one.

(The points will end up in MAPublisher / Illustrator)

1
  • Easy Custom Labeller can do that for you
    – Ian Turton
    Sep 26, 2017 at 20:01

4 Answers 4

3

As you need to get this in Illustrator, you might need some nice aligned text. I'm just hoping you don"t have too much or my method will be too time consuming.

>The method below can be re-used to create customized labelling for contour lines<

Let's take an example with contour_lines layer where you have stored your Z values. the Z values displayed below are automatic labels, they don't "exist", in a definite X,Y place, it's interactive, so it can't be exported. that's what this method is about, making those attributes located in space :

L1

Create a layer called crosslines (red below) with lines along where you need to get text written. As it's contour lines you're dealing with, there are best aligned when in line :

L2

Add in each layer a unique Id column (ex : UID_Z and UID_CROSS with values = $id). Open the Line intersections tool in the processing window an fill in the values like below :

L3

L4

You will obtain points where lines cross :

L5

Join this point layer and the contour_line layer with the uid_Z field :

L6

You will now have a set of point with the Z values. If you center the values on the point, you label like that :

L7

You have now a GIS layer of (X,Y) space located points on the contour lines with Z values. Export in .mif for example or any GIS format Mapublisher reads (except DXF that doesn't takes attributes) and open in Mapublisher for labeling. You might have to work on angular matters if you need rotation, but it should be easier this way. For angles, you might need to pass on to the points the crossline angle maybe. But that's another question...

7
  • This is actually a nice solution, the only problem is that I need to have the angle so that the elevation text follows the contour line.
    – oskarlin
    Sep 28, 2017 at 12:53
  • It's possible to add azimuth via the crosslines, but it's another question that has been already asked and answered :) See here for example : gis.stackexchange.com/questions/55449/…
    – gisnside
    Sep 28, 2017 at 13:06
  • That's a too complicated method in that link. I need it to be quick and relatively simple. When I looked at it I was lost immediately.
    – oskarlin
    Oct 11, 2017 at 21:24
  • Perhaps I could populate one column with the angle with angle_at_vertex(geometry, vertex) ?
    – oskarlin
    Oct 11, 2017 at 22:08
  • 1
    gisnside: gis.stackexchange.com/a/258220/9073
    – oskarlin
    Oct 12, 2017 at 8:18
2

I solved it thanks to this question and answers.

Station Lines plugin

First I used the QGIS plugin Station Lines to get small vector lines crossing my contour lines at a specified distance.

Then I added an attribute column in the Station lines layer and populated it with the angle of each line: angle_at_vertex($geometry, 0)

Then I used the Line intersections tool to create a point layer out of the intersections between my contour lines and the station lines layer.

Done!

Illustration showing labels based on the points along the line

1

You can retrieve x and y coordinates (with 'Field Calculator') for the vertex with index 0 for each lines, and with this information obtain a new shapefile.

  1. Create a field named x_start. Then populate it with this expression (from Field Calculator): $x_at(0) this function returns the x coordinate of point with index 0;
  2. create a new field named y_start. Then populate it with this expression (from Field Calculator): $y_at(0) that returns the y coordinate of of point with index 0;
  3. Than save as CSV;
  4. Open the .csv file with 'Add Delimited text layer' and set x and y, so QGIS can renders the point;
  5. Now you can export the csv file as Esri shapefile with 'Save as' from layer.
10
  • But there's no guarantee that the label is displayed around the start/end point of the poly. Sep 27, 2017 at 11:32
  • but so you can retrieve one point for each lines Sep 27, 2017 at 12:05
  • That's not what the question is about though. Sep 27, 2017 at 12:25
  • I don't really understand the answer I'm afraid.
    – oskarlin
    Sep 28, 2017 at 12:55
  • What don't you understand? The method allows to obtain coordinates of a vertex for each line, then you can covert the information as shapefile. The points that you obtain have the same attribute of the lines. the limit is that the position is not the same of the original labels, you have to move them manually. Sep 29, 2017 at 9:16
1

In QGIS 3.24 there is a processing algorithm called Extract Labels that extracts all labels as points. You can set the scale and it out puts a layer with the labels as point features and all of their styling as attributes.

https://www.qgis.org/en/site/forusers/visualchangelog324/index.html#feature-extract-labels-algorithm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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