This project has moved and is read-only. For the latest updates, please go here.

Rendering Labels

Topics: Italiano, SharpMap Project, SharpMap v0.9 / v1.x
Oct 13, 2011 at 4:45 PM

Hi all, I have a problem with the Label Layer. 

Sometimes the label falls outside the area of a polygon, how can I do for visualizing it correctly?

Oct 14, 2011 at 8:58 AM

Can you give an example? If you raise an issue, you can attach an image.

Hth FObermaier

Oct 14, 2011 at 9:16 AM

Sure: (I don't know how to attach an image here, I'm sorry)

As you can see, the label "1;81;8" (in black) falls out the area. If you want I can post some other examples

Oct 15, 2011 at 4:30 AM

Try: labellayer.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;


Oct 15, 2011 at 1:57 PM

Nothing has changed :/ MultipartGeometryBehaviour is "Largest" but the label still falls off the polygon

Oct 15, 2011 at 7:11 PM

I just checked:

For polygonal features the label is placed at the center of the bounding box. In your case that happens to be outside of the polygon.

You have two choices:

  1. Add reference to SharpMap.Extensions, GeoApi and NetTopologySuite, create a custom theme for the label layer, that computes a point on the surface of the polygon using the InteriorPointArea class.
  2. If you use some spatial database (postgis, sqlserverspatial, spatialite, ...) you can modify the provider of your label layer to return a point on the surface ST_PointOnSurface(geom);

Hth FObermaier

Oct 16, 2011 at 10:18 AM

I'm sorry but I don't understand what I have to do. I think the way is method 1, but maybe the best way is to act in CreateLabel function, instead of "GetCentroid" can exist a function "GetCenter" that computes a point basing on the the average of the medians of the polygon

Oct 16, 2011 at 12:02 PM

Nm, maybe I get it: 
in my customTheme -> public IStyle GetStyle(FeatureDataRow fdr)

what I  have to do is modify fdr.Geometry, so the labels will be written the way I like. Right?

Oct 16, 2011 at 12:20 PM
Edited Oct 16, 2011 at 12:22 PM

yes, that is what you have to do. we will be exchanging SharpMap.Geometries with NTS.Geometries for 1.0, then this step won't be necessary anymore.

Hth FObermaier

Oct 16, 2011 at 1:16 PM

Thank you as always FObermaier