0

enter image description here

I want to auto rotate labels of polygons in Mapfile, all options that exist in MapServer refers to linear features only and not polygons. Is there any algorithm I can implement in the Mapfile to auto rotate label based on polygon rotation?

I need something similar to below image (taken from QGIS).

  • What do you mean by "rotate" in this context? To place a label at the center of a polygon and rotate it to some angle, or perhaps to make a label that follows tho borders of a polygon? – user30184 Jul 28 '16 at 5:58
  • Rotate label angle which is at center of polygon, any algorithm ? – Shiko Jul 28 '16 at 6:34
1

There isn't such option in MapServer. I suppose that for getting such option a new geometry transformation algorithm should be implemented http://www.mapserver.org/mapfile/geomtransform.html. First thing to do is to define how to measure the rotation angle. Perhaps it could be the direction of the longest side of a minimum rotated rectangle that encloses the whole geometry.

Only option that comes into my mind is to use some external tool for computing the rotation angle and write it into a new attribute in your polygon data. Then you could use the attribute based rotation as described in http://www.mapserver.org/mapfile/label.html.

Alternatively if you could generate the center lines of the polygons, or perhaps better the center lines of the minimum bounding rectangles of the polygons, into a new line vector data set you could add a new line layer just for labeling with ANGLE AUTO. If lines have no attached styles only the labels will appear on the map. There are utilities for computing the centre lines and sometimes the process is called skeletonizing.

  • I was thinking to use the extent of shape to get the width and height and change the angle based on that. while it is not exactly accurate in irregular polygons specially but is there a way to get extent in .map file? – Shiko Jul 28 '16 at 7:12
  • Regarding using external tool is not an option for me but I will check the geomtransform. – Shiko Jul 28 '16 at 7:12
  • If your data are in the database the "external tool" could simply mean a clever piece of SQL. – user30184 Jul 28 '16 at 7:18
  • My data are shape files – Shiko Jul 28 '16 at 7:18

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.