MapXTreme 2005代码段(1)数据访问部分

1、创建表
//TableInfo
MapInfo.Data.TableInfo ti = MapInfo.Data.TableInfoFactory.CreateTemp("MyPointTable");
//Adding an IntColumn to my table.
//The style and geometry columns are already added when the TableInfo is created.
ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateIntColumn("Index"));
//Create a table from TableInfo
MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);

//Point #1
MapInfo.Geometry.Point pt = new MapInfo.Geometry.Point(this.mapControl1.Map.GetDisplayCoordSys(), -100.0995, 31.187);
MapInfo.Styles.SimpleVectorPointStyle vs = new MapInfo.Styles.SimpleVectorPointStyle();
vs.PointSize = 25;
vs.Color = Color.DarkMagenta;
MapInfo.Data.Feature ft = new MapInfo.Data.Feature(pt,vs);
table.InsertFeature(ft);

//Point #2
MapInfo.Geometry.Point pt2 = new MapInfo.Geometry.Point(this.mapControl1.Map.GetDisplayCoordSys(), -120, 40);
MapInfo.Styles.SimpleVectorPointStyle vs2 = new MapInfo.Styles.SimpleVectorPointStyle();
vs2.PointSize = 40;
vs2.Color = Color.Aqua;
MapInfo.Data.Feature ft2 = new MapInfo.Data.Feature(pt2, vs2);
table.InsertFeature(ft2);

//Adding table to the Map.
FeatureLayer fl = new FeatureLayer(table);
this.mapControl1.Map.Layers.Add(fl);

//Writing table to a .Tab file
MapInfo.Data.TableInfoNative native = (MapInfo.Data.TableInfoNative)MapInfo.Data.TableInfoFactory.CreateFromFeatureCollection(MapInfo.Data.TableType.Native, table);
native.TablePath = @"c:\MyNativeTable.tab"; //set the name of the table and path where it will be saved
native.WriteTabFile();
MapInfo.Data.Table nativetable = MapInfo.Engine.Session.Current.Catalog.CreateTable(native);

nativetable.Close();
nativetable = MapInfo.Engine.Session.Current.Catalog.OpenTable(@"c:\MyNativeTable.tab");
nativetable.InsertFeature(ft);
nativetable.InsertFeature(ft2);
2、创建列
MapInfo.Data.Columns columns = new MapInfo.Data.Columns();
columns.Add(new MapInfo.Data.Column("NumCities", MapInfo.Data.MIDbType.Int, "Count(State)"));

MapInfo.Data.Table USAtab = MapInfo.Engine.Session.Current.Catalog.GetTable("USA");
MapInfo.Data.Table CitiesTab= MapInfo.Engine.Session.Current.Catalog.GetTable("Cities");

USAtab.AddColumns(columns, MapInfo.Data.BindType.DynamicCopy, CitiesTab, "State", MapInfo.Data.Operator.Equal, "State");
3、删除表
string tabFile,datFile,indFile,idFile,mapFile;

//Get .TAB file
System.IO.FileInfo tabFileObj = new System.IO.FileInfo(tab1.TableInfo.TablePath.ToString());

tabFile = tabFileObj.Name.ToString();

//create filename + other MapInfo table extensions and create a FileInfo Object
datFile = tabFileObj.Name.Replace(".TAB",".DAT");
System.IO.FileInfo datFileObj = new System.IO.FileInfo(tabFileObj.Directory + "\\" + datFile);
indFile = tabFileObj.Name.Replace(".TAB",".IND");
System.IO.FileInfo indFileObj = new System.IO.FileInfo(tabFileObj.Directory + "\\" + indFile);
idFile = tabFileObj.Name.Replace(".TAB",".ID");
System.IO.FileInfo idFileObj = new System.IO.FileInfo(tabFileObj.Directory + "\\" + idFile);
mapFile = tabFileObj.Name.Replace(".TAB",".MAP");
System.IO.FileInfo mapFileObj = new System.IO.FileInfo(tabFileObj.Directory + "\\" + mapFile);

//delete all files from the drive
tabFileObj.Delete();
datFileObj.Delete();
indFileObj.Delete();
idFileObj.Delete();
mapFileObj.Delete();

//close the table reference from the current catalog
tab1.Close();

 

转载于:https://www.cnblogs.com/Fantasia/archive/2006/11/29/576354.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值