mapxtreme2004经典代码之一:添加几何对象

In MXT, geometry & style are object model.
在mxt中,几何实体和样式都是对象模型。

The follow example code demonstrate how to create a geometry , add it to map to display it:
下面的代码演示了怎样生成一个几何对象(Point),然后+到地图控件上去显示。

The code is not difficult, but I put is here only because it covers many concepts like CoordSys(&CoordSysFactory:Design Patter Concepte), TableInfo(TableInfoMemTable), Table(Column,GeometryColumn,MI Ado.net data provider MIConnection, MICommand), Feature(FeatureGeometry)
代码本身并不难,我在这里放置这段代码的原因是因为它涉及到很多概念:坐标系(坐标系工厂:设计模式概念),表格元数据:表格信息(内存表格),表格(列,集合列,MapInfo数据提供者,数据连接,命令)图元(几何图元)

I hope u can have a deeper understanting about i
希望你能有一个深刻的理解。
The code  is without any comment,   I think u r more clever than me.
代码没有注释,因为我认为你比我更聪明,

 1 None.gif          private   void  button1_Click( object  sender, System.EventArgs e)
 2 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 3InBlock.gif        
 4InBlock.gif            CoordSysFactory csf = new CoordSysFactory();
 5InBlock.gif            CoordSys coordsys = csf.CreateCoordSys("mapinfo:coordsys 1,104");
 6InBlock.gif            double x = 10,y=20;
 7InBlock.gif
 8InBlock.gif            TableInfoMemTable timt = new MapInfo.Data.TableInfoMemTable("mem");
 9InBlock.gif
10InBlock.gif            
11InBlock.gif            
12InBlock.gif            GeometryColumn gc = new MapInfo.Data.GeometryColumn(coordsys);
13InBlock.gif            gc.Alias = "Obj";
14InBlock.gif            gc.DataType = MIDbType.FeatureGeometry;
15InBlock.gif            timt.Columns.Add(gc);
16InBlock.gif
17InBlock.gif            Column c = new Column();
18InBlock.gif            c.Alias = "MI_Style";
19InBlock.gif            c.DataType = MIDbType.Style;
20InBlock.gif            timt.Columns.Add(c);
21InBlock.gif            Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(timt);
22InBlock.gif
23InBlock.gif            Geometry g = new MapInfo.Geometry.Point(coordsys,x,y);
24InBlock.gif            FeatureGeometry fg = (FeatureGeometry)g;
25InBlock.gif
26InBlock.gif            SimpleVectorPointStyle svps = new SimpleVectorPointStyle(34,Color.Red,50);
27InBlock.gif            CompositeStyle cs = new CompositeStyle(svps);
28InBlock.gif
29InBlock.gif            MIConnection micon = new MIConnection();
30InBlock.gif            
31InBlock.gif            micon.Open();
32InBlock.gif            MICommand micom = micon.CreateCommand();
33InBlock.gif            micom.CommandText = "insert into mem values(@obj,@style)";
34InBlock.gif            micom.Parameters.Add("@obj",MIDbType.FeatureGeometry);
35InBlock.gif            micom.Parameters.Add("@style",MIDbType.Style);
36InBlock.gif            micom.Parameters["@obj"].Value = g;
37InBlock.gif            micom.Parameters["@style"].Value = cs;
38InBlock.gif
39InBlock.gif            micom.Prepare();
40InBlock.gif            int n = micom.ExecuteNonQuery();
41InBlock.gif
42InBlock.gif            micom.Cancel();
43InBlock.gif            micom.Dispose();
44InBlock.gif
45InBlock.gif            FeatureLayer fl = new FeatureLayer(table);
46InBlock.gif            this.mapControl1.Map.Layers.Add(fl);
47InBlock.gif
48InBlock.gif        
49InBlock.gif        
50ExpandedBlockEnd.gif        }
Because all geometry is a object , u can create any FeatureGeometry to & add it to the map;the code is all the same except the constructor to create the geometry.
因为几何实体都是对象,所以你可以创建自己的几何实体,并+到地图上去显示它;所有的代码都是很相似,仅仅是不同类型,其构造方法不同而已。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值