Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a problem setting angled text labels with the new-style labelling dialog. The situation is this:

I have a shape file which only contains only labelling texts. This is a point layer, and it contains all information needed for the label, like text size, font etc. - while the placement of the label is steered by the cordinates of the geometry of the point, so there are no attributes containing the X and y coordinate. This is legacy data, so I have no choice in the matter - the labels aren't linked to objects in other shapefiles, they're just there by themselves, having originally made up a separate toponym layer.

If I use the old labelling mechanism, I can enter the text angle field in the appropriate place (in my data it's called TextAngle), and the text is displayed at the desired angle. But if I use the new-style labelling dialog, the text angle field in the 'position' section of the 'data defined settings' tab remains greyed out unless I set the fields 'x-coordinate' and 'y-coordinate'. Yet I don't have fields containing x and y coordinates in my data - they are implicit, being the very coordinates my data points occupy. They appear when I get info for the elements as 'derived', but they aren't in the attribute table. If I try and trick the dialog by entering something else in the 'x-coordinate' and 'y-coordinate' fields, I can enter my text angle field, but it has no effect.

Am I missing something? I'd really rather use the new-style labelling, since the buffering is nicer.

Help welcome!

share|improve this question

3 Answers 3

In fact, it's very easy to add x-ordinate and y-ordinate columns automatically to the attribute table of a point shapefile: Vector -> Geometry Tools -> Export/Add geometry columns.

share|improve this answer
    
Having tried this solution and also the one proposed by underdark I found they both work. Thanks! But I have over 1000 of these shape files. Is there a command line tool to do the same thing? –  Kay F. Jahnke May 13 '12 at 15:40

Currently it's not possible to rotate new labels without specifying the x/y position. It's one (if not the) major blocker for removing old labeling engine.

You can add explicit x and y attributes using Field Calculator $x and $y operators as a work-around.

share|improve this answer
    
Having browsed the thread you link to, I think that noone seems to make much of this problem. Yet in a point layer it is absurd to ask for x- and y-coordinates - this only makes sense in line and polygon layers. On the other hand, if the layer in question is a point layer, the x- and y-coordinate is defined and shouldn't be too hard to acquire (say I, not having looked at the code) –  Kay F. Jahnke May 13 '12 at 8:23

I found a python module to do the job. It's called shapefile.py and I found it at

http://code.google.com/p/pyshp/

Using this module, adding the x and y coordinate as attributes was quite straightforward. I wrote a little script called add_xy.py:

#! /bin/python

import sys
import shapefile

sf = shapefile.Reader(sys.argv[1])
fields=sf.fields
shapeRecs = sf.shapeRecords()
fields.append ( ['x-coord', 'F', 19, 11] )
fields.append ( ['y-coord', 'F', 19, 11] )
w = shapefile.Writer(shapefile.POINT)
for f in fields:
w.field (*f)
for r in shapeRecs:
    r.record.extend(r.shape.points[0])
for r in shapeRecs:
    w.point ( *r.shape.points[0] )
for r in shapeRecs:
    w.record ( *r.record )
w.save(sys.argv[2])

I called this like

python add_xy.py input.shp output

Now when I load output.shp into QGIS, I have the additional coordinate fields and I can use the angle defined in the data. Bit of a circuitious route, but it works :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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