Create an image from Geometry and label vertices

Topics: SharpMap v2.0
Mar 1, 2012 at 6: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?

Cheers

Dan

Coordinator
Mar 1, 2012 at 11:47 AM

Hello Dan, are you really using SharpMap v2 from code.google.com/p/sharpmapv2?

Mar 1, 2012 at 12:02 PM

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

Mar 1, 2012 at 12: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 11:34 AM

Any advice on the labeling?

Coordinator
Mar 5, 2012 at 12:08 PM
Edited Mar 5, 2012 at 12: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:

s.th 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));

fdt.BeginLoad();
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);
 }
}

fdt.EndLoad();

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