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);
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)
转载请注明原文地址: https://ibbs.8miu.com/read-28400.html