How do you use DataTableProvider

Apr 23, 2008 at 7:52 PM

How do you display a point with the DataTableProvider. This code does not work (display):

Dim X As Double = 2136126
Dim Y As Double = 13754723
Dim myMap As New Map
myMap.MinimumZoom = 100
myMap.BackColor = Color.White
Dim myLayer As Layers.VectorLayer
Dim fdt As New DataTable

fdt.Columns.Add("FID", GetType(System.Int32))
fdt.Columns.Add("xCoord", GetType(System.Double))
fdt.Columns.Add("yCoord", GetType(System.Double))
fdt.Columns.Add("LblCol", GetType(System.String))
Dim dr As DataRow = fdt.NewRow
dr.Item("FID") = 1
dr.Item("xCoord") = X
dr.Item("yCoord") = Y
dr.Item("LblCol") = "Comp 1"
fdt.Rows.Add(dr)


Dim dtp As New SharpMap.Data.Providers.DataTablePoint(fdt, "FID", "xCoord", "yCoord")
myLayer = New SharpMap.Layers.VectorLayer("Comp Label Point")
myLayer.DataSource = dtp

myLayer.MinVisible = Double.Epsilon
myLayer.Style.EnableOutline = True
myLayer.Style.Enabled = True
myLayer.Style.Fill = Brushes.Red
myMap.Layers.Add(myLayer)


Dim pt As SharpMap.Geometries.Point = New SharpMap.Geometries.Point(X, Y)
myMap.Center = pt
myMap.Zoom = 100
myMap.Size = New System.Drawing.Size(Me.PictureBox1.Width, Me.PictureBox1.Height)
'myMap.ZoomToExtents()
Me.PictureBox1.Image = myMap.GetMap


' This code will display a point but can not display a label
' *****************************************************************************************************************************************
Dim pt As SharpMap.Geometries.Point = New SharpMap.Geometries.Point(X, Y)
Dim prvdr As SharpMap.Data.Providers.GeometryProvider = New SharpMap.Data.Providers.GeometryProvider(pt)
myLayer = New SharpMap.Layers.VectorLayer("Comp Point")
myLayer.DataSource = prvdr
'myLayer.Style.Sy()
myLayer.MinVisible = Double.Epsilon
myLayer.Style.EnableOutline = True
myLayer.Style.Enabled = True
myLayer.Style.Fill = Brushes.Red
myMap.Layers.Add(myLayer)
' *****************************************************************************************************************************************

May 29, 2008 at 7:57 PM
crortiz,
I am surprised that no one has answer this for you yet.. You you need to add an label layer to your code. it would be something like.

SharpMap.Layers.LabelLayer myLabel = new SharpMap.Layers.LabelLayer("Label Layer");
myLabel.DataSource = myLayer.DataSource;
myLabel.Enabled = true;
myLabel.LabelColumn = "LblCol";
myLabel.MaxVisible = 360;
myLabel.Style = new SharpMap.Styles.LabelStyle();
myLabel.Style.ForeColor = Color.Black;
myLabel.Style.Font = new Font(FontFamily.GenericSerif, 12);
myLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
myLabel.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;
myLabel.SRID = 4326;

Coordinator
May 29, 2008 at 9:39 PM
Thanks, dsjames, for the save. Things get a little hectic and these requests get dropped from time to time. We're always quite grateful when another voice from the user community steps up and shows the way.
Jun 2, 2008 at 9:23 PM
Thanks, that is just what I needed.  I did this with a shapefile and it did not dawn on me this is the same.
Jun 11, 2008 at 6:39 AM
hi guys,

I can't get the Labels to display. I'm doing something like this:


            DataTable fdt = new DataTable("fdt");

            fdt.Columns.Add("FID", typeof(System.Int32));
            fdt.Columns.Add("xCoord", typeof(System.Double));
            fdt.Columns.Add("yCoord", typeof(System.Double));
            fdt.Columns.Add("LblCol", typeof(System.String));


            DataRow dr = fdt.NewRow();
            dr["FID"] = 1;
            dr["xCoord"] = 1110;
            dr["yCoord"] = 1110;
            dr["LblCol"] = "Comp 1";

            fdt.Rows.Add(dr);

            dr = fdt.NewRow();
            dr["FID"] = 2;
            dr["xCoord"] = 101;
            dr["yCoord"] = 101;
            dr["LblCol"] = "Comp 2";

            fdt.Rows.Add(dr);


            SharpMap.Data.Providers.DataTablePoint dtp = new SharpMap.Data.Providers.DataTablePoint(fdt, "FID", "xCoord", "yCoord");
         
           


            SharpMap.Layers.LabelLayer myLabel = new SharpMap.Layers.LabelLayer("Label Layer");
            myLabel.DataSource = dtp;
            myLabel.Enabled = true;
            myLabel.LabelColumn = "LblCol";
            myLabel.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;

            SharpMap.Layers.VectorLayer myVectorLayer = new SharpMap.Layers.VectorLayer("Vector Layer");
            myVectorLayer.DataSource = dtp;

            dtp.Open();

            SharpMap.Map map = new SharpMap.Map(new Size(400, 300));


            map.Layers.Add(myVectorLayer);
            map.Layers.Add(myLabel);

            map.ZoomToExtents();
            mapImage.Map = map;
            mapImage.Map.Zoom = 1000000;
            mapImage.Refresh();


The 2 points are rendered fine. But the Labels are no where to be found.
Any thoughts on this?

Thanks in advance!

Jun 11, 2008 at 9:36 PM
Edited Jun 11, 2008 at 9:37 PM
I'm not very versed in C# but just a guess no style has been defined for your label layer.  Here is some code that I used in a VB app that displays the label.

lblLayer =

New SharpMap.Layers.LabelLayer("Comp Label")
LblLayer.DataSource = myLayer.DataSource
LblLayer.Enabled =
True
LblLayer.LabelColumn = "LblCol"

LblLayer.Style = New SharpMap.Styles.LabelStyle
LblLayer.Style.ForeColor = Color.Black
LblLayer.Style.Font =
New
Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold)
LblLayer.Style.HorizontalAlignment = Styles.LabelStyle.HorizontalAlignmentEnum.Left
LblLayer.Style.VerticalAlignment = Styles.LabelStyle.VerticalAlignmentEnum.Bottom
LblLayer.Style.Offset =
New
PointF(3, -15)
LblLayer.Style.Halo =
New
Pen(Color.White, 2)

LblLayer.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
LblLayer.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
myMap.Layers.Add(LblLayer)

 

 

 

Jun 12, 2008 at 10:38 AM
Thanks a lot crortiz.
I got it working just this morning.
I traced the problem to the DataTablePoint.cs and FeatureDataSet.cs.
My app is working fine now. =)