This project has moved. For the latest updates, please go here.
This example is derivied from the Add a PostGIS layer example.

//Name of table in database
string tablename = "Roads"; 
//Name of object ID column - MUST be integer!
string idColumn = "gid";

//Initialize map object
SharpMap.Map myMap = new SharpMap.Map(new System.Drawing.Size(500,250));
//Create layer
SharpMap.Layers.VectorLayer layRoads= new SharpMap.Layers.VectorLayer("Roads");
//Set the datasource to the PostgreSQL table
layRoads.DataSource = new SharpMap.Providers.OleDbPoint(connStr, tablename, idColumn);

//Set up a road label layer
SharpMap.Layers.LabelLayer layRoadLabel = new SharpMap.Layers.LabelLayer("Road labels");
//Set the datasource to that of layRoads.
layRoadLabel.DataSource = layRoads.DataSource;
layRoadLabel.Enabled = true;
//Specifiy field that contains the label string.
layRoadLabel.LabelColumn = "RoadOfName";

//Set the label style
layRoadLabel.Style = new SharpMap.Styles.LabelStyle();
layRoadLabel.Style.ForeColor = Color.Black;
layRoadLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
layRoadLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left;
layRoadLabel.Style.VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom;
layRoadLabel.Style.Offset = new PointF(3, 3);
layRoadLabel.Style.Halo = new Pen(Color.Yellow, 2);
layRoadLabel.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
layRoadLabel.SmoothingMode = SmoothingMode.AntiAlias;
layRoadLabel.SRID = layRoads.SRID;

//Add layer to map
//Add label layer to map

//Zoom to extents
//Render map
System.Drawing.Image img = myMap.GetMap();

Last edited Aug 31, 2012 at 12:12 PM by FObermaier, version 4