Labelling Points

Dec 6, 2010 at 1:57 PM
Edited Dec 6, 2010 at 1:58 PM

How do I add labels to points which are added from a connected Access MDB file?

I have coordinate columns X and Y and a name for the point such as "BH1" or "TP33".  How do I display the name text next to the points?

This goes back to discussion:226928

Cheers

James

Developer
Dec 6, 2010 at 3:56 PM

Load your FeatureSet with the points, make sure you set up a column in the DataTable, and that the DataTable has the name values for attributes.  Then get the FeatureLayer that is created when you do map1.Layers.Add(myFeatureSet);  It may return the layer from that method, but it may be an IMapLayer.  You will need to cast it to an IFeatureLayer in order to add labels properly since Raster and Image layers do not have that particular super power.   At that point you can create a new MapLabelLayer I think, and set it to myFeatureLayer.LabelLayer = myMapLabelLayer.  On the MapLabelLayer, you can specify the filter expression etc.  You may need to set some property on FeatureLayer like myFeatureLayer.ShowLabels = true.  I am at work and can't take a lot of time to sketch out some sample code now, but maybe after work.

Ted

Dec 6, 2010 at 4:04 PM
Thanks Ted... I'll look into it. As usual any code gratefully accepted. ;o)

Cheers

James D Nelson



On 6 December 2010 16:56, shade1974 <notifications@codeplex.com> wrote:

From: shade1974

Load your FeatureSet with the points, make sure you set up a column in the DataTable, and that the DataTable has the name values for attributes. Then get the FeatureLayer that is created when you do map1.Layers.Add(myFeatureSet); It may return the layer from that method, but it may be an IMapLayer. You will need to cast it to an IFeatureLayer in order to add labels properly since Raster and Image layers do not have that particular super power. At that point you can create a new MapLabelLayer I think, and set it to myFeatureLayer.LabelLayer = myMapLabelLayer. On the MapLabelLayer, you can specify the filter expression etc. You may need to set some property on FeatureLayer like myFeatureLayer.ShowLabels = true. I am at work and can't take a lot of time to sketch out some sample code now, but maybe after work.

Ted

Read the full discussion online.

To add a post to this discussion, reply to this email (DotSpatial@discussions.codeplex.com@discussions.codeplex.com)

To start a new discussion for this project, email DotSpatial@discussions.codeplex.com@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Dec 15, 2010 at 9:29 AM

I tried with something like this:

//...

MapLabelLayer labelLayer = new MapLabelLayer(fs);

MapPointLayer pointLayer = new MapPointLayer(fs);

Layers.Add(pointLayer);

pointLayer.LabelLayer = mapLabelLayer;

pointLayer.ShowLabels = true;

//...

What happens is that points are shown normally, but without labels.

Is there anything else needed to be put here?

Thanks,

Dragan

Dec 15, 2010 at 10:11 AM

...just to add that I defined "fs" like this:

FeatureSet fs = new FeatureSet(FeatureType.Point);

fs.Projection = KnownCoordinateSystems.Projected.UtmWgs1984.WGS1984UTMZone34N;

fs.DataTable.Columns.Add("First column");

//....

Feature figure = new Feature(new Coordinate(easting, northing));  //easting and northing have proper values
fs.DataTable.Rows.Add(new string[] {"some string"});
fs.AddFeature(figura);

//...then follows code from the previous message

 

Developer
Dec 15, 2010 at 3:02 PM

You need to indicate what should show up on the labels.  You will have to set an expression on the label category.

mapLabelLayer.Symbology.Categories[0].Expression = "[First column]";

To control which features are drawn, you can set the FilterExpression on the same category.

Ted