import arcpy.sa
arcpy.env.workspace = r"C:\Users\nhaddad\Desktop\project_8"
arcpy.env.overwriteOutput = True
altitude_cursor = arcpy.da.SearchCursor("solar_points", "Altitude")
azimuth_cursor = arcpy.da.SearchCursor("solar_points", "Azimuth")
for i,j in zip(altitude_cursor,azimuth_cursor):
output = arcpy.sa.Hillshade(r"C:\Users\nhaddad\Desktop\final_exam\worcester_dem", j[0], i[0], "SHADOWS", 0.348)
当我需要循环遍历表的10行并创建10个映射时,我只能创建一个输出映射。
发布于 2022-05-11 13:25:13
您从不保存您的山坡或将其添加到列表(或其他数据结构),以便稍后使用结果。您可以简单地使用output.save("/path/to/destination/file/name")
来保存山坡结果。
另外,在使用with
时,请使用arcpy.da.SearchCursor
确保游标在不再需要时再次关闭。此外,您不需要两个游标。
import os
import arcpy, arcpy.sa
DEM = r"C:\Input\Hillshade\worcester_dem"
SOLAR_POINTS_FOLDER = r"C:\Input\SolarPoints"
OUTPUT_FOLDER = r"C:\Output"
with arcpy.EnvManager(workspace=SOLAR_POINTS_FOLDER):
with arcpy.da.SearchCursor("solar_points", ["Azimuth", "Altitude"]) as cursor:
for azimuth, altitude in cursor:
output = arcpy.sa.Hillshade(DEM, azimuth, altitude, "SHADOWS", 0.348)
# either save file (or add it to an array for later use)
output.save( \
os.path.join(OUTPUT_FOLDER, f"worcester_{azimuth}_{altitude}"))
注意:上面的示例是从内存中编写的,没有经过测试/执行。
https://stackoverflow.com/questions/72146583
复制相似问题