mapxtreme2004经典代码之一:添加几何对象
2005-08-31 00:11
489 查看
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 private void button1_Click(object sender, System.EventArgs e)
2
4 CoordSysFactory csf = new CoordSysFactory();
5 CoordSys coordsys = csf.CreateCoordSys("mapinfo:coordsys 1,104");
6 double x = 10,y=20;
7
8 TableInfoMemTable timt = new MapInfo.Data.TableInfoMemTable("mem");
9
10
11
12 GeometryColumn gc = new MapInfo.Data.GeometryColumn(coordsys);
13 gc.Alias = "Obj";
14 gc.DataType = MIDbType.FeatureGeometry;
15 timt.Columns.Add(gc);
16
17 Column c = new Column();
18 c.Alias = "MI_Style";
19 c.DataType = MIDbType.Style;
20 timt.Columns.Add(c);
21 Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(timt);
22
23 Geometry g = new MapInfo.Geometry.Point(coordsys,x,y);
24 FeatureGeometry fg = (FeatureGeometry)g;
25
26 SimpleVectorPointStyle svps = new SimpleVectorPointStyle(34,Color.Red,50);
27 CompositeStyle cs = new CompositeStyle(svps);
28
29 MIConnection micon = new MIConnection();
30
31 micon.Open();
32 MICommand micom = micon.CreateCommand();
33 micom.CommandText = "insert into mem values(@obj,@style)";
34 micom.Parameters.Add("@obj",MIDbType.FeatureGeometry);
35 micom.Parameters.Add("@style",MIDbType.Style);
36 micom.Parameters["@obj"].Value = g;
37 micom.Parameters["@style"].Value = cs;
38
39 micom.Prepare();
40 int n = micom.ExecuteNonQuery();
41
42 micom.Cancel();
43 micom.Dispose();
44
45 FeatureLayer fl = new FeatureLayer(table);
46 this.mapControl1.Map.Layers.Add(fl);
47
48
49
50 }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.
因为几何实体都是对象,所以你可以创建自己的几何实体,并+到地图上去显示它;所有的代码都是很相似,仅仅是不同类型,其构造方法不同而已。
在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 private void button1_Click(object sender, System.EventArgs e)
2
4 CoordSysFactory csf = new CoordSysFactory();
5 CoordSys coordsys = csf.CreateCoordSys("mapinfo:coordsys 1,104");
6 double x = 10,y=20;
7
8 TableInfoMemTable timt = new MapInfo.Data.TableInfoMemTable("mem");
9
10
11
12 GeometryColumn gc = new MapInfo.Data.GeometryColumn(coordsys);
13 gc.Alias = "Obj";
14 gc.DataType = MIDbType.FeatureGeometry;
15 timt.Columns.Add(gc);
16
17 Column c = new Column();
18 c.Alias = "MI_Style";
19 c.DataType = MIDbType.Style;
20 timt.Columns.Add(c);
21 Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(timt);
22
23 Geometry g = new MapInfo.Geometry.Point(coordsys,x,y);
24 FeatureGeometry fg = (FeatureGeometry)g;
25
26 SimpleVectorPointStyle svps = new SimpleVectorPointStyle(34,Color.Red,50);
27 CompositeStyle cs = new CompositeStyle(svps);
28
29 MIConnection micon = new MIConnection();
30
31 micon.Open();
32 MICommand micom = micon.CreateCommand();
33 micom.CommandText = "insert into mem values(@obj,@style)";
34 micom.Parameters.Add("@obj",MIDbType.FeatureGeometry);
35 micom.Parameters.Add("@style",MIDbType.Style);
36 micom.Parameters["@obj"].Value = g;
37 micom.Parameters["@style"].Value = cs;
38
39 micom.Prepare();
40 int n = micom.ExecuteNonQuery();
41
42 micom.Cancel();
43 micom.Dispose();
44
45 FeatureLayer fl = new FeatureLayer(table);
46 this.mapControl1.Map.Layers.Add(fl);
47
48
49
50 }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.
因为几何实体都是对象,所以你可以创建自己的几何实体,并+到地图上去显示它;所有的代码都是很相似,仅仅是不同类型,其构造方法不同而已。
相关文章推荐
- 各种关联关系对象间 添加依赖。代码实现注意:###### 必须先拿到持久态的对象。再对其添加依赖
- Scala深入浅出实战经典之 List伴生对象操作方法代码实战.
- MapXtreme2004代码 之 自定义范围主题地图
- 为MapXtreme 2004 6.1 Win 添加测距功能按钮
- 原生js面向对象开发打砖块游戏,用代码怀念儿时经典
- simhash算法介绍-尾部添加比较经典的实现代码,代码值得一读
- 学习笔记:Unity战斗卡牌游戏(二)-----滑动列表及克隆删除对象以及代码添加脚本
- 如何在浏览器的控制台中输出json对象,以及添加代码调试。
- MapXtreme2004代码 几个地图工具的使用(C#)
- Scala深入浅出实战经典:38,List伴生对象操作方法代码实战
- MapXtreme2004代码 MapControl控件中显示地图文件
- MapXtreme2004代码 简单专题图的显示
- C++实现自动为对象添加“属性”访问代码
- MapXtreme2004代码 搜索特定图元并将其显示到地图上
- MapXtreme2004代码 之 自定义范围主题地图
- MapXtreme2004常用代码
- Scala深入浅出进阶经典 第64讲:Scala中隐式对象代码实战详解
- JS动态添加与删除select中的Option对象(示例代码)
- JS动态添加与删除select中的Option对象(示例代码)
- VS 自动添加注释的代码运行时报: 未将对象引用设置到对象实例。