version 1.1 draw line two point or multipoint

Topics: SharpMap v0.9 / v1.x
Mar 25, 2014 at 4:59 PM
you can have a working example on how to draw a line between two points or more points?
thanks
Editor
Mar 26, 2014 at 2:30 PM
set the mapbox active tool to drawline like this.

MapBox.ActiveTool = MapBox.Tools.DrawLine;

Handle the on geometry defined event of the mapbox to get the geometry that is drawn by the user.
Mar 26, 2014 at 4:52 PM
Robert_Smart wrote:
set the mapbox active tool to drawline like this.

MapBox.ActiveTool = MapBox.Tools.DrawLine;

Handle the on geometry defined event of the mapbox to get the geometry that is drawn by the user.
Hi tanks for reply

no i have
Dim A As New NetTopologySuite.Geometries.Point(MappaShape.Map.Layers("aaaaa").Envelope.Centre.CoordinateValue)
Dim B As New NetTopologySuite.Geometries.Point(MappaShape.Map.Layers("bbbbb").Envelope.Centre.CoordinateValue)
how to draw a line between A and B?
thanks
Developer
Mar 26, 2014 at 5:30 PM
Don't forget that Sharpmap is based on layers, so if you want to add any geometry, you must to add it to a vector layer.

It's quite easy, first you must to create your whatever geometry, then:
var provider = new GeometryProvider(yourgeometry);
var layer = new VectoryLayer("mylayer", provider);

map.Layers.Add(layer);
you can add several geometries to the same provider, even at a later point, this way:
provider.Geometries.Add(yourgeometry);
Mar 26, 2014 at 5:47 PM
I'm sorry I have not given all my code

Dim A As New NetTopologySuite.Geometries.Point(MappaShape.Map.Layers("aaaaa").Envelope.Centre.CoordinateValue)
Dim B As New NetTopologySuite.Geometries.Point(MappaShape.Map.Layers("bbbbb").Envelope.Centre.CoordinateValue)

Dim coLineCoords(2) As NetTopologySuite.Geometries.Point
coLineCoords(1) = New NetTopologySuite.Geometries.Point(MappaShape.Map.Layers("aaaaa").Envelope.Centre.CoordinateValue)
coLineCoords(2) = New NetTopologySuite.Geometries.Point(MappaShape.Map.Layers("bbbbb").Envelope.Centre.CoordinateValue)

Dim provider As New SharpMap.Data.Providers.GeometryProvider(coLineCoords)
Dim vl As SharpMap.Layers.VectorLayer = New VectorLayer("mylayer")
        vl.Style = New SharpMap.Styles.VectorStyle()
        vl.DataSource = provider
        vl.Style.Symbol = New Bitmap(My.Resources.ReportingPoint)
        vl.Style.SymbolScale = 0.4F
        vl.Style.Fill = New System.Drawing.SolidBrush(Color.Green)
        vl.Style.EnableOutline = True
        vl.Style.Line = New Pen(Color.Black, 1)
        vl.Style.Line.DashPattern = New Single() {4.0F, 2.0F}
        vl.Style.Line.Width = 4
        vl.Style.Outline.Brush = Brushes.Blue
        vl.Style.Outline.Width = 5

this sample draw point, not line from point a and point B

where is the error?

thanks
Developer
Mar 26, 2014 at 6:04 PM
Points and lines are simply different kind of geometries. To construct a line you must use this:
var lineGeometry = new NetTopologySuite.Geometries.LineString(new[]{coordinate1, coordinate2..., coordinateN);