下午好,的ArcGIS SelectLayerByLocation_managerment錯誤000368:無效的輸入數據
我一直在敲打我的頭撞牆試圖讓arcpy.SelectLayerByLocation_managerment工作,不能找到一個解決辦法 - 我使用ArcMap /目錄10.2。
我有一個大的折線數據集,我試圖分割幾個單獨的多邊形圖層文件。這個想法是,腳本將循環訪問圖層文件,選擇座標在X米內的多段線部分並將它們導出到單獨的文件夾。這裏是我的代碼:
arcpy.AddMessage("\n Checking Script for Errors...")
#Script to split one layer (OSMM/OSVML) into parts, parts defined by another layer.
import arcpy
import os
#References users Map document - get parameter input from prompt
mxd = arcpy.mapping.MapDocument(arcpy.GetParameterAsText(0))
df = arcpy.mapping.ListDataFrames(mxd, "Frame")[0]
arcpy.env.workspace = arcpy.GetParameterAsText(1)
#For loop to iterate through all layers in dataframe
for lyr in arcpy.mapping.ListLayers(mxd,"",df):
#Get layer name
layerName = lyr.name
#Skip the OS File
if layerName == "OSMM_Line_Detail":
arcpy.AddMessage("\n Skipping " + layerName)
else:
#Inform users of layer being processed
arcpy.AddMessage("\n Processing: " + layerName)
#Select the wanted layer that is within a distance of the current layer
arcpy.AddMessage("\n Select by location")
arcpy.SelectLayerByLocation_management('OSMM_Line_Detail',"WITHIN_A_DISTANCE",layerName,arcpy.GetParameterAsText(3),"NEW_SELECTION")
#Create directory for file (http://desk.stinkpot.org:8080/tricks/index.php/2006/07/create-a-directory-in-python/)
dirname = ("C:\Users\USERNAME\Documents\Test Data\Basemapping and Boundary Data\Split line by area\Line " + layerName)
if not os.path.isdir(dirname + "/"):
arcpy.AddMessage("\n Directory not found, creating directoy for: " + layerName)
os.mkdir(dirname + "/")
#Exports the selection of layer to new directory
arcpy.FeatureClassToShapefile_conversion(arcpy.GetParameterAsText(2), ""C:\Users\USERNAME\Documents\Test Data\Basemapping and Boundary Data\Split line by area\Line " + layerName)
arcpy.AddMessage("\n Completed split for " + layerName)
arcpy.AddMessage("\n Script complete")
#delete variables created
del lyr
del df
del mxd
#script ends
我目前收到的錯誤代碼:
Traceback (most recent call last):
File "C:\Users\Richard.Lauberts\Documents\LIS Data\Toolbox and Scripts\Python Script for Splitting MasterMap by Site.py", line 26, in <module>
arcpy.SelectLayerByLocation_management('OSMM_Line_Detail',"WITHIN_A_DISTANCE",layerName,'110 Meters',"NEW_SELECTION")
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6618, in SelectLayerByLocation
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000368: Invalid input data.
Failed to execute (SelectLayerByLocation).
我已經將文件導出到一個地理數據庫,並重新來源的圖層,我曾嘗試使用ArcPy中。 MakeFeatureLayer_management建議在其他一些職位,試圖硬編碼的文件名稱,而不是使用GetParameterAsTest,似乎沒有任何幫助!
對於代碼中距離值的輸入,我嘗試過「110」,「110米」,「110米」,並將其作爲getParameters(在arc工具箱界面中設置爲線性值)用戶挑選長度和單位)。
任何建議將不勝感激。
前面的錯別字:錯位「」倒數第二行。您可能需要「C:\ Users \」等的「r」前面。讓python從字面上讀取\字符。 –