How to combine the features in the DefaultSelection

C# Code:
//This is the table with the features that will be combined

MapInfo.Mapping.FeatureLayer fl = this .MapControl1.Map.Layers["USA"] as MapInfo.Mapping.FeatureLayer;

//This created a temp table that has the same table structure as the table above
//This is where the new big combined feature will be stored
MapInfo.Data.TableInfoMemTable ti = new MapInfo.Data.TableInfoMemTable("Combined_Features");

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

MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);

MapInfo.FeatureProcessing.FeatureProcessor featureProcessor = new MapInfo.FeatureProcessing.FeatureProcessor();
MapInfo.Data.Feature f = null ;


foreach (MapInfo.Data.IResultSetFeatureCollection irfc in MapInfo.Engine.Session.Current.Selections.DefaultSelection)
{
//Only want to combine features in the USA layer
if (irfc.BaseTable.Alias == fl.Table.Alias)
{
f = featureProcessor.Combine(irfc);
}
}

//Adds the feature to the temp table
table.InsertFeature(f);

//Creates a new featurelayer for the table and adds it to the map
MapInfo.Mapping.FeatureLayer fl2 = new MapInfo.Mapping.FeatureLayer(table);
this .MapControl1.Map.Layers.Add(fl2);


        • Hide details for VB.Net Code:VB.Net Code:
'This is the table with the features that will be combined
Dim fl As MapInfo.Mapping.FeatureLayer = Me .MapControl1.Map.Layers("USA")

'This created a temp table that has the same table structure as the table above
'This is where the new big combined feature will be stored
Dim ti As MapInfo.Data.TableInfoMemTable = New MapInfo.Data.TableInfoMemTable("Combined_Features")

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

Dim table As MapInfo.Data.Table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti)

Dim featureProcessor As MapInfo.FeatureProcessing.FeatureProcessor = New MapInfo.FeatureProcessing.FeatureProcessor
Dim f As MapInfo.Data.Feature = Nothing

Dim irfc As MapInfo.Data.IResultSetFeatureCollection
For Each irfc In MapInfo.Engine.Session.Current.Selections.DefaultSelection
'Only want to combine features in the USA layer
If irfc.BaseTable.Alias = fl.Table.Alias Then
f = featureProcessor.Combine(irfc)
End If
Next

'Adds the feature to the temp table
table.InsertFeature(f)

'Creates a new featurelayer for the table and adds it to the map
Dim fl2 As MapInfo.Mapping.FeatureLayer = New MapInfo.Mapping.FeatureLayer(table)
Me .MapControl1.Map.Layers.Add(fl2)
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值