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

labels layer does not show up

Topics: SharpMap Project
Oct 16, 2009 at 10:19 PM


this is my first time to work with SharpMap, In my code, I am defining a FeatureDataTable to use as the data provider for the map. please see down the code I've written just to draw a simple polygon with a label. my problem is with the label layer which is not showing up. When I only add the lotsLayer to the map, every thing is ok and I can see the polygon. but, wdding the "lblLayer" to the map creates a problem where I can't see any of the two layers anymore, not even the lotsLayer.

Can anyone tell me if I am doing something wrong??


///the code

            SharpMap.Data.FeatureDataTable layerTable = new SharpMap.Data.FeatureDataTable();
            layerTable.Columns.Add("label", Type.GetType("System.String"));

            //creating a polygon from a set of points

            double Xnw = 0;
            double Ynw = 2.5;
            double Xse = 2;
            double Yse = 0;

            string lbl = "lot1";

            List<SharpMap.Geometries.Point> points = new List<SharpMap.Geometries.Point>();

            SharpMap.Geometries.Point p1 = _sharpMap.ImageToWorld(new System.Drawing.PointF((float)Xnw, (float)Ynw));
            SharpMap.Geometries.Point p2 = _sharpMap.ImageToWorld(new System.Drawing.PointF((float)Xse, (float)Ynw));
            SharpMap.Geometries.Point p3 = _sharpMap.ImageToWorld(new System.Drawing.PointF((float)Xse, (float)Yse));
            SharpMap.Geometries.Point p4 = _sharpMap.ImageToWorld(new System.Drawing.PointF((float)Xnw, (float)Yse));


            SharpMap.Geometries.LinearRing lr = new SharpMap.Geometries.LinearRing(points);
            SharpMap.Geometries.Polygon po = new SharpMap.Geometries.Polygon(lr);

            //create a FeatureDataRow and add the polygon and the label to it then add it to the table
            SharpMap.Data.FeatureDataRow dr = layerTable.NewRow();
            dr.Geometry = po;
            dr["label"] = lbl;


            //the main layer 'lotsLayer'
            SharpMap.Layers.VectorLayer lotsLayer = new SharpMap.Layers.VectorLayer("Lots");
            lotsLayer.DataSource = new SharpMap.Data.Providers.GeometryProvider(layerTable);
            lotsLayer.Style.Fill = Brushes.Aqua;
            lotsLayer.Style.EnableOutline = true;
            lotsLayer.Style.Outline = Pens.DarkGreen;

            //the labels layer 'lblLayer'
            SharpMap.Layers.LabelLayer lblLayer = new SharpMap.Layers.LabelLayer("Labels");
            lblLayer.DataSource = lotsLayer.DataSource;
            lblLayer.Enabled = true;
            lblLayer.LabelColumn = "label";
            lblLayer.Style = new SharpMap.Styles.LabelStyle();
            lblLayer.Style.CollisionDetection = true;
            lblLayer.Style.CollisionBuffer = new SizeF(20, 20);
            lblLayer.Style.ForeColor = Color.White;
            lblLayer.Style.Font = new Font(FontFamily.GenericSerif, 100);
            lblLayer.MaxVisible = 90;
            lblLayer.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
            //adding the layers to the map
            //refresh the map
                picMap.Image = _sharpMap.GetMap();
            catch { }


Thank you

Oct 17, 2009 at 12:33 PM

Hi tshunnar, at a guess there is an exception being thrown which is why you wrapped the GetMap call in a try catch. Please remove the try/catch and post the stack trace. cheers jd 



Oct 17, 2009 at 7:11 PM

you'r right, here is the stack trace and the exception message.

Stack trace:  
at SharpMap.Data.Providers.GeometryProvider.ExecuteIntersectionQuery(BoundingBox box, FeatureDataSet ds) in C:\Documents and Settings\Thaer\My Documents\Visual Studio 2005\Projects\src_09\SharpMap\Data\Providers\GeometryProvider.cs:line 188
   at SharpMap.Layers.LabelLayer.Render(Graphics g, Map map) in C:\Documents and Settings\Thaer\My Documents\Visual Studio 2005\Projects\src_09\SharpMap\Layers\LabelLayer.cs:line 255
   at SharpMap.Map.GetMap() in C:\Documents and Settings\Thaer\My Documents\Visual Studio 2005\Projects\src_09\SharpMap\Map\Map.cs:line 156
   at DeedsDataSimulator.Form1.button3_Click(Object sender, EventArgs e) in C:\Documents and Settings\Thaer\My Documents\Visual Studio 2005\Projects\DeedsDataSimulator\DeedsDataSimulator\Form1.cs:line 464

Exception Message:
"Attribute data is not supported by the GeometryProvider.


Oct 17, 2009 at 7:44 PM

Hi tshunnar - I should have caught it earlier.. you should use a GeometryFeatureProvider instead of a GeometryProvider.. and try not to use try/catch blocks as a general rule.. they hide errors and make debugging very much harder.. far better to identify the problem early and fix it.. cheers jd

Oct 17, 2009 at 10:50 PM

Thank you for the tip, you are absolutely right. However, I can't find the GeometryFeatureProvider class. I think I am using an older version, mine is 0.9 which is as I read the latest stable release. what version should I use?

Oct 17, 2009 at 11:25 PM

Use and build the trunk from the source code tab

Oct 19, 2009 at 6:57 PM

Ok, Finally it worked, thank you. But, I want to mentione how I've got it to work. First I've got the latest change set (60134) and tried to build, but I had more than 60 errors as I remember. I tried to build the SharpMap project alone since that's what I need, again I had 34 errors, and most of them where in the Utilities.WFS package. I tried to figure out if it is my fault or what is happaning, but couldn't so I started going back in the revisions and compile and reached revision 48802 which worked fine.

I just thought that this is something I should mentione. I have a file of the errors the compiler found in the SharpMap project.


Thank you for your help