//XY绑定:含有x,y坐标点的图层放置在Sql Server数据库中,按xy坐标生成点图层
//1.要在存在该表的数据库中建立MAPINFO_MAPCATALOG表,否则会报错:
//"An unhandled exception of type ''MapInfo.Data.TableException'' occurred in mapinfo.coreengine.dll.
//Additional information: 不能打开表。 ODBC 错误: ODBC RC=-1, ODBC SQLState=S0002, DBMS RC=208, DBMS Msg=[Microsoft][ODBC SQL Server Driver][SQL Server]对象名 ''MAPINFO.MAPINFO_MAPCATALOG'' 无效。
//2.要含xy坐标点的表建立主键,否则会报错:
//"Additional information: 不能打开表。因为不能识别唯一键,不能访问远程数据。"
//建立XY空间方案
MapInfo.Data.SpatialSchemaXY xy = new MapInfo.Data.SpatialSchemaXY();
xy.XColumn = "X";
xy.YColumn = "Y";
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=LIXIAOHUI;Database=test;Uid=sa;Pwd=sa;","select * from Us_Cust",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);