0

The following script produces the ERROR 000210: Cannot create output... .shp and ERROR 000354: The name containts invalic characters Failed to execute (Select.).

The line with arcpy.Select_analysis is causing the problem

The result should be shapefiles with the SAME NAME as the Input, but in the Output-Workspace-Folder!

Is there a problem with the path or would you have another idea?

import arcpy, os, math
from arcpy.sa import*
arcpy.CheckOutExtension("Spatial")

pathworkspace = r"D:\aprettylongpath\InputWithShapefilesInside"
outputworkspace = r"D:\aprettylongpath\OutputStillEmpty"

arcpy.env.workspace = pathworkspace
mylist = arcpy.ListFeatureClasses()
where_clause = '"GRIDCODE" =2'

for z in mylist:
    print "Shapefile..."+z
    inShapefiles = z
    arcpy.Select_analysis(inShapefiles,os.path.join(outputworkspace,z),where_clause)

The result from the print in the 3rd last line is:

Shapefile...1111111-rgbi-10cm_compband.shp
2

I've had similar problems when writing to shapefiles where some characters in the filename causes issues (in this case the hyphen). My suggestion is to use the function to validate table names in arcpy:

arcpy.Select_analysis(inShapefiles,arcpy.ValidateTableName(os.path.join(outputworkspace,z)),where_clause)
0

Solved it by slicing my string. Don't know why the output name made a problem, but now it works.

for z in mylist:
    inShapefiles=z
    basename=os.path.basename(inShapefiles)[:7]
    arcpy.Select_analysis(inShapefiles,arcpy.os.path.join(outputworkspace,basename),where_clause)

ValidateTableName did not work for me without this change. The reason for the problem is still not known.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.