import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
# Run WeightedSum
outWeightedSum = WeightedSum(WSTable([["snow", "VALUE", 0.25], ["land", "VALUE",0.25],
["soil", "VALUE", 0.5]]))
outWeightedSum.save("C:/sapyexamples/output/outwsum")
WeightedSum 示例 2(独立脚本)
本示例通过将多个栅格合并到一起并应用适当的加权因子来创建适宜性栅格,用以为滑雪场地选址。
# Name: WeightedSum_Ex_02.py
# Description: Overlays several rasters multiplying each by their given
# weight and summing them together.
# Requirements: Spatial Analyst extension
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = "C:/sapyexamples/data"
# Set local variables
inRaster1 = "snow"
inRaster2 = "land"
inRaster3 = "soil"
WSumTableObj = WSTable([[inRaster1, "VALUE", 0.25], [inRaster2, "VALUE", 0.25],
[inRaster3, "VALUE", 0.5]])
# Run WeightedSum
outWeightedSum = WeightedSum(WSumTableObj)
# Save the output
outWeightedSum.save("C:/sapyexamples/output/weightsumout")