Hi everyone in ESRI community!
I have an code below utilized IPixelBlock3. however it was an older ESRI 9.3 version i believe. I do not know why the pixel block in the final array does not take set value any other than SByte. But my data needs to be Byte. The legitimate range of my pixel values extends outside the range of sbyte . It seems like something upstream in how pixeldata0 is declared or initialized from pblock_03, that passed to the setvalue call are causing it to only want an sbyte. i Do not know if IPixelBlock3 got changed in ESRI 10.5 version. the code are as below if any body can help to see and help me out?
the error is happening at the end of the scripts where i have comments.
```
System<SPAN class="punctuation token">.</SPAN>Array pixelDatao<SPAN class="punctuation token">;</SPAN>
DateTime dt1 <SPAN class="operator token">=</SPAN> DateTime<SPAN class="punctuation token">.</SPAN>Now<SPAN class="punctuation token">;</SPAN>
tspre <SPAN class="operator token">=</SPAN> dt1 <SPAN class="operator token">-</SPAN> dt0<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">int</SPAN> jtile <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> jtile <SPAN class="operator token"><</SPAN> nytiles<SPAN class="punctuation token">;</SPAN> jtile<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">int</SPAN> itile <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> itile <SPAN class="operator token"><</SPAN> nxtiles<SPAN class="punctuation token">;</SPAN> itile<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">// have we gone into raster 2 area yet, or have finished with it</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>ytile <SPAN class="operator token">*</SPAN> <SPAN class="punctuation token">(</SPAN>jtile <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> yoff1<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">&&</SPAN> <SPAN class="punctuation token">(</SPAN>ytile <SPAN class="operator token">*</SPAN> jtile <SPAN class="operator token"><</SPAN> <SPAN class="punctuation token">(</SPAN>nrowo <SPAN class="operator token">-</SPAN> yoff2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>xtile <SPAN class="operator token">*</SPAN> <SPAN class="punctuation token">(</SPAN>itile <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> xoff1<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">&&</SPAN> <SPAN class="punctuation token">(</SPAN>xtile <SPAN class="operator token">*</SPAN> itile <SPAN class="operator token"><</SPAN> <SPAN class="punctuation token">(</SPAN>ncolo <SPAN class="operator token">-</SPAN> xoff2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
DateTime dt00 <SPAN class="operator token">=</SPAN> DateTime<SPAN class="punctuation token">.</SPAN>Now<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">int</SPAN> xpt <SPAN class="operator token">=</SPAN> itile <SPAN class="operator token">*</SPAN> xtile<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">int</SPAN> ypt <SPAN class="operator token">=</SPAN> jtile <SPAN class="operator token">*</SPAN> ytile<SPAN class="punctuation token">;</SPAN>
tlco<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetCoords</SPAN><SPAN class="punctuation token">(</SPAN>xpt<SPAN class="punctuation token">,</SPAN> ypt<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
rRastero<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Read</SPAN><SPAN class="punctuation token">(</SPAN>tlco<SPAN class="punctuation token">,</SPAN> pBlocko<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// Get target pixeldata array </SPAN>
IPixelBlock3 pBlocko_3 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>IPixelBlock3<SPAN class="punctuation token">)</SPAN>pBlocko<SPAN class="punctuation token">;</SPAN>
pixelDatao <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>System<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">)</SPAN>pBlocko_3<SPAN class="punctuation token">.</SPAN><SPAN class="token function">get_PixelDataByRef</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">int</SPAN> xpt2 <SPAN class="operator token">=</SPAN> xtile <SPAN class="operator token">*</SPAN> itile <SPAN class="operator token">-</SPAN> xoff1<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">int</SPAN> ypt2 <SPAN class="operator token">=</SPAN> ytile <SPAN class="operator token">*</SPAN> jtile <SPAN class="operator token">-</SPAN> yoff1<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>ypt2 <SPAN class="operator token"><</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> ypt2 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>xpt2 <SPAN class="operator token"><</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> xpt2 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN>
tlc2<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetCoords</SPAN><SPAN class="punctuation token">(</SPAN>xpt2<SPAN class="punctuation token">,</SPAN> ypt2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
rRaster2<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Read</SPAN><SPAN class="punctuation token">(</SPAN>tlc2<SPAN class="punctuation token">,</SPAN> pBlock2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// Get target pixel data array </SPAN>
IPixelBlock3 pBlock2_3 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>IPixelBlock3<SPAN class="punctuation token">)</SPAN>pBlock2<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// pixelData2 = (System.Array)pBlock2_3.get_PixelData(0);</SPAN>
DateTime dt01 <SPAN class="operator token">=</SPAN> DateTime<SPAN class="punctuation token">.</SPAN>Now<SPAN class="punctuation token">;</SPAN>
tsread <SPAN class="operator token">=</SPAN> tsread <SPAN class="operator token">+</SPAN> <SPAN class="punctuation token">(</SPAN>dt01 <SPAN class="operator token">-</SPAN> dt00<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//loop through each pixel in the pixelblock and do calculation</SPAN>
<SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">int</SPAN> y <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> y <SPAN class="operator token"><</SPAN> pBlocko_3<SPAN class="punctuation token">.</SPAN>Height<SPAN class="punctuation token">;</SPAN> y<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">int</SPAN> x <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> x <SPAN class="operator token"><</SPAN> pBlocko_3<SPAN class="punctuation token">.</SPAN>Width<SPAN class="punctuation token">;</SPAN> x<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">// check to see if it's a valid data point</SPAN>
<SPAN class="keyword token">object</SPAN> oval1 <SPAN class="operator token">=</SPAN> pBlocko_3<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetVal</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> x<SPAN class="punctuation token">,</SPAN> y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">object</SPAN> oval2 <SPAN class="operator token">=</SPAN> pBlock2_3<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetVal</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> x<SPAN class="punctuation token">,</SPAN> y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">object</SPAN> oval3 <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//object val3 = null;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>oval1 <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">// access buffers from cutnodes might stretch beyond county buffer zone</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>xpt <SPAN class="operator token">+</SPAN> x <SPAN class="operator token">>=</SPAN> xoff1 <SPAN class="operator token">&&</SPAN> xpt <SPAN class="operator token">+</SPAN> x <SPAN class="operator token"><</SPAN> ncolo <SPAN class="operator token">-</SPAN> xoff2 <SPAN class="operator token">&&</SPAN>
ypt <SPAN class="operator token">+</SPAN> y <SPAN class="operator token">>=</SPAN> yoff1 <SPAN class="operator token">&&</SPAN> ypt <SPAN class="operator token">+</SPAN> y <SPAN class="operator token"><</SPAN> nrowo <SPAN class="operator token">-</SPAN> yoff2<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">int</SPAN> x2 <SPAN class="operator token">=</SPAN> xpt <SPAN class="operator token">+</SPAN> x <SPAN class="operator token">-</SPAN> xoff1 <SPAN class="operator token">-</SPAN> xpt2<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">int</SPAN> y2 <SPAN class="operator token">=</SPAN> ypt <SPAN class="operator token">+</SPAN> y <SPAN class="operator token">-</SPAN> yoff1 <SPAN class="operator token">-</SPAN> ypt2<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//object oval2 = pBlock2_3.GetVal(0, x2, y2);</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>oval2 <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">int</SPAN> val1 <SPAN class="operator token">=</SPAN> Convert<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToByte</SPAN><SPAN class="punctuation token">(</SPAN>oval1<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">int</SPAN> val2 <SPAN class="operator token">=</SPAN> Convert<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToByte</SPAN><SPAN class="punctuation token">(</SPAN>oval2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">int</SPAN> val3 <SPAN class="operator token">=</SPAN> accval<SPAN class="punctuation token">[</SPAN>val2<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> val1<SPAN class="punctuation token">;</SPAN>
oval3 <SPAN class="operator token">=</SPAN> Convert<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToByte</SPAN><SPAN class="punctuation token">(</SPAN>val3<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
pixelDatao<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetValue</SPAN><SPAN class="punctuation token">(</SPAN>oval3<SPAN class="punctuation token">,</SPAN> x<SPAN class="punctuation token">,</SPAN> y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="comment token">// this is where the error is (oval3 need to be byte, however PixelDatao is only taken SByte , i tried to change the above scripts, but somehow pixelDatao just Sbyte. i want it to be Byte)</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
pBlocko_3<SPAN class="punctuation token">.</SPAN><SPAN class="token function">set_PixelData</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> pixelDatao<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
DateTime dt02 <SPAN class="operator token">=</SPAN> DateTime<SPAN class="punctuation token">.</SPAN>Now<SPAN class="punctuation token">;</SPAN>
tsup <SPAN class="operator token">=</SPAN> tsup <SPAN class="operator token">+</SPAN> <SPAN class="punctuation token">(</SPAN>dt02 <SPAN class="operator token">-</SPAN> dt01<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
rRastero<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Write</SPAN><SPAN class="punctuation token">(</SPAN>tlco<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN>IPixelBlock<SPAN class="punctuation token">)</SPAN>pBlocko_3<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
DateTime dt03 <SPAN class="operator token">=</SPAN> DateTime<SPAN class="punctuation token">.</SPAN>Now<SPAN class="punctuation token">;</SPAN>
tswrite <SPAN class="operator token">=</SPAN> tswrite <SPAN class="operator token">+</SPAN> <SPAN class="punctuation token">(</SPAN>dt03 <SPAN class="operator token">-</SPAN> dt02<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>```