mapx连接数据库
MIConnection Connection = new MIConnection(); Connection.Open(); MapInfo.Data.SpatialSchemaXY xy = new MapInfo.Data.SpatialSchemaXY(); xy.XColumn = "id"; xy.YColumn = "age"; xy.NullPoint = "0.0, 0.0"; xy.StyleType = MapInfo.Data.StyleType.None; xy.DefaultStyle = new MapInfo.Styles.CompositeStyle(); xy.CoordSys = MapInfo.Engine.Session.Current.CoordSysFactory.CreateLongLat(MapInfo.Geometry.DatumID.WGS84); //建立TableInfo MapInfo.Data.TableInfoServer ti = new MapInfo.Data.TableInfoServer("Customers", "Driver={SQL Server};Server=wingao;Database=mapxdb;Uid=sa;Pwd=1;", "select * from CH_SHENGHUI", MapInfo.Data.ServerToolkit.Odbc); ti.SpatialSchema = xy; MapInfo.Data.Table miCustomers = MapInfo.Engine.Session.Current.Catalog.OpenTable(ti); MapInfo.Mapping.FeatureLayer featureLayer = new MapInfo.Mapping.FeatureLayer(miCustomers); mapControl1.Map.Layers.Add(featureLayer); mapControl1.Map.SetView(featureLayer); Connection.Close(); MessageBox.Show("OK!");
http://www.cnblogs.com/dachie/archive/2010/08/17/1801598.html
TableInfoNative tableInfoNative = new TableInfoNative(layerName); tableInfoNative.Columns.Add(ColumnFactory.CreateStyleColumn()); tableInfoNative.Columns.Add(ColumnFactory.CreateStringColumn("Name", 100)); tableInfoNative.Columns.Add(ColumnFactory.CreateStringColumn("LineType", 100)); //保存tab MapInfo.Data.Table t = MapInfo.Engine.Session.Current.Catalog.CreateTable(tableInfoNative); //加载到mapControl Table tb = Session.Current.Catalog.CreateTable(tableInfoNative); FeatureLayer tempLayer = new FeatureLayer(tb, layerName); mapcontrol.Map.Layers.Add(tempLayer); |