• 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        private void button1_Click(object sender, System.EventArgs e)
     2        {
     3        
     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.
    因为几何实体都是对象,所以你可以创建自己的几何实体,并+到地图上去显示它;所有的代码都是很相似,仅仅是不同类型,其构造方法不同而已。

  • 相关阅读:
    CSS居中方法搜集
    函数表达式与函数声明的一点区别
    z-index 解析
    Android EditText的输入监听,输入字符的动态获取
    dispatchkeyevent的调用机制
    自定义带有图片的PreferenceActivity
    declare-styleable:自定义控件的属性
    在fragment中调用SharedPreferences
    使用Preference保存设置
    getSharedPreferences()与getSharedPreferences()与getDefaultSharedPreferences()的区别
  • 原文地址:https://www.cnblogs.com/xiexiaokui/p/226572.html
Copyright © 2020-2023  润新知