本文介绍了使用基于函数输出的值创建栅格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个函数根据输入斜率和距离计算价格。我想将价格写入栅格作为栅格值。我怎么做? OpenSource和ArcMap解决方案可以工作。 您可以在 R 中轻松完成此操作。我建议你下载并安装它(它是免费的并且是开源的)。你唯一需要做的就是研究如何在R中编写你的价格函数,这就是为什么我建议你发布代码。一旦你定义了pricefunc,你就可以从R命令行运行这些命令。 #安装所需的软件包 install.packages(c(raster,spatstat,sp,rgdal),dep = TRUE) #加载所需的软件包 require(栅格)需要(spatstat) require(sp) require(rgdal) #读取数据文件(您可能需要在此修改目录路径,R默认为查看您的$ USERHOME $目录R使用/ not \来分隔目录 slp< - 栅格(slope.tif)道路< - readShapeLines(road.shp) #从空间线创建点线段模式 distPSP #斜坡栅格值 slpPPP #计算每个单元距线的距离距离< - nncross( slpPPP,distPSP) #使用calcualted dista创建栅格 rDist 值(rDist)< - 距离 #在这里定义你的princefunc()。它应该采用两个输入值,斜率和距离并返回一个值,我称之为价格 pricefunc< - 函数(slp,dist){ ...我的代码 .. 。更多代码 ...更多代码返回(价格)} #使用您的价格函数计算价格栅格并保存为输出。 tif rPrice< - overlay(slp,rDist,fun = function(x,y){pricefunc(x,y)},filename =output.tif) I have a function that calculates a price based on the input slope and distance. I want to write the price to a raster as the rastervalue. How do I do that? OpenSource and ArcMap solutions would work.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 解决方案 You can do this pretty easily in R. I recommend you download and install it (it's free and Open Source). The only thing you will have to do is to work out how to code your price function in R which is why I suggested you post that code. Once you have your pricefunc defined you can then run these commands from the R command line.# Install required packagesinstall.packages( c("raster" , "spatstat" , "sp" , "rgdal") , dep = TRUE )# Load required packagesrequire( 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 directoriesslp <- raster( "slope.tif" )roads <- readShapeLines( "road.shp" )# Create point segment pattern from Spatial LinesdistPSP <- as.psp( roads )# Create point pattern from slope raster valuesslpPPP <- as.ppp( values(slp) )# Calculate distances from lines for each celldistances <- nncross( slpPPP , distPSP )# Create raster with calcualted distancesrDist <- 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 pricepricefunc <- function( slp , dist ){ ...my code ... more code ...more code return( price )}# Calculate price raster using your price function and save as output.tifrPrice <- overlay( slp , rDist , fun = function( x , y ){ pricefunc( x , y ) } , filename = "output.tif" ) 这篇关于使用基于函数输出的值创建栅格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-15 16:06