物探论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 623|回复: 0

mapxtreme+c#实战摘要(一)

[复制链接]
发表于 2013-3-13 21:30:16 | 显示全部楼层 |阅读模式
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();

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|物探论坛 ( 鄂ICP备12002012号 微信号:iwutan )

GMT+8, 2024-5-10 19:54 , Processed in 0.132879 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表