ThinkGeo.com    |     Documentation    |     Premium Support

Save TabFile as ShapeFile

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.



-



Hi Guys, 
 I am waiting for useful comment. 
  
 Regards

Ben,


This might because FDO doesn't have a good support for multi Cores. Could you try running this app with only one core? Here is how to do it:


1)                   Open the Windows Task Manager.

2)                   On the Tab Processes, Right-Click on the corresponding process.

3)                   Select “Set Affinity”, a “Processor Affinity” dialogue pop up.




4)                   Un-check all of the CPUs, only leave the “CPU 0” checked. Following is an image:



After that, your code should be working fine. Please let us know if you have more issues.


Thanks,


Ben



great, It works perfectly, but we decide to write our converter. 
  
 Regards, 
 Ben

Ben, 
  
 Thanks for letting us know your status. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale

Ben, 
  
 Just let you know we found a way to set the affinity in code. Simply add the following line in your app (C#) and you can make it woking only on one Core.  
  
 Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)1;  
  
 Sure we are still looking for the "real solution" to make the FDO support multi cores.  
  
 Thanks,  
  
 Ben