I used the below code to convert Tab file to Shape file:
wpfMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
BaseMap.Business.DataProvider.TabFile MyTab = new BaseMap.Business.DataProvider.TabFile();
TabFileFeatureLayer worldLayer = MyTab.Load(
SampleFolder + @"HoustonMuniBdySamp_Boundary.TAB", null);
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add("WorldLayer", worldLayer);
wpfMap1.Overlays.Add(staticOverlay);
worldLayer.Open();
wpfMap1.CurrentExtent = worldLayer.GetBoundingBox();
worldLayer.Close();
wpfMap1.Refresh();
//-----------------------------------------------------------------------------------------
worldLayer.Open();
Collection<FeatureSourceColumn> allColumns = worldLayer.QueryTools.GetColumns();
Collection<Feature> allFeatures = worldLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns);
ShapeFileType MyShapeFileType = ShapeFileType.Polygon;
worldLayer.Close();
Collection<DbfColumn> dbfColumns = new Collection<DbfColumn>();
foreach (FeatureSourceColumn featureSourceColumn in allColumns)
{
DbfColumn dbfColumn = new DbfColumn(featureSourceColumn.ColumnName, DbfColumnType.String, 50, 0);
dbfColumns.Add(dbfColumn);
}
string targetShapeFilePath = @"C:\TabToShape.shp";
ShapeFileFeatureLayer.CreateShapeFile(MyShapeFileType, targetShapeFilePath, dbfColumns, System.Text.Encoding.UTF8, OverwriteMode.Overwrite);
ShapeFileFeatureLayer shapes = new ShapeFileFeatureLayer(targetShapeFilePath, ShapeFileReadWriteMode.ReadWrite);
shapes.Open();
shapes.EditTools.BeginTransaction();
foreach (Feature feature in allFeatures)
{
shapes.EditTools.Add(feature);
}
TransactionResult result = shapes.EditTools.CommitTransaction();
shapes.Close();
if (result.TotalFailureCount > 0)
{
MessageBox.Show(string.Format("{0} failed", result.TotalFailureCount));
}
the Problem is that after
Collection<feature> allFeatures = worldLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns);
sometimes, especially for the big files, it return the below exception:
Exception has been thrown by the target of an invocation.
or
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.