Creating a python toolbox using the ESRI .pyt format. This tool is very straight forward (at least in theory) in that one polygon input generates three outputs: a convex hull layer for the input polys, a centroid layer for the input polys, and an intersection of the convex hull and centroids.
def execute(self, parameters, messages): """Execute linear orientation analysis.""" input = parameters[0].valueAsText baseName = arcpy.Describe(input).baseName arcpy.env.workspace = arcpy.Describe(input).catalogPath #overwrite doesn't work, tool still fails if output already exists arcpy.env.overwriteOutput = True #output names mbg = "{0}_MBG".format(baseName) cents = "{0}_centroids".format(baseName) intersectOutput = "{0}_MBG_Intersect".format(baseName) #output arcpy.MinimumBoundingGeometry_management(input, mbg, "CONVEX_HULL", "NONE", "#", "MBG_FIELDS") arcpy.FeatureToPoint_management(input, cents, "INSIDE") arcpy.Intersect_analysis(in_features = [mbg, cents], out_feature_class = intersectOutput, join_attributes = "ALL", cluster_tolerance = "-1 Unknown", output_type="INPUT") return
Stack trace on the error seems to indicate that arcpy.Intersect_Analysis cannot find the feature classes generated by MinimumBoundingGeometry and FeatureToPoint that the script just created:
Traceback (most recent call last):
File "<string>", line 111, in execute
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\analysis.py", line 289, in Intersect
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset C:\GISData\scratch\acir_runs\Hernando_Fuzzy2.gdb\Mines\Mines_MBG #;C:\GISData\scratch\acir_runs\Hernando_Fuzzy2.gdb\Mines\Mines_centroids # does not exist or is not supported
Failed to execute (Intersect).
Commenting out lines 26-30 produces viable output from the MBG and F2P tools.
Anybody run into this one before? Am I missing something obvious - perhaps scoping issues - inherent to .pyc toolboxes/classes, or this is another instance of arcpy $#!^ing the bed?
Solved! Go to Solution.
Finally got it to work by carefully formatting the fully qualified path names.
def execute(self, parameters, messages): """Execute linear orientation analysis.""" input = parameters[0].valueAsText baseName = arcpy.Describe(input).baseName basePath = os.path.split(arcpy.Describe(input).catalogPath)[0] arcpy.env.workspace = basePath #overwrite doesn't work, tool still fails if output already exists arcpy.env.overwriteOutput = True #output names mbg = "{0}_MBG".format(baseName) cents = "{0}_centroids".format(baseName) intersectOutput = "{0}_MBG_Intersect".format(baseName) #output arcpy.MinimumBoundingGeometry_management(input, mbg, "CONVEX_HULL", "NONE", "#", "MBG_FIELDS") arcpy.FeatureToPoint_management(input, cents, "INSIDE") #======================================================================= arcpy.Intersect_analysis(in_features = [r'{0}\\{1}'.format(basePath, mbg),r'{0}\\{1}'.format(basePath, cents)], out_feature_class = intersectOutput, join_attributes = "ALL", cluster_tolerance = "-1 Unknown", output_type="POINT") #======================================================================= return
Nothing I tried using single slashes worked, the intersect tool apparently needed '\\' regardless of whether or not you passed a raw string using 'r' or not. How obscure is that...
throw in a print statement to check the input and output names and append the catalogpath if you have to
Tried that, along with some other basic debugging trying to tackle basic issue like this. Still no joy, even with the fully qualified path names to the feature classes. I also tried enclosing the intersect call within its own function outside of def execute and passing the parameters to a seperate function; that did not work, either.
Running Intersect manually on the two outputs afterwards works fine, however; no problems there.
I would check you "in_features = [mbg, cents]" seems that is the issue and maybe not quite the correct format that is wants in script.
Finally got it to work by carefully formatting the fully qualified path names.
def execute(self, parameters, messages): """Execute linear orientation analysis.""" input = parameters[0].valueAsText baseName = arcpy.Describe(input).baseName basePath = os.path.split(arcpy.Describe(input).catalogPath)[0] arcpy.env.workspace = basePath #overwrite doesn't work, tool still fails if output already exists arcpy.env.overwriteOutput = True #output names mbg = "{0}_MBG".format(baseName) cents = "{0}_centroids".format(baseName) intersectOutput = "{0}_MBG_Intersect".format(baseName) #output arcpy.MinimumBoundingGeometry_management(input, mbg, "CONVEX_HULL", "NONE", "#", "MBG_FIELDS") arcpy.FeatureToPoint_management(input, cents, "INSIDE") #======================================================================= arcpy.Intersect_analysis(in_features = [r'{0}\\{1}'.format(basePath, mbg),r'{0}\\{1}'.format(basePath, cents)], out_feature_class = intersectOutput, join_attributes = "ALL", cluster_tolerance = "-1 Unknown", output_type="POINT") #======================================================================= return
Nothing I tried using single slashes worked, the intersect tool apparently needed '\\' regardless of whether or not you passed a raw string using 'r' or not. How obscure is that...