物探论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 492|回复: 0

SqlSever与MAPXTREME

[复制链接]
发表于 2013-3-13 20:56:54 | 显示全部楼层 |阅读模式
一。 将sql server数据库表中的字段绑定到表usa的例子

//绑定远程属性数据表(sql server)
//打开地图目标表
Table targetTbl=Session.Current.Catalog.OpenTable (@"C:\Program



Files\MapInfo\Professional\Data\Map_Data\Namerca\USA\Usa_Maps\USA.tab");
FeatureLayer targetLyr=new FeatureLayer (targetTbl,"targetTbl","TargetTable");
mapControl1.Map.Layers.Add (targetLyr);
//打开数据源表(在sql server中),表中需要要唯一关键字段。
MapInfo.Data.TableInfoServer ti=new  TableInfoServer("sourcetable");
ti.ConnectString ="Driver={SQL Server};Server=Lixiaohui;database=test; Uid=sa; Pwd=sa;";
ti.Query="select * from us_cust";
ti.Toolkit=MapInfo.Data.ServerToolkit.Odbc;
Table srcTbl=Session.Current.Catalog.OpenTable(ti);
MessageBox.Show (this,srcTbl.TableInfo.Columns.Count.ToString());
//从源表中将字段加入到目标表,以state(州名)字段为连接字段,加入的字段为以州为单位的订单数。
Columns cols=new Columns();
cols.Add (new Column("sumOrder",MIDbType.Int,"Sum(ORDER_AMT)"));
targetTbl.AddColumns (cols,MapInfo.Data.BindType.Static,srcTbl,"Upper(STATE)",MapInfo.Data.Operator.Equal,"Upper(State)");

二、存在SqlSever中XY坐标点的绑定代码

//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=sawd=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);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|物探论坛 ( 鄂ICP备12002012号 微信号:iwutan )

GMT+8, 2024-5-13 04:19 , Processed in 0.058551 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表