Global Navigation Bar

MapInfo Products Knowledge Base


Product: MapXtreme 2004/2005
Version: 6.0, 6.1, 6.2, 6.5
Platform: Not Platform Related
Category: Data Access

Summary:
An example which shows how to use an IFeatureEnumerator.

Question:
Here is an example that uses an IFeatureEnumerator to create a copy of a table.

Answer:

Hide details for C# Code:C# Code:

MapInfo.Data.Table USCaps = MapInfo.Engine.Session.Current.Catalog.OpenTable(@"C:\Program Files\MapInfo\MapXtreme2004\Maps\North America\usa_caps.tab");

//Sets up a new table info
MapInfo.Data.TableInfoMemTable ti = new MapInfo.Data.TableInfoMemTable("Temp");

foreach(MapInfo.Data.Column col in USCaps.TableInfo.Columns)
{
ti.Columns.Add(col.Clone());
}

//Creates the new table
MapInfo.Data.Table temp = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);

//Create the IFeatureEnumerator
MapInfo.Data.IFeatureEnumerator ienum = (USCaps as MapInfo.Data.ITableFeatureCollection).GetFeatureEnumerator();

//Loops through all the features of the USCaps table and adds them to the new table
while(ienum.MoveNext())
{
MapInfo.Data.Feature ftr = ienum.Current;
temp.InsertFeature(ftr);
}

//Closes the IFeatureEnumarator
(ienum as MapInfo.Data.MIDataReader).Close();

FeatureLayer fl = new FeatureLayer(temp);
this.mapControl1.Map.Layers.Add(fl);
    Hide details for VB.Net Code:VB.Net Code:

    Dim USCaps As MapInfo.Data.Table = MapInfo.Engine.Session.Current.Catalog.OpenTable("C:\Program Files\MapInfo\MapXtreme2004\Maps\North America\usa_caps.tab")

    'Sets up a new table info
    Dim ti As New MapInfo.Data.TableInfoMemTable("Temp")

    For Each col As MapInfo.Data.Column In USCaps.TableInfo.Columns
    ti.Columns.Add(col.Clone())
    Next

    'Creates the new table
    Dim temp As MapInfo.Data.Table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti)

    'Create the IFeatureEnumerator
    Dim ienum As MapInfo.Data.IFeatureEnumerator = CType(USCaps, MapInfo.Data.ITableFeatureCollection).GetFeatureEnumerator()

    'Loops through all the features of the USCaps table and adds them to the new table
    While (ienum.MoveNext())
    Dim ftr As MapInfo.Data.Feature = ienum.Current
    temp.InsertFeature(ftr)
    End While

    'Closes the IFeatureEnumarator
    CType(ienum, MapInfo.Data.MIDataReader).Close()

    Dim fl As New FeatureLayer(temp)
    Me.MapControl1.Map.Layers.Add(fl)

      Last Modified: 04/13/2006 01:59:32 PM
      Global Navigation Bar