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

Create an image from Geometry and label vertices

Topics: SharpMap v2.0
Mar 1, 2012 at 7:08 AM

Dear all,

I have been playing with the examples but cant seem to find a good way to create an image from a known geometry.

1. I have the geometry of an object ( polygon) Get this by querying a shapefile

2. I would like to create a drawing of that polygon and label the vertices. The reason i would like that is so i can embed the image in a report. Like 1,2,3,4

Any advice on how i could achieve that using sharpmap?



Mar 1, 2012 at 12:47 PM

Hello Dan, are you really using SharpMap v2 from

Mar 1, 2012 at 1:02 PM

I have downloaded the one form here. Why is that?

Mar 1, 2012 at 1:06 PM

I found some code in the win form sample that draws random polygons. That would help. Now just need to solve the labelling task

Mar 5, 2012 at 12:34 PM

Any advice on the labeling?

Mar 5, 2012 at 1:08 PM
Edited Mar 5, 2012 at 1:29 PM

Oh, sorry I thought you were all set.

You need to create a GeometryFeatureProvider that holds a geometry for each of your polygon vertices: like this:

var fdt = new FeatureDataTable();
fdt.Columns.Add(new DataColumn("Oid", typeof(uint));
fdt.Columns.Add(new DataColumn("Ring", typeof(int));
fdt.Columns.Add(new DataColumn("Index", typeof(int));

uint rowId = 0;
var vindex = 0;
foreach(var pt in polygon.ExteriorRing.Vertices)
    var row = (FeatureDataRow)fdt.LoadRow(new[] { rowId++, 0, vindex++ });
row.Geometry = new Point(pt);
 } foreach(var ring in polygon.InteriorRings) {
vindex = 0;
    foreach(var pt in ring.Vertices)
        var row = (FeatureDataRow)fdt.LoadRow(new[] { rowId++, 0, vindex++ });
row.Geometry = new Point(pt);


var p = new GeometryFeatureProvider("Vertices", fdt);
var l = new LabelLayer("Vertices");
l.DataSource = p;

l.LabelColumn = "Index";

This code has not seen a compiler :)

Hth FObermaier