mapxtreme+c#实战摘要(一)

ppp80近日用了一下mapxtreme for .net。虽然感觉没有mapx的好用,不过这

个可以和.net结合,已经很满足了。不过我的程序只用了一点点mapxtreme的

东西,所以发掘的东西很少,先记在下边:


1创建临时层
MapInfo.Data.TableInfoMemTable tblInfoTemp = new MapInfo.Data.TableInfoMemTable("Animation");
 MapInfo.Data.Table tblTemp = Cat.GetTable("Animation");
    if (tblTemp != null)     {
     Cat.CloseTable("Animation");
    }

 tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(mapControl1.Map.GetDisplayCoordSys()));
    tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
    tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("编号", 8));
    tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("设备编号", 8));

tblTemp = Cat.CreateTable(tblInfoTemp);

FeatureLayer lyr = new FeatureLayer(tblTemp);
    mapControl1.Map.Layers.Add(lyr);

2创建点样式
MapInfo.Styles.FontPointStyle _fontSymbol=new MapInfo.Styles.FontPointStyle();
   
_fontSymbol.Code=53;
_fontSymbol.PointSize=14;
_fontSymbol.Color=System.Drawing.Color.Purple;
_fontSymbol.Font.Name="Map Symbols";
   _fontSymbol.Font.FontWeight=MapInfo.Styles.FontWeight.Bold;
_fontSymbol.Angle=Ang;//因为是车,所以有一定角度的


3创建点

FeatureGeometry pt3 = new MapInfo.Geometry.Point(lyr.CoordSys, new DPoint(x,y)) as FeatureGeometry;
 MapInfo.Styles.CompositeStyle cs3 = new MapInfo.Styles.CompositeStyle(new MapInfo.Styles.SimpleVectorPointStyle(37, System.Drawing.Color.Red, 10));
    
MapInfo.Data.Feature ftr3 = new MapInfo.Data.Feature(tblTemp.TableInfo.Columns);
 ftr3.Geometry = pt3;
cs3.SymbolStyle=_fontSymbol;
 ftr3.Style = cs3;
  ftr3["编号"] = idr[0].ToString();
 ftr3["设备编号"] =idr[1].ToString();

。。。。
     

4为点添加标注
MapInfo.Styles.TextStyle _fontSymbol=new MapInfo.Styles.TextStyle();
 _fontSymbol.Font.ForeColor=Color.Red;

  _fontSymbol.Font.Size=8;

 LabelLayer layer = new LabelLayer();
 mapControl1.Map.Layers.Add(layer);
     LabelSource source = new LabelSource(Cat.GetTable("Animation"));
     source.DefaultLabelProperties.Caption = "Temp";           

source.DefaultLabelProperties.Style=_fontSymbol;
 layer.Sources.Append(source);

5清除所有的点


Catalog cat = MapInfo.Engine.Session.Current.Catalog;
   Table tblTemp = cat.GetTable("Animation");
   if (tblTemp != null)
   { tblTemp.BeginAccess (MapInfo.Data.TableAccessMode.Write );
    foreach(Feature ftr in tblTemp)
    {
     tblTemp.DeleteFeature(ftr.Key);
    }
    tblTemp.EndAccess ();
   }

6查找点


Feature fKS = _catalog.SearchForFeature("Animation", MapInfo.Data.SearchInfoFactory.SearchWhere("编号='"+ID+"'"));
    SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchIntersectsFeature(fKS, IntersectType.Geometry);
    IResultSetFeatureCollection fc = _catalog.Search("Animation", si);
mapControl1.Map.SetView(fc.Envelope);
_selection.Clear();
    _selection.Add(fc);

7在datagrid中显示图层所有点


dataGrid1.CaptionVisible=false;
 this.miCommand.CommandText = "Select * from " + miTable.Alias;
   MapInfo.Data.MIDataReader miReader = this.miCommand.ExecuteReader();
   DataTable dt = new DataTable("Data");
   for (int i = 0; i < miReader.FieldCount; i++)
   {
    DataColumn dc = dt.Columns.Add(miReader.GetName(i));
   }
   while (miReader.Read())
   {
    DataRow dr = dt.NewRow();
    for (int i = 0; i < miReader.FieldCount; i++)
    {
     dr[i] = miReader.GetValue(i);
    }
    dt.Rows.Add(dr); 
   }
   dt.Columns[0].ColumnMapping = MappingType.Hidden;
   dt.Columns[1].ColumnMapping = MappingType.Hidden;
   dt.Columns[6].ColumnMapping = MappingType.Hidden;
   if (showSchema)
   {
    dataGrid1.DataSource = miReader.GetSchemaTable();
   }
   else
   {
    dataGrid1.DataSource = dt;
   }
   miReader.Close();

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值