Global Navigation Bar

MapInfo Products Knowledge Base


Product: MapXtreme 2004/2005
Version: 6.5
Platform: All Windows Platforms
Category: Features

Summary:
How to access an individual member of a Feature Collection object

Question:
Feature collection objects (IResultSetFeatureCollection, etc) are based off the standard .NET collection classes and individual memebers can be accessed via a MapInfo.Data.Key or integer based index.

Answer:

Hide details for C# Code:C# Code:
MapInfo.Mapping.MapTableLoader loader = new MapTableLoader
(@"C:\Program Files\MapInfo\Professional\Data\USA.TAB");
this.mapControl1.Map.Load(loader);

MapInfo.Data.MIConnection conn = new MapInfo.Data.MIConnection();
conn.Open();

MapInfo.Data.Table tab1 = conn.Catalog.GetTable("USA");

MapInfo.Data.SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchAll();
MapInfo.Data.IResultSetFeatureCollection irfc = conn.Catalog.Search(tab1,si);

//get the very first feature in the irfc
MapInfo.Data.Feature f = irfc[0];

//insert the above feature into the table, assign a key value
MapInfo.Data.Key key = tab1.InsertFeature[f];

MapInfo.Data.Feature f2 = irfc[key];


Hide details for VB Code:VB Code:
Dim loader As MapInfo.Mapping.MapTableLoader = New MapTableLoader("C:\Program Files\MapInfo\Professional\Data\USA.TAB")
Dim conn As MapInfo.Data.MIConnection = New MapInfo.Data.MIConnection
conn.Open()

Dim tab1 As MapInfo.Data.Table = conn.Catalog.GetTable("USA")

Dim si As MapInfo.Data.SearchInfo = MapInfo.Data.SearchInfoFactory.SearchAll()

Dim irfc As MapInfo.Data.IResultSetFeatureCollection = conn.Catalog.Search(tab1, si)


'get the very first feature in the irfc
Dim f As MapInfo.Data.Feature = CType(irfc, MapInfo.Data.Feature).Item(1)

'insert the above feature into the table, assign a key value

Dim key As MapInfo.Data.Key = tab1.InsertFeature(f)

Dim f2 As MapInfo.Data.Feature = CType(irfc, MapInfo.Data.Feature).Item(key.ToString())


Last Modified:
Global Navigation Bar