区域统计输出修复

问题描述 投票:0回答:1

我遇到的问题是,当我尝试使用 {rounded_percent} 格式化我想要的表的文件输出路径时,我无法运行区域统计信息并创建表。我希望将四舍五入的百分比值包含在表名称中。我不是Python专家,也不是在ArcPro中使用它的专家,所以我可能会错过一些非常简单的东西。下面我有一些 python 行,我一直在尝试在 ArcPro 上的 python 窗口中运行它们。如果您发现我做错了什么,请告诉我。谢谢

`# 故障排除 导入arcpy 从 arcpy.sa 导入 *

# Set input raster paths
timberland_raster = "C:\\Users\\...\\AcreageAnalysis.gdb\\Timberland_Acreage_County"
mort_pct_raster = "C:\\Users\...\\AcreageAnalysis.gdb\\MORT_PCT_AC"
county_boundary = "C:\\Users\\...\\AcreageAnalysis.gdb\\FIA_Landcover_OK_2015"
# Create binary mask for a specific percentage (for testing)
percentage = 3.700668297952402
binary_mask = Con(Raster(mort_pct_raster) == percentage, 1, 0)

# Multiply binary mask with timberland raster
affected_timberland_raster = timberland_raster * binary_mask

# Round the percentage value to three decimal places
rounded_percent = round(percentage, 3)

# Calculate zonal statistics for the affected timberland raster

# Output folder for the table
out_table = "C:\\Users\\...\\GIS\\AnalysisOutput\\tbl_{rounded_percent}.dbf".format(rounded_percent)
out_stat = ZonalStatisticsAsTable(county_boundary, "CNTY_FIPS", affected_timberland_raster, out_table, "DATA", "SUM")

print("Zonal statistics calculation completed.")


# This script works for creating a table and calculating zonal statistics on one percentage if the output table is named "tbl.dbf"
# out_table = "C:\\Users\\...\\GIS\\AnalysisOutput\\tbl.dbf"`


I have tried formatting the file output path with `"\\tbl_{0:.3f}.dbf".format(rounded_percent)` or using f-strings (as I believe they're called) like `f"C:\\Users\\...\\GIS\\AnalysisOutput\\tbl_{rounded_percent}.dbf"`

python gis arcgis
1个回答
0
投票

在 ArcGIS Pro 中运行此命令,看起来输出表名称不允许句点。用另一个字符替换四舍五入百分比的句点应该可以。

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.