Product: MapXtreme 2004/2005
Version: 6.0, 6.1, 6.2, 6.5
Platform: Not Platform Related
Category: Data Access
Summary:
Adding a Shape file as a layer on the map.
Question:
How can a Shape file be added as a layer on the map?
Answer:
Here's an example:
C# Code:
TableInfoShapefile ti = new TableInfoShapefile("EsriShape");
ti.TablePath = @"c:\temp\usa_region.shp";
MapInfo.Geometry.CoordSysFactory CSysFactory = Session.Current.CoordSysFactory;
MapInfo.Geometry.CoordSys coordSys = CSysFactory.CreateCoordSys("mapinfo:coordsys 1.0");
ti.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(coordSys));
ti.Columns.Add(ColumnFactory.CreateStringColumn("State", 2));
ti.Columns.Add(ColumnFactory.CreateStringColumn("State_name", 20));
ti.DefaultStyle = new MapInfo.Styles.AreaStyle(
new MapInfo.Styles.SimpleLineStyle(new MapInfo.Styles.LineWidth(2.0, MapInfo.Styles.LineWidthUnit.Pixel), (int)MapInfo.Styles.PatternStyle.Solid, Color.Red),
new MapInfo.Styles.SimpleInterior((int)MapInfo.Styles.PatternStyle.Cross, Color.Red, Color.White));
Table table = Session.Current.Catalog.OpenTable(ti);
MapTableLoader tl = new MapTableLoader(table);
mapControl1.Map.Load(tl);
VB.NET Code:
Dim conn As MapInfo.Data.MIConnection = New MapInfo.Data.MIConnection
conn.Open()
Dim ti As MapInfo.Data.TableInfoShapefile = New MapInfo.Data.TableInfoShapefile("EsriShape")
ti.TablePath = "c:\temp\usa_region.shp"
Dim CSysFactory As MapInfo.Geometry.CoordSysFactory = MapInfo.Engine.Session.Current.CoordSysFactory
Dim coordSys As MapInfo.Geometry.CoordSys = CSysFactory.CreateCoordSys("mapinfo:coordsys 1.0")
ti.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(coordSys))
ti.Columns.Add(ColumnFactory.CreateStringColumn("State", 2))
ti.Columns.Add(ColumnFactory.CreateStringColumn("State_name", 20))
ti.DefaultStyle = New MapInfo.Styles.AreaStyle(New MapInfo.Styles.SimpleLineStyle(New MapInfo.Styles.LineWidth(2.0, MapInfo.Styles.LineWidthUnit.Pixel), MapInfo.Styles.PatternStyle.Solid, Color.Red), New MapInfo.Styles.SimpleInterior(MapInfo.Styles.PatternStyle.Cross, Color.Red, Color.White))
Dim table As MapInfo.Data.Table = MapInfo.Engine.Session.Current.Catalog.OpenTable(ti)
Dim tl As MapTableLoader = New MapTableLoader(table)
MapControl1.Map.Load(tl)
Note: Writing TAB files for Shapefile tables is currently not supported. Calling TableInfo.WriteTabFile WILL throw an exception.
Last Modified:
|