0

I'm trying to use FeatureClassToFeatureClass_conversion() to convert tab files to shapefiles. When I run the code below, the error says

C:/temp1\Overlays\Character_Places\Historic_Misc_Heritage.TAB Failed to execute. Parameters are not valid. ERROR 000732: Input Features: Dataset C:/temp1\Overlays\Character_Places\Historic_Misc_Heritage.TAB does not exist or is not supported. Failed to execute (FeatureClassToFeatureClass).

import arcpy 
from arcpy import env
import os

path = "C:/temp1"
for root, dirs, files in os.walk(path,topdown=False):
   for file in files:
      if file.endswith(".TAB"):
         tabFile = os.path.join(root, file)
         print(tabFile)

         outLocation = "C:/temp3/results.gdb"
         outFeatureClass = "shapefiles"
         arcpy.FeatureClassToFeatureClass_conversio(tabFile,outLocation, outFeatureClass)

When I comment out the FeatureClassToFeatureClass code and print(tabFile) tabFile's contents are printed as..

C:/temp1\Overlays\Character_Places\Historic_Misc_Heritage.TAB
C:/temp1\Overlays\Character_Places\Identified_Places_Heritage.TAB
C:/temp1\Overlays\Character_Places\places_of_history.TAB
C:/temp1\Overlays\Character_Places\places_of_culture.TAB
etc
etc

I'm unsure why its saying the dataset doesn't exist and why tabFile isn't the correct input parameter for FeatureClassToFeatureClass() to work

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Tony Bonomo
  • 137
  • 1
  • 8
  • 1
    Can you please explain what the difference is between your previous question (http://gis.stackexchange.com/questions/210291/using-featureclasstofeatureclass-conversion-to-convert-tab-to-shapefiles/210300#comment320519_210300) and this one? – fatih_dur Sep 12 '16 at 23:18
  • Here I'm trying to implement the FeatureClassToFeatureClass_conversion part now. Please see an error message – Tony Bonomo Sep 12 '16 at 23:30
  • 1
    inFeatures = "tabFile" should be inFeatures = tabFile or just use tabFile instead of inFeatures further down. – PolyGeo Sep 12 '16 at 23:32
  • 1
    @TonyBonomo what was the result? Please update your question to reflect these changes – Midavalo Sep 12 '16 at 23:51
  • Hi, I changed it to inFeatures = tabFile. However I still get the same python error as above in my post. Does tabFile (which is a list of tab file paths) need to be in the format of a feature class or layer? – Tony Bonomo Sep 13 '16 at 00:30
  • files is a list but in your code tabFile looks like it is a *.tab file. Please ensure that the messages (from errors and printing) you present are coming straight from the actual code snippet that you present. – PolyGeo Sep 13 '16 at 00:56
  • 1
    You need to know what kind of data you are outputting from your TAB file - you can't just export mydata.tab, you'd have to specify something like mydata.tab\mydata point to output a point shapefile from point data in your TAB file. – Midavalo Sep 13 '16 at 03:14
  • Last I heard ArcGIS doesn't support direct MapINFO TAB (MIF/TAB) conversion unless you have the interoperability extension. Have a read of http://gis.stackexchange.com/questions/42/converting-mapinfo-tab-and-or-mif-to-shp-using-free-tools-or-arcgis-for-desktop, I'd use OGR2OGR to convert the MapINFO to Esri Shapefile and then import those. When you specify TAB files ArcGIS reads them as 'TAB delimited text files', a table format and not vector (feature) data... preview one in ArcCatalog and see what I mean. – Michael Stimson Sep 13 '16 at 03:45
  • 1
    yes Im already using the Data interoperability ext in this. – Tony Bonomo Sep 13 '16 at 03:48
  • I have updated my code, python error and results.. please see update above. I'm unsure why its saying the dataset doesn't exist and why tabFile isn't the correct input parameter for FeatureClassToFeatureClass? – Tony Bonomo Sep 13 '16 at 04:02
  • Perhaps try path = r"C:\temp1" instead of path = "C:/temp1". You also seem to have an extra level of indentation on your first for line and its code block – PolyGeo Sep 13 '16 at 04:02

1 Answers1

1

I'm not very familiar with TAB files, but when I view them in ArcCatalog they appear to be similar to a geodatabase which holds different feature classes with different geometries. When you reference a feature class in a geodatabase you construct a path like c:\mydata\mygeodatabase.gdb\myfeatureclass where you specify the feature class name after the geodatabase name.

It appears that you need to do something similar with the TABfile. My file looked like c:\mydata\mytabfile.tab\mytabfile point where you've got the name and geometry type after the tab filename.

enter image description here

When I try to run Feature Class to Feature Class on just the TAB file I get an error (same as yours from arcpy)

enter image description here

But when I include the actual geometry from inside the file, the tool accepts it and outputs it as expected

enter image description here

You may need to modify your script to something like this:

for root, dirs, files in os.walk(path,topdown=False):
   for file in files:
      if file.endswith(".TAB"):
         fc = os.path.splitext(file)[0]
         fcnamegeom = "{} point".format(fc)
         tabFile = os.path.join(root, file, fcnamegeom)
         print(tabFile)

         outLocation = "C:/temp3/results.gdb"
         outFeatureClass = fc
         arcpy.FeatureClassToFeatureClass_conversio(tabFile, outLocation, outFeatureClass)

This takes the name of the TAB file and removes the extension, and uses that as the feature class name and combines geometry type point to it (could be changed to whatever geometry type you're using). It then outputs the feature class to your geodatabase results.gdb using the feature class name as the output name.

There doesn't appear to be a way to get arcpy to automatically read the contents of the TAB file (using something like arcpy.ListFeatureClasses() or similar), so you may need to know what each one is beforehand - perhaps storing them in a gdb table and reading that to get the names and geometry type to pass through to your arcpy.FeatureClassToFeatureClass_conversion() tool.

Midavalo
  • 29,696
  • 10
  • 48
  • 104