AE中柵格計算的問題

2022-08-01 15:57:10 字數 3554 閱讀 3082

話說今天有人問我關於影像 raster 計算問題..

給偶了一串很長的公式, 問我要怎麼方便計算..

像 10 - ( alayer * blayer ) / clayer + dlayer * 0.11 + tan ( elayer ) * cos ( flayer )

偶就跟他說用 spatial analysis 中的 raster calculator  的方式去計算就 ok 了ㄚ.

可是對方跟偶說是要動態的, 要去設計視窗給 user 作. 圖層不一定..

好吧.. 就想說之前有作過 透過 mathop 的方式來設計這串公式.

之前偷是透過 mathop 這個 function 搞 times 乘 plus 加, 當然也有 tan , cos 等三角函式...

由於 mathop 的引數都是兩個 geodataset 的物件, 針對於 10 引數的話..

一種就是建乙個 const 為 10 的 raster  資料.. 再去加減..

或是透過 ipixelblock 的方式去計算影像的資料.. 

搞的規模很龐大.. 搞的天昏地案日月無光. 搞的乙個頭兩個大...

程式就越寫越多. function 就越搞越雜..

寫個漏漏長的幾千行程式後發現.... 發現....

底下是很笨很笨的下去慢慢算..

dim pmathop as imathop

set pmathop = new rastermathops

dim presultdataset as igeodataset

set presultdataset = new rasterdataset

set presultdataset = pmathop.times(prmlayer.raster, pkmlayer.raster)

set presultdataset = pmathop.div(presultdataset, pslayer.raster)

set presultdataset = pmathop.atan(presultdataset)

然後針對那些引數的加減乘除..

public function rasterparamcalc(presultdataset as igeodataset, ctype as string, fnum as double) as igeodataset

dim ptmplayer as irasterlayer

set ptmplayer = new rasterlayer

ptmplayer.createfromraster presultdataset

dim prasprops as irasterprops

set prasprops = ptmplayer.raster

dim ppb as ipixelblock3

dim ppnt as ipnt

set ppnt = new pnt

ppnt.setcoords prasprops.width, prasprops.height

set ppb = ptmplayer.raster.createpixelblock(ppnt)

if ppb is nothing then

msgbox "影像資料無法取得pixelblock.."

exit function

end if

'dim prawpixels as irawpixels

ppnt.x = 0

ppnt.y = 0

ptmplayer.raster.read ppnt, ppb

dim v as variant

v = ppb.pixeldata(0)

dim m, n as integer

for m = 0 to ppb.width - 1

for n = 0 to ppb.height - 1

if (v(m, n) < 65535 and v(m, n) > -65535) then

if ctype = "+" then set v(m, n) = v(m, n) + cdbl(fnum)

if ctype = "-" then set v(m, n) = v(m, n) - cdbl(fnum)

if ctype = "*" then v(m, n) = v(m, n) * cdbl(fnum)

if ctype = "/" then v(m, n) = v(m, n) / cdbl(fnum)

end if

next n

next m

ppb.pixeldata(0) = v

set v = nothing

'write the pixel block with a (0,0) offset of the upper left corner

dim prasteredit as irasteredit

set prasteredit = ptmplayer.raster

if prasteredit is nothing then

msgbox "影像資料無法取得編輯狀態.."

exit function

end if

ppnt.x = 0

ppnt.y = 0

prasteredit.write ppnt, ppb

set rasterparamcalc = prasteredit

set ptmplayer = nothing

set prasprops = nothing

set ppb = nothing

set ppnt = nothing

set v = nothing

set prasteredit = nothing

end function

忙了好好好好長的一陣子後發現.. 有個神奇的 imapalgebraop

就像 ratsercalculate  可以直接就給他算下企...

天ㄚ.. 我是在作啥...

dim pmapalgebraop as imapalgebraop

set pmapalgebraop = new rastermapalgebraop

pmapalgebraop.bindraster palayer, "a"

pmapalgebraop.bindraster pblayer, "b"

pmapalgebraop.bindraster pclayer, "c"

pmapalgebraop.bindraster pelayer, "e"        

pmapalgebraop.bindraster pflayer, "f"

dim pcalcds as igeodataset

set pcalcds = new rasterdataset

set pcalcds = pmapalgebraop.execute(

" 1 + ( [a] / ( ( [e] + 10 ) * [i] * [d] * cos([f]) * atan( [b])) ")

c#**:

private void rastercaculator(string path) 

關於ArcGIS10 0中的柵格計算中的函式

版本公升級確實很重要,在arcgis10.1中計算成功的,在10.0 了問題。在進行柵格計算時,計算公式很簡單,包括兩個ln函式 22.73 11.1 ln 5 0.34 ln 人口.tif 可計算結果報錯 000539 python 錯誤訊息。error running expression rc...

AE開發中遇到的一些問題!

1.scenecontrol開發,如何儲存sxd文件,或者如何儲存場景資訊?2.在scenecontrol中繪製點 線要素是否必須加裝sxd文件?是否因為scenecontrol中的某些參量必須通重載入sxd文件來初始化。3.scenecontrol自定義圖層技術,在axmapcontrol中載入自...

ArcGIS中柵格空值計算與替換方法

在研究或工作中,經常會遇到柵格資料中某些像元資料缺失或者不能被使用,也會因為異常值而將部分像元定義為空值 nodata 再此情況下,我們需要重新計算空值像元中正常值,從某種意義上也是對空值像元的內向插值。整體思路是根據空值像元周圍值來計算空值像元,類似於線性內插。具體方法如下 1 首先確定空值柵格資...