I'm trying to use the intersect tool, with one of my inputs being from a get parameter as text. As I don't have an advanced licence I have to iterate through the list to run the intersect on each item in the list.
However, there is something about the input into the intersect analysis it doesnt like. I get the error message:
Traceback (most recent call last): File "\DRBS-NAS01\ueec\GIS100円 MT testing\BufferTest\Scripts\Intersection batch.py", line 37, in arcpy.Intersect_analysis(Des4, DirectAndIndirect + "\test2", "ALL") File "c:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\analysis.py", line 334, in Intersect raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Features: Dataset SOBLayer #;'\DRBS-NAS01\ueec\GIS100円 MT testing\BufferTest\Data\Designations\Ancient_Woodland_England.shp' # does not exist or is not supported Failed to execute (Intersect).
import arcpy
import os
## Working folders
WorkingDir = os.getcwd() ## To go up more directories: os.getcwd()
os.path.dirname(os.getcwd()); os.chdir(os.path.dirname(os.getcwd()))
DesDir = WorkingDir + "\\Data\\Designations"
OutputDir = WorkingDir + "\\Data\\Outputs"
Interim = OutputDir + "\\Interim"
DirectAndIndirect = OutputDir + "\\DirectAndIndirect"
if not os.path.exists(DirectAndIndirect):
os.makedirs(DirectAndIndirect)
SiteOptions = arcpy.GetParameterAsText(0)
SiteOptionsBuffers = arcpy.GetParameterAsText(1)
DesList1 = arcpy.GetParameterAsText(2)
DesList2 = DesList1.split(';')
DesBufferList = arcpy.GetParameterAsText(3)
arcpy.MakeFeatureLayer_management(SiteOptionsBuffers, "SOBLayer")
query = '"IndImpBuff" = {}'.format(DesBufferList)
arcpy.SelectLayerByAttribute_management("SOBLayer","NEW_SELECTION", query)
Des4 = ["SOBLayer"]
for Des1 in DesList2:
Des2 = os.path.basename(Des1)
Des4.append(Des1)
arcpy.Intersect_analysis(Des4, DirectAndIndirect + "\\test2", "ALL")
Could someone suggest what the problem with the Intersect input is please?
-
1Try creating variables for the inputs of the intersect and use print statements to see if they're what you expect. Or, since this is being run as a script tool, use AddMessage.Ebingsya– Ebingsya2022年05月05日 14:35:35 +00:00Commented May 5, 2022 at 14:35
-
1You can use arcpy.Exists to check if the datasets exist.Ahmad Raji– Ahmad Raji2022年05月05日 16:00:56 +00:00Commented May 5, 2022 at 16:00
1 Answer 1
Thanks for the comments. It's led me to a solution. The AddMessage was showing that in the DesList2 it was listing the dataset as:
u"'\DRBS-NAS01\ueec\GIS100円 MT testing\BufferTest\Data\Designations\Ancient_Woodland_England.shp'"
A bit of digging, and for reasons I dont understand, changing my loop as follows got it working:
for Des1 in DesList2:
Des2 = os.path.basename(Des1)
Des6 = Des1[1:-1].encode()
Des4.append(Des6)
arcpy.Intersect_analysis(Des4, DirectAndIndirect + "\\test2", "ALL")
Explore related questions
See similar questions with these tags.