0

我有一个根据输入斜率和距离计算价格的函数。我想将价格作为栅格值写入栅格。我怎么做?OpenSource 和 ArcMap 解决方案可以工作。

slopeRaster = "slope.tif"
emptyRaster = "emptyraster.tif" # How do I create an empty raster?
road = "road.shp"

for cell in emptyraster:
    # get slope from sloperaster at cell location
    ...
    slope = ...

    # get distance to nearest road from center of cell
    ...
    distance = ...

    # calculate price for cell
    price = pricefunc(slope, distance)

    # write price to cell as value  # How do I write a value to a raster
4

1 回答 1

3

您可以在R. 我建议您下载并安装它(它是免费且开源的)。您唯一需要做的就是弄清楚如何在 R 中编写价格函数,这就是我建议您发布该代码的原因。一旦你定义了价格函数,你就可以从 R 命令行运行这些命令。

# Install required packages
install.packages( c("raster" , "spatstat" , "sp" , "rgdal") , dep = TRUE )

# Load required packages
require( raster )
require( spatstat )
require( sp )
require( rgdal )

# Read in your data files (you might have to alter the directory paths here, the R default is to look in your $USERHOME$ directory R uses / not \ to delimit directories
slp <- raster( "slope.tif" )
roads <- readShapeLines( "road.shp" )


# Create point segment pattern from Spatial Lines
distPSP <- as.psp( roads )


#   Create point pattern from slope raster values
slpPPP <- as.ppp( values(slp) )


#   Calculate distances from lines for each cell
distances <- nncross( slpPPP , distPSP )


# Create raster with calcualted distances
rDist <- raster( slp )
values( rDist ) <- distances


# Define your princefunc() here. It should take two input values, slope and distance and return one value, which I have called price
pricefunc <- function( slp , dist ){
    ...my code
        ... more code
    ...more code
    return( price )
}


# Calculate price raster using your price function and save as output.tif
rPrice <- overlay( slp , rDist , fun = function( x , y ){ pricefunc( x , y ) } , filename = "output.tif" ) 
于 2013-03-14T18:06:40.330 回答