VERIFIED SOLUTION i
X

Creating line feature in MapXtreme

UPDATED: July 25, 2018


Here is the code snippet to create a line feature:
C# Code:
MapInfo.Data.TableInfo ti = MapInfo.Data.TableInfoFactory.CreateTemp("Temp");
MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);

MapInfo.Geometry.DPoint startPoint = new MapInfo.Geometry.DPoint(-100, 40);
MapInfo.Geometry.DPoint endPoint = new MapInfo.Geometry.DPoint(-70, 20);

MapInfo.Geometry.FeatureGeometry g = MapInfo.Geometry.MultiCurve.CreateLine(this.mapControl1.Map.GetDisplayCoordSys(), startPoint, endPoint); 
//set line style
MapInfo.Styles.SimpleLineStyle bl = new MapInfo.Styles.SimpleLineStyle(new MapInfo.Styles.LineWidth(3, MapInfo.Styles.LineWidthUnit.Pixel), 2); 
MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(null, bl, null, null);

MapInfo.Data.Feature f = new MapInfo.Data.Feature(g, cs);
table.InsertFeature(f);

FeatureLayer fl = new FeatureLayer(table);
this.mapControl1.Map.Layers.Add(fl);

VB.Net Code:​
Dim ti As MapInfo.Data.TableInfo = MapInfo.Data.TableInfoFactory.CreateTemp("Temp")
Dim table As MapInfo.Data.Table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti)

Dim startPoint As New MapInfo.Geometry.DPoint(-100, 40)
Dim endPoint As New MapInfo.Geometry.DPoint(-70, 20)

Dim g As MapInfo.Geometry.FeatureGeometry = MapInfo.Geometry.MultiCurve.CreateLine(Me.MapControl1.Map.GetDisplayCoordSys(), startPoint, endPoint)

'set line style
Dim bl As New MapInfo.Styles.SimpleLineStyle(New MapInfo.Styles.LineWidth(3, MapInfo.Styles.LineWidthUnit.Pixel), 2)
Dim cs As New MapInfo.Styles.CompositeStyle(Nothing, bl, Nothing, Nothing)

Dim f As New MapInfo.Data.Feature(g, cs)
table.InsertFeature(f)

Dim fl As New FeatureLayer(table)
Me.MapControl1.Map.Layers.Add(fl)


 

Downloads

  • No Downloads