I'm trying to label the polygon boundaries instead of an anchor point. Not sure if this is possible. For this example I wish to label these numbers in the top left corner of every polygon.

I wish to label these numbers in the top left corner of every polygon


label and then uses the coordinates of the first point of the polygon

enter image description here

  • 1
    Bit complicated but i will try to work this method out! Thanks – Douwe Vermeer Nov 15 '16 at 12:45

I know you're looking for QGIS answer, but I think you could tailor the method below to suit your needs.


  1. Loop through the vertices in each polygon
  2. Assign a score for each vertex, considering the distance from the polygon centroid to the vertex, and the angle from the centroid to the vertex. You can weight the components if you want to consider distance or angle more heavily (e.g. below, I only weight distance by half). My method below calculates a score by giving positive points for distance and subtracting a penalty for being far away from 45 degrees (NW). I think it's correct, but you should check the math.
  3. Write the highest scoring points to a new feature class
  4. Use those points to label


fc = 'Parcels'
sr = arcpy.Describe(fc).spatialReference
points = []
with arcpy.da.SearchCursor(fc,'SHAPE@',spatial_reference=sr) as cursor:
    for row in cursor:
        score = 0
        for part in row[0]:
            for pnt in part:
                pnt_geom = arcpy.PointGeometry(pnt)
                dx = row[0].centroid.X - pnt.X
                dy = row[0].centroid.Y - pnt.Y
                ang = math.degrees(math.atan2(dy,dx))
                cur_score = (pnt_geom.distanceTo(row[0].centroid)*0.5) - (pnt_geom.distanceTo(row[0].centroid)*0.5 * abs(ang+45)/180)
                if cur_score > score:
                    score = cur_score
                    point = pnt_geom

enter image description here

  • Nice method, will try this out! – Douwe Vermeer Nov 15 '16 at 12:42

Edited: Can be done:

enter image description here

Under Label options you will find the 'Placement' options.

  • Tried your method but since my polygons are shaped in different ways it will not work like I want it to. Thanks anyway! – Douwe Vermeer Nov 4 '16 at 13:14

I'm not sure that is really possible with such randomly shaped polygons. I think you best bet would be to extract the centroids using 'Vector > Geometry Tools > Polygon centroids'. Then move each centroid to the appropriate location and label up this layer instead.

  • Moving the centroids didnt work out for me. Will try some more and then might get a result. Thanks! – Douwe Vermeer Nov 15 '16 at 12:45

I have the process in theory however what you are asking is not feasible always. It should be decided which is more important, to being top point or the most left? (please see attached pictureenter image description here)

Sometimes can have just one point, but sometimes we need compromise. My idea will work in some cases and not in some.

So the idea is to export all the nodes into csv. vector-geometry tools-extract nodes. save into shape. save as csv.

In excel you need to find 2 points in each group of points (one group of points is one polygon - use ID for separation), the point with the smallest X and the point with the smallest Y. If both the same point than you good, if not I would go with the mid point enter image description here. At the end you will have a point csv with all the mid or top/left points. Load back the point into qgis creating points and activate the label. https://stackoverflow.com/questions/17114443/excel-how-to-get-min-value-in-a-group


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.