for loop problem for beginner [message #93808] |
Tue, 25 October 2016 04:38  |
Suresh Negi
Messages: 28 Registered: August 2016
|
Junior Member |
|
|
Hi, I have one image of size 91x76 in which there are values at some point and rest are zeros. So I want to extract only values and wana save them in column of csv format.
here b1 is the raster image to which i want to save in array a.
But not working please help...and how to save result in csv format so that I can get the values in excel column.
e = ENVI()
file = 'C:\Auto_Classification\Delhi\A10.tif'
raster = e.OpenRaster(file)
b1 = raster.GetData(BANDS=[0])
help,b1
a= intarr(1000)
k=0
for i=0,90,1 do for j=0,75 do begin
if (b1(i,j) ne 0) then begin
a(k)=b1(i,j)
k=k+1
endif
endfor
print,a
end
|
|
|
Re: for loop problem for beginner [message #93809 is a reply to message #93808] |
Tue, 25 October 2016 04:48   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Tuesday, October 25, 2016 at 1:38:07 PM UTC+2, Sanu wrote:
> Hi, I have one image of size 91x76 in which there are values at some point and rest are zeros. So I want to extract only values and wana save them in column of csv format.
> here b1 is the raster image to which i want to save in array a.
> But not working please help...and how to save result in csv format so that I can get the values in excel column.
>
> e = ENVI()
> file = 'C:\Auto_Classification\Delhi\A10.tif'
> raster = e.OpenRaster(file)
> b1 = raster.GetData(BANDS=[0])
> help,b1
> a= intarr(1000)
> k=0
> for i=0,90,1 do for j=0,75 do begin
> if (b1(i,j) ne 0) then begin
> a(k)=b1(i,j)
> k=k+1
> endif
> endfor
> print,a
> end
Hi,
have a look at the where() function. It does what you did in the loop, just much much better:
http://www.harrisgeospatial.com/docs/WHERE.html
You will find some examples that will get you going.
Cheers,
Helder
|
|
|
Re: for loop problem for beginner [message #93811 is a reply to message #93809] |
Wed, 26 October 2016 04:19   |
Suresh Negi
Messages: 28 Registered: August 2016
|
Junior Member |
|
|
On Tuesday, October 25, 2016 at 5:19:02 PM UTC+5:30, Helder wrote:
> On Tuesday, October 25, 2016 at 1:38:07 PM UTC+2, Sanu wrote:
>> Hi, I have one image of size 91x76 in which there are values at some point and rest are zeros. So I want to extract only values and wana save them in column of csv format.
>> here b1 is the raster image to which i want to save in array a.
>> But not working please help...and how to save result in csv format so that I can get the values in excel column.
>>
>> e = ENVI()
>> file = 'C:\Auto_Classification\Delhi\A10.tif'
>> raster = e.OpenRaster(file)
>> b1 = raster.GetData(BANDS=[0])
>> help,b1
>> a= intarr(1000)
>> k=0
>> for i=0,90,1 do for j=0,75 do begin
>> if (b1(i,j) ne 0) then begin
>> a(k)=b1(i,j)
>> k=k+1
>> endif
>> endfor
>> print,a
>> end
>
> Hi,
> have a look at the where() function. It does what you did in the loop, just much much better:
> http://www.harrisgeospatial.com/docs/WHERE.html
> You will find some examples that will get you going.
>
> Cheers,
> Helder
Hi but I did'nt get the results.Please help me in making this program.
|
|
|
Re: for loop problem for beginner [message #93812 is a reply to message #93811] |
Wed, 26 October 2016 04:27  |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Wednesday, October 26, 2016 at 1:19:44 PM UTC+2, Sanu wrote:
> On Tuesday, October 25, 2016 at 5:19:02 PM UTC+5:30, Helder wrote:
>> On Tuesday, October 25, 2016 at 1:38:07 PM UTC+2, Sanu wrote:
>>> Hi, I have one image of size 91x76 in which there are values at some point and rest are zeros. So I want to extract only values and wana save them in column of csv format.
>>> here b1 is the raster image to which i want to save in array a.
>>> But not working please help...and how to save result in csv format so that I can get the values in excel column.
>>>
>>> e = ENVI()
>>> file = 'C:\Auto_Classification\Delhi\A10.tif'
>>> raster = e.OpenRaster(file)
>>> b1 = raster.GetData(BANDS=[0])
>>> help,b1
>>> a= intarr(1000)
>>> k=0
>>> for i=0,90,1 do for j=0,75 do begin
>>> if (b1(i,j) ne 0) then begin
>>> a(k)=b1(i,j)
>>> k=k+1
>>> endif
>>> endfor
>>> print,a
>>> end
>>
>> Hi,
>> have a look at the where() function. It does what you did in the loop, just much much better:
>> http://www.harrisgeospatial.com/docs/WHERE.html
>> You will find some examples that will get you going.
>>
>> Cheers,
>> Helder
>
> Hi but I did'nt get the results.Please help me in making this program.
What results did you get? What code did you try?
h
|
|
|