Traceback (most recent call last): File…
- User
Traceback (most recent call last): File "D:\arcgis10.5\Desktop10.5\ArcPy\arcpy\sa\Utils.py", line 53, in swapper result = wrapper(*args, **kwargs) File "D:\arcgis10.5\Desktop10.5\ArcPy\arcpy\sa\Functions.py", line 7197, in Wrapper out_raster) File "D:\arcgis10.5\Desktop10.5\ArcPy\arcpy\geoprocessing_base.py", line 510, in return lambda *args: val(*gp_fixargs(args, True)) arcgisscripting.ExecuteError: ERROR 999999: Error executing function. Failed to execute (ExtractByMask).
- Assistant
The error message indicates that there was an error executing the function "ExtractByMask" in ArcPy. However, the specific cause of the error is not provided in the traceback. To troubleshoot this issue, you can try the following steps:
-
Check the inputs: Make sure that the input rasters and the mask feature are valid and accessible. Check if the paths are correct and if the data exists.
-
Verify the data types: Ensure that the input raster and mask feature have compatible data types and coordinate systems. Incompatible data types or coordinate systems can cause errors.
-
Check for overlapping extents: Confirm that the spatial extent of the input raster and the mask feature overlap. If they don't overlap, the extraction cannot occur and will result in an error.
-
Check the license: Ensure that you have the necessary licensing for the Spatial Analyst extension, which is required for the ExtractByMask function to work. If you don't have the license, you may need to obtain it or use an alternative method.
-
- User
-- coding: UTF-8 --
import arcpy import glob import os
'''
批量裁剪:
对输入文件夹下的数据,根据 shp 文件,进行批量裁剪,结果存放于输出文件夹
需要修改:
inws:输入路径(必选)
outws:输出路径(必选)
mask:参考范围的 shp 文件(必选)
nameT:建议进行规范化,文件名的易读性(可选)
'''
arcpy.CheckOutExtension('Spatial')
输入路径 应该注意,中文路径,会导致读不出文件
inws = (r"F:\tif\wushenqi\tif\vci_drought\nwushenqi_vci3-20230817T062019Z-001\nwushenqi_vci3")
输出路径
outws = (r"F:\tif\wushenqi\data\3\3_vci")
指定 shp 范围边界文件,即目标区域的边界
mask = (r"F:\tif\wushenqi\shp\split\3\8735.shp")
利用 glob 包,将 inws 下的所有 tif 文件读存放到 rasters 中
rasters = glob.glob(os.path.join(inws, "*.tif"))
循环 rasters 中的所有影像,进行按掩模提取操作
for ras in rasters: # nameT:输出文件名 nameT = os.path.basename(ras) + "_clp.tif"
- Assistant
这个错误提示显示在执行
arcpy.sa.ExtractByMask函数时出现了问题。为了解决这个问题,你可以尝试以下几个步骤:-
检查路径和文件:确保输入路径和输出路径都是有效的,并且文件存在。特别注意中文路径可能会导致读取文件失败。
-
检查数据类型和坐标系:确保输入的栅格数据和掩膜(shp 文件)具有兼容的数据类型和坐标系。不兼容的数据类型或坐标系可能导致错误。
-
检查栅格数据和掩膜的空间范围:确认输入的栅格数据和掩膜(shp 文件)的空间范围是否有重叠。如果没有重叠,提取操作将无法执行并导致错误。
-
检查许可证:确保你拥有 Spatial Analyst 扩展的许可证,该扩展对于执行 ExtractByMask 函数是必需的。如果没有该扩展的许可证,你可能需要获取许可证或使用其他方法。
-
检查 ArcPy 版本和兼容性:如果你使用的 ArcPy 版本与 ArcGIS 的版本不兼容,可能会导致该函数出错。确保 ArcPy 版本与 ArcGIS 版本相匹配。
除了这些步骤之外,你还可以尝试在提取之前对输入的栅格数据和掩膜进行预处理,例如转换数据类型、重新投影等操作,以确保数据的一致性和兼容性。
如果以上步骤无法解决问题,建议提供更多问题的细节,例如具体的错误信息、输入数据的示例等,以便更好地帮助你解决问题。
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.