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.
[GIS] How to place labels in the top left corner of every polygon
labelingpolygonqgis
Related Solutions
You can label in a position.
Go into layer control (right click) and then select the layer you want, then the label button. IN there, is all the positioning you need.
In MapBasic, you can do the following in the MapBasic window (very easy) or you can script it:
- Loop through your objects in the layer you want to label
- get the objects x,y you want (using ObjectInfo if I remember correctly)
- then adjust the label based on that.
Code to adjust is:
Set Map Layer 1 Label Object 1
Visibility On
Anchor (0, 85) ’anchor the label at this (x,y)
You could also look at this; trial version is free, in case it works for you: evermap.com/evername.asp
Finally I find solution, works exactly as I wanted. Every time when map is rendered, the distance between the centroid of the visible part of the polygon and the edge of the visible part of the polygon will be recalculated and the label will always be positioned on the top of the visible part of the polygon
Steps:
Get the visible part of the polygon
-intersect between the geometry and the bbox(visible part of map)
Create a new geometry (point) in the centroid of the visible part of the polygon
Calculating the distance from the centroid of the visible part of polygon and the edge of the visible part of polygon ← value by which the point will move along the Y axis
Set offset for point - move the point along the Y axis
Place the label on the point
Here is the code:
<TextSymbolizer>
<Geometry> <!-- creating a point (geometry) to which the label will be attached -->
<ogc:Function name="offset"> <!-- moving a point along the y axis-->
<!-- creating a point -->
<ogc:Function name="Concatenate">
<ogc:Literal>POINT(</ogc:Literal>
<ogc:Function name="getX"> <!-- x coordinate of the new point -->
<ogc:Function name="centroid"> <!-- position the new point in the centroid of the visible part of the polygon -->
<ogc:Function name="intersection"> <!-- get the visible part of the polygon by making an intersect between bbox(of full image) and geometry -->
<ogc:Function name="env">
<ogc:Literal>wms_bbox</ogc:Literal>
</ogc:Function>
<ogc:PropertyName>geom</ogc:PropertyName>
</ogc:Function>
</ogc:Function>
</ogc:Function>
<ogc:Literal><![CDATA[ ]]></ogc:Literal>
<ogc:Function name="getY"> <!-- Y coordinate of the new point -->
<ogc:Function name="centroid">
<ogc:Function name="intersection">
<ogc:Function name="env">
<ogc:Literal>wms_bbox</ogc:Literal>
</ogc:Function>
<ogc:PropertyName>geom</ogc:PropertyName>
</ogc:Function>
</ogc:Function>
</ogc:Function>
<ogc:Literal>)</ogc:Literal>
</ogc:Function>
<!-- offset along the x axis -->
<ogc:Literal>0.0</ogc:Literal> <!-- there is no displacement along the x axis, it remains in the middle of the visible part of the polygon -->
<!-- offset along the y axis -->
<ogc:Function name="distance"> <!-- the point should be moved along the y axis to the top (distance between the centroid of the visible polygon and the boundary of the geometry of the visible polygon) -->
<ogc:Function name="centroid"> <!-- centroid of visible polygon -->
<ogc:Function name="intersection">
<ogc:Function name="env">
<ogc:Literal>wms_bbox</ogc:Literal>
</ogc:Function>
<ogc:PropertyName>geom</ogc:PropertyName>
</ogc:Function>
</ogc:Function>
<ogc:Function name="boundary"> <!-- boundary of geometry(of visible part of polygon) -->
<ogc:Function name="intersection">
<ogc:Function name="env">
<ogc:Literal>wms_bbox</ogc:Literal>
</ogc:Function>
<ogc:PropertyName>geom</ogc:PropertyName>
</ogc:Function>
</ogc:Function>
</ogc:Function>
</ogc:Function>
</Geometry>
<Label>
<ogc:PropertyName>date</ogc:PropertyName>
</Label>
Best Answer
Edited: Can be done:
Under Label options you will find the 'Placement' options.