oracle连接nacti,MapXtreme 连接Oracle数据库(转)

MapXtreme2004、2005、2008都可以连接Oracle数据库,可以把地图数据存放在Oracle数据库中,然后在程序中调用。这样的优点就是地图数据维护比较方便。

以下是代码:

1 连接到Oracle空间数据库

TableInfoServer ti=new TableInfoServer("ZKT");

ti.Toolkit = MapInfo.Data.ServerToolkit.Oci;

ti.CacheSettings.CacheType =

MapInfo.Data.CacheOption.All;

ti.MbrSearch = false;

ti.ConnectString = "SRVR=s1;UID=gisWD=gis;";

2 打开空间表

ti.Query = "SELECT * FROM T1 WHERE id1 = '" + strBuilderID +

"'";

Table t = conn.Catalog.OpenTable(ti);

3 建立内存表,加快操作

c = MapInfo.Engine.Session.Current.Catalog;

TableInfoMemTable tiMem = new

TableInfoMemTable("memZKT");

tiMem.CacheSettings.CacheType =

MapInfo.Data.CacheOption.All;

tiMem.Temporary = true;

foreach(MapInfo.Data.Column c1 in t.TableInfo.Columns){

tiMem.Columns.Add(c1.Clone());

System.Diagnostics.Debug.Write(c1.Alias + "-" +

c1.DataType.ToString());

}

tableMem = c.CreateTable(tiMem);

4 利用MapXtreme2004的ADO.Net从空间表导入内存表

MIConnection conn ;

MICommand miCommand;

conn = new MIConnection();

conn.Open();

miCommand = conn.CreateCommand();

miCommand.CommandText = "Insert into memZKT select * from

zkt";

miCommand.ExecuteNonQuery();

5 更改图元样式

MapInfo.Styles.CompositeStyle myStyle = new

MapInfo.Styles.CompositeStyle();

MapInfo.Styles.SimpleLineStyle regionBorder = new

MapInfo.Styles.SimpleLineStyle();

regionBorder.Width = new

MapInfo.Styles.LineWidth(1,MapInfo.Styles.LineWidthUnit.Pixel);

regionBorder.Color  =

System.Drawing.Color.Black;

MapInfo.Styles.SimpleInterior regionInterior = new

MapInfo.Styles.SimpleInterior();

regionInterior.Pattern =

(int)MapInfo.Styles.PatternStyle.None;

regionInterior.Transparent = true;

MapInfo.Styles.SimpleLineStyle lineStyle = new

MapInfo.Styles.SimpleLineStyle();

lineStyle.Width = new

MapInfo.Styles.LineWidth(1,MapInfo.Styles.LineWidthUnit.Pixel);

lineStyle.Color  =

System.Drawing.Color.Black;

myStyle.AreaStyle.Border = regionBorder;

myStyle.AreaStyle.Interior = regionInterior;

myStyle.LineStyle = lineStyle;

System.Windows.Forms.Application.DoEvents();

miCommand.CommandText = "Update memZKT Set

[email=MI_STYLE=@style]MI_STYLE=@style[/email] ";

miCommand.Parameters.Add("@style",myStyle);

miCommand.ExecuteNonQuery();

miCommand.Parameters.Clear();

6 导出到文件

MapInfo.Mapping.MapExport exp = new

MapInfo.Mapping.MapExport(_map);

exp.Format = MapInfo.Mapping.ExportFormat.Jpeg;

MapInfo.Geometry.DRect bounds = f.Geometry.Bounds;

newBounds.x1 = bounds.x2 + (bounds.Width() / 2);

newBounds.y1 = bounds.y2 + (bounds.Height() / 2);

newBounds.x2 = bounds.x1 - (bounds.Width() / 2);

newBounds.y2 = bounds.y1 - (bounds.Height() / 2);

_map.Center = f.Geometry.Centroid;

_map.Bounds = newBounds;

exp.Export(strDir + f["id"].ToString() + ".jpg");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值