1

What I'm trying to do is to label vertices of a polygon with a number and plot that number inside the polygon.

So far I extracted the vertices to a 2nd point layer. Named them correctly and plotted them. I can't find an option to restrict their position to the inside of a polygon. Is there any possibility to do this?

What I know is possible is to create two additional columns in the point layer and use them for plotting coordinates. With lots of points, it can be quite tedious to find the right plotting coordinates for each point.

Is there any cleverer way to accomplish that?

  • how about buffering the points and intersecting with the polygon and labeling the intersections. – Ian Turton Mar 19 at 8:26
  • Thank you for that idea. It is a nice thought. For me it didn't work that well because some of my vertices are quite close together while others are further apart. The buffers of the points overlap a lot with the closely centred points. In general the labels are better "centered" around the point though. I will keep it in mind :) – Steineklopfer Mar 19 at 9:11
2

From your original polygon layer make e.g. a virtual layer as a ring which is outside your polygon with:

select st_difference(st_buffer(geometry,0.002), geometry) from polygonlayer

and use this one as a blocking layer for the labels.

Result

Note: The 0.002 is in degrees, because the example image was generated with EPSG 4326. If you use a projected CRS, you should use a larger value appropriate to the units of your CRS.

  • Thank you for the quick reply :) I like this option. The command didn't work for me. I guess it is related to dimensions. It also didn't work with a bigger number instead of the 0.002). I instead created a much bigger buffer from the gui option and intersected that. Now all the labels are inside the polygon! Sometimes they are not as nicely centred on the corner like with the other option from Ian. The advantage of your option is, that it doesn't matter so much if some points are close together and others are further apart. – Steineklopfer Mar 19 at 9:08
  • Well I can't edit my comment anymore, but I meant "difference" instead of intersection. – Steineklopfer Mar 19 at 9:15
  • the 0.002 is in degrees, because the example image was generated with EPSG 4326. If you use some metric coodrinates, you should change the value. Best regards Stefan – eurojam Mar 19 at 9:15

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.