ArcPy Feature Class to Feature Class - Name contains invalid charcters

2346
3
Jump to solution
08-03-2018 08:34 AM
Business_IntelligenceSoftware
Occasional Contributor

Hi,

I have a Feature Class to Feature Class script that is supposed to take a Feature Class (FC) of locations and create a separate FC for each location. However, it keeps giving me the following two errors.

ERROR 000210: Cannot create output E:\arcGIS_Shared\Business Analyst\PotentialCitePackages.gdb\NorthEdmond  
ERROR 000354: The name contains invalid characters
Failed to execute (FeatureClassToFeatureClass)

Here is the FC to FC script:

inFeatures = "PythonTest_Geocoded"
fields = ['ObjectID', 'Shape','USER_Center']

with arcpy.da.SearchCursor(inFeatures, fields) as cursor:
    for row in cursor:
        outLocation = r"E:\arcGIS_Shared\Business Analyst\PotentialCitePackages.gdb"
        outFeatureClass = "{0}".format(row[2])
        delimitedField = arcpy.AddFieldDelimiters(env.workspace, "USER_Center")
        expression = delimitedField + " = '{0}'".format(row[2])
        print(expression)
         
        ## Execute FeatureClassToFeatureClass
        arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outLocation, outFeatureClass, expression)

The output FCs are supposed to be named after their corresponding locations ('USER_Center"). This field contains no invalid characters, as you can see below (I was testing this code on a table with only 3 rows).

Could someone help me figure out what I'm doing wrong/missing?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Whitespace characters are invalid, and I suspect you have one at the end of your text, i.e., the text is 'NorthEdmond ' instead of 'NorthEdmond' .  Try changing:

outFeatureClass = "{0}".format(row[2].strip())

View solution in original post

3 Replies
DanPatterson_Retired
MVP Emeritus

can you print out the expression.

see that capital U suggests it may be making a Unicode character, and I suspect that your path no longer is in raw format and only contains single backslashes.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Whitespace characters are invalid, and I suspect you have one at the end of your text, i.e., the text is 'NorthEdmond ' instead of 'NorthEdmond' .  Try changing:

outFeatureClass = "{0}".format(row[2].strip())
Business_IntelligenceSoftware
Occasional Contributor

That was the answer. Thanks for your help!

0 Kudos