Select to view content in your preferred language

Correct syntax for coverage

2146
17
09-04-2012 02:41 PM
SamCoggins1
Occasional Contributor
Hello:

I've got a script that looks in a directory, finds coverages, and converts the coverages to a geodatabase. This works perfectly for every feature class in the coverage, except 'arc'. I have tried multiple ways of importing the 'arc' feature class, each time Python tells me it doesn't not exist or is not supported. I am wondering if I'm using the correct syntax, which I had assumed to be similar to a geodatabase. I am using this to refer to the arc feature class:

CDMS_Arc = "I:\\Workspace\\Coverage\\Arc"

Thanks
Tags (2)
0 Kudos
17 Replies
SamCoggins1
Occasional Contributor
Nope, made no difference. Same error. Not sure where to go from here. I had thought of using a search cursor and copying the data over by 'searching' for each row in the arc feature, then 'updating' a new geodatabase feature class with the searched data. However, the arc feature class is not recognised by the search cursor.

There is an interesting issue in the error message I get from my original script (I can't take full credit for this script, as some of the finer points were provided by the IT guy I worked with):


# Import system modules
import arcpy, string

# Source directory
directory = r'I:\Q_workspace\Sam_GIS\290812_CoveragetoGDB\COVERS'
destDir = directory + '\\gdb'

# Workspace
arcpy.env.workspace = directory

# Determine coverages in folders
coverageList = arcpy.ListDatasets()
for coverage in coverageList:
    outPath = destDir + '\\' + coverage
    if arcpy.Exists(outPath):
        print outPath + " already exists.  Stopping..."
        break
    else:
        print "Creating " + outPath
        newGDB = arcpy.CreateFileGDB_management(destDir, coverage)

    # Determine feature classes in coverage
    arcpy.env.workspace = directory + '\\' + coverage
    fcList = arcpy.ListFeatureClasses()
    print coverage + " has the following featureclassses: " + ','.join(fcList)
    arcpy.FeatureClassToGeodatabase_conversion(fcList, newGDB)
    


Which results in this error:

Traceback (most recent call last):
  File "I:\Q_workspace\Sam_GIS\290812_CoveragetoGDB\NumeroUno.py", line 40, in <module>
    arcpy.FeatureClassToGeodatabase_conversion(fcList, newGDB)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\conversion.py", line 1152, in FeatureClassToGeodatabase
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset I:\Q_workspace\Sam_GIS\290812_CoveragetoGDB\COVERS\CDMS\Tic;I:\Q_workspace\Sam_GIS\290812_CoveragetoGDB\COVERS\CDMS\Point;Arc;I:\Q_workspace\Sam_GIS\290812_CoveragetoGDB\COVERS\CDMS\Annotation does not exist or is not supported
Failed to execute (FeatureClassToGeodatabase).

In the section of the error message I've provided in Bold font, notice the Point and Annotation feature classes are provided with the full path, while the Arc feature is not. I'm not sure what this means, it's a little strange. Maybe part of the problem?
0 Kudos
curtvprice
MVP Alum
List FeatureClasses returns local paths:

>>> arcpy.env.workspace = r"e:\work\basincov"
>>> arcpy.ListFeatureClasses()
[u'arc', u'label', u'polygon', u'tic']


I recommend explictly setting up complete paths for each before you give them to the tool. You also probably want to drop "tic" - not very useful now that digitizing tables are pretty much extinct.

Also, annotation is no good either, since the tool does not support that (according to the help anyway). Maybe the annotation is our issue here.

Note my use of os.path.join (a lot cleaner than just appending strings)

import os
arcpy.env.workspace = os.path.join(directory,coverage)
fcList = arcpy.ListFeatureClasses()
fcList = fcList.remove("tic") # don't need tics
fcList = fclist.remove("annotation") # drop annotation
# use a list comprehension to prepend full paths
fcListFull = [os.path.join(arcpy.env.workspace,k) for k in fcList]
arcpy.FeatureClassToGeodatabase_conversion(fcListFull, newGDB)


BTW I'm with Matthew, you may have a data issue. I can't reproduce your problem with the local path (note I'm using 10.1).

>>> zgdb = arcpy.CreateFileGDB_management(r"e:\work","zgdb")
>>> x
[u'arc', u'label', u'polygon', 'tic']
>>> arcpy.FeatureClassToGeodatabase_conversion(x,zgdb)
e:\work\basincov\arc Successfully converted:  e:\work\zgdb.gdb\basincov_arc
e:\work\basincov\label Successfully converted:  e:\work\zgdb.gdb\basincov_label
e:\work\basincov\polygon Successfully converted:  e:\work\zgdb.gdb\basincov_polygon
e:\work\basincov\tic Successfully converted:  e:\work\zgdb.gdb\basincov_tic
<Result 'e:\\work\\zgdb.gdb'>
0 Kudos
SamCoggins1
Occasional Contributor
Yeah, I figured it may just be a data issue... Think I'm just going to leave it for now. Thanks all for the advice/comments/help...
0 Kudos
RebeccaStrauch__GISP
MVP Emeritus
Hi @scoggins,

I was also having issues, more with trying to figure out what "datatype" it wanted when attaching the script to a toolbar.  I finally got "Dataset" to work (not coverage like I would have guessed).  I am using 10.1 btw.

Simplified code with parameter setup is below.  I used "Workspace or Feature Dataset" and "Any Value" for the data type of the other two variables. 


import arcpy

#setup variables
arcpy.env.overwriteOutput = True

theCoverage = arcpy.GetParameterAsText(0)
if theCoverage == '#':
    theCoverage = r"c:\_data\_Skwentna07\covers\trans07\arc"
#theCoverage = r"c:\_data\_Skwentna07\covers\trans07\arc"

theWorkspace = arcpy.GetParameterAsText(1)
if arcpy.env.workspace == '#':
    arcpy.env.workspace = r"c:\_data\_Skwentna07\Reports\RetroFitDev2\newTest.gdb"
    #C:\_data\_Skwentna07\Reports\RetroFitDev2\newTest.gdb
#arcpy.env.workspace = r"c:\_data\_Skwentna07\Reports\RetroFitDev2\newTest.gdb"
theWorkspace = arcpy.env.workspace

outFC = arcpy.GetParameterAsText(2)
if outFC == '#':
    outFC =  "cleanTrans"   # Transects

print("  Converting the coverage to a FC " + str(outFC))
arcpy.FeatureClassToFeatureClass_conversion(theCoverage, theWorkspace, outFC)



....or at least it worked a couple times....now??  UGH!  ((it did work, kind of....wrote to my mxd env which was still set to the default gdb instead of theWorkspace variable.  The default fgdb in 10.1 messes with me all the time!)
0 Kudos
RebeccaStrauch__GISP
MVP Emeritus


I was also having issues, more with trying to figure out what "datatype" it wanted when attaching the script to a toolbar.  I finally got "Dataset" to work (not coverage like I would have guessed).  I am using 10.1 btw.

Simplified code with parameter setup is below.  I used "Workspace or Feature Dataset" and "Any Value" for the data type of the other two variables. 




Update (caution): if the coverage is not DOUBLE precision and then CLEANed (with ARC option), the command may not import all records.  But with the CLEAN, some lines may get flipped, which for my project is a problem.  Just using the BUILD with ARC option didn't improve anything.

Best option for me which doesn't flip line direction is to use the ARCSHAPE command (one the SINGLE or DOUBLE precision coverage....no difference) and then use FeatureClassToFeatureClass to import the shape file.
0 Kudos
curtvprice
MVP Alum
Some suggestions below.

I was also having issues, more with trying to figure out what "datatype" it wanted when attaching the script to a toolbar.  I finally got "Dataset" to work (not coverage like I would have guessed). 


I believe you were looking for "Coverage Feature Class", which is a subset of "Dataset"

"Workspace or Feature Dataset" and "Any Value" for the data type of the other two variables. 


That last one is a feature class name, so it should be type String. Your script could validate that against the workspace using the arcpy.ValidateTableName method to make sure it's a legal output name.


theCoverage = arcpy.GetParameterAsText(0)
if theCoverage == '#':


GetParameterAsText() will return "" (not "#") if the parameter was not set and you haven't set a default value in the script tool parameters tab.
"" evaluates to false in an if, so I often do this:
theCoverage = arcpy.GetParameterAsText(0)
if not theCoverage: 
    theCoverage = r"c:\_data\_Skwentna07\covers\trans07\arc"


If you think you may run this from Windows instead of from a toolbox, you can support "#" like this:
theCoverage = arcpy.GetParameterAsText(0)
if theCoverage in ["","#"]:
    theCoverage = r"c:\_data\_Skwentna07\covers\trans07\arc"


UGH! ((it did work, kind of....wrote to my mxd env which was still set to the default gdb instead of theWorkspace variable.


If you apply an environment setting inside the script, it will override any application settings. (Note you can set this parameter in the script tool parameters dialog to default to the app workspace setting.) These settings are local to the script, and will not affect the GP environment of the application that launched the script tool.
theWorkspace = arcpy.GetParameterAsText(1)
if not theWorkspace:
    theWorkspace = r"c:\_data\_Skwentna07\Reports\RetroFitDev2\newTest.gdb"
arcpy.env.workspace = theWorkspace
0 Kudos
RebeccaStrauch__GISP
MVP Emeritus
Some suggestions below.

GetParameterAsText() will return "" (not "#") if the parameter was not set and you haven't set a default value in the script tool parameters tab.
"" evaluates to false in an if, so I often do this:
theCoverage = arcpy.GetParameterAsText(0)
if not theCoverage: 
    theCoverage = r"c:\_data\_Skwentna07\covers\trans07\arc"


If you think you may run this from Windows instead of from a toolbox, you can support "#" like this:
theCoverage = arcpy.GetParameterAsText(0)
if theCoverage in ["","#"]:
    theCoverage = r"c:\_data\_Skwentna07\covers\trans07\arc"




This change makes sense.  I think the other code was from the python class I took a few years ago and I never revisted it in the newer versions/toolbar.
0 Kudos
JoelCalhoun
Deactivated User
One thing to also keep in mind is that if you have coverage annotation you need to use ImportCoverageAnnotation otherwise your annotation will be converted to a line with a "name" attribute.

 env.workspace = landpath + os.sep + "ilr"
    # Get a list of all feature classes in the workspace
    fcs = arcpy.ListFeatureClasses()
    # Loop through the list of feature classes
    for fc in fcs:
        fc = str(fc)
        if "." in fc:
            fc_fix = fc.replace(".", "_") # Replace . with _ for use as a feature class input name
            #messages("Fixed " + fc_fix)
        else:
            fc_fix = fc

        # Create a Describe object
        desc = arcpy.Describe(landpath + os.sep + "ilr" + os.sep + fc)
        # Pull Describe Object properties
        if hasattr(desc, "featureType"):
            featureType = desc.featureType
             
        if featureType == "CoverageAnnotation":
           # Process: Import Coverage Annotation
           arcpy.ImportCoverageAnnotation_conversion(fc, out_dataset_path + os.sep + out_name + os.sep + out_name + "_" + fc_fix, "2400", "CLASSES_FROM_LEVELS", "NO_MATCH", "NO_SYMBOL_REQUIRED", "STANDARD", "", "AUTO_CREATE", "AUTO_UPDATE")

        else:
            arcpy.FeatureClassToFeatureClass_conversion(fc, out_dataset_path + os.sep + out_name, out_name + "_" + fc_fix)
0 Kudos