从MapX到MapXtreme2004[3]-搜索图元Feature

一、根据名称搜索图元

  1、Mapxtreme的架构和Mapx有所变化,Mapx中,Layer包含Features,而Mapxtreme中则不是

  2、Mapxtreme的例子中的查找,是通过Find对象来实现的,而Find对象的构造,需要指定Table和Colume,Table好办,FeatureLayer.table即可,而Colume通过FeatureLayer.table.tableinfo.colums["列名"]来指定。但是,关键问题,大多数的地图,并未设计过多的字段来供查询,查的其实就是个标题和label而已。

  3、要用笨办法,遍历图层的features,通过这个方法
           foreach(Feature feature in lyr.table)
           {
           }

  4、Feature派生自Object,包含一个Geometry属性,这个属性是各种几何图形对象的基类

      Geometry classes that derive from FeatureGeometry include: Point, MultiPoint, MultiCurve, MultiPolygon, FeatureGeometryCollection, Rectangle, RoundedRectangle, Ellipse, LegacyArc, and LegacyText.

  5、通过如下方式引用feature对象
            ((MapInfo.Geometry.LegacyText)feature.Geometry).Caption

二、通过search方法搜索

  1、catalog的search方法可以按条件搜索图元(第一个图元)
        // also uses search for feature
        Feature fDEU = _catalog.SearchForFeature("europe", MapInfo.Data.SearchInfoFactory.SearchWhere
("Country='DEU'"));

  2、先利用SearchInfoFactory构造一个SearchInfo对象,指定其搜索属性: 

            SearchAll: Returns all the rows.
            SearchNearest: Returns the rows with table geometries that are closest to the given search point.
            SearchWhere: Returns the rows specified by the given where Clause.
            SearchWithinDistance: Returns the rows where the table geometry is contained within a buffer of the search point, rectangle or geometry.
            SearchWithinFeature: Returns the rows where the table geometry is contained within the search features's geometry.
            SearchWithinGeometry: Returns the rows where the table geometry is contained within the search geometry.
            SearchWithinRect: Returns the rows where the table geometry intersects the given rectangle.
            SearchIntersectsFeature: Returns the rows where the table geometry intersects with the search features's geometry.
            SearchIntersectsGeometry: Returns the rows where the table geometry intersects with the search geometry.
            SearchWithinScreenRadius: Creates a SearchInfo that returns the rows where the table geometry intersects a screen circle.
            SearchWithinScreenRect:Returns the rows where the table geometry intersects the given screen rectangle  
  3、再调用search方法,将结果放到
            MultiResultSetFeatureCollection
            IResultSetFeatureCollection
  4、或许还要设置视图
            MapInfo.Engine.Session.Current.MapFactory[0].SetView(fc.Envelope);
三、通过选择工具来选择一个范围
        1、需要控制选择的图层
        2、选择的结果,通过MapInfo.Engine.Session.Current.Selections.DefaultSelection得到一个Selection对象
        3、Selection对象,是一个IResultSetFeatureCollection的集合,每个对应一个表
        4、对每一个IResultSetFeatureCollection,可以通过枚举器来遍历访问
   Selection sl =MapInfo.Engine.Session.Current.Selections.DefaultSelection;
   IResultSetFeatureCollection fc=sl[0];
   IFeatureEnumerator fn=fc.GetFeatureEnumerator();
   ListBox1.Items.Clear();
   while(fn.MoveNext())
    if(fn.Current.Geometry.GetType().ToString()=="MapInfo.Geometry.LegacyText")
     ListBox1.Items.Add(((MapInfo.Geometry.LegacyText)fn.Current.Geometry).Caption);

原文地址:https://www.cnblogs.com/jetz/p/197214.html