comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Apply a shapefile to raster images in IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Apply a shapefile to raster images in IDL [message #41289] Sat, 02 October 2004 14:29 Go to next message
envi35 is currently offline  envi35
Messages: 8
Registered: October 2004
Junior Member
Dear Listers,
I'm a novice in IDL, not sure if my questions are totally improper. I
want to use an Arcview format shapefile as a mask, to a huge number of
raster images, which are in a polar stereographic grid format with
separate image data files and lat/lon files. I would really appreciate
if you could give me any hint about the following questions:

1. How to read the shapefile into an IDL variable?
2. How to tailor the shapefile to my raster image grid?
3. If the above questions are not proper or impossible in IDL, would
you give me some suggestions to do the work?

Thank you in advance,
Jenny
Re: Apply a shapefile to raster images in IDL [message #41318 is a reply to message #41289] Mon, 11 October 2004 13:29 Go to previous messageGo to next message
Jonathan Greenberg is currently offline  Jonathan Greenberg
Messages: 91
Registered: November 2002
Member
Jenny (and others):

We've been developing a "bridge" between raster and vector formats
(designed, primarily, for optimized extraction of raster data from vector
coverages) -- if anyone wants to check it out, go to
http://starspan.casil.ucdavis.edu/ -- this code is open source, and we'd
love to get feedback on it. Right now its designed for unix boxes (macos x
people shouldn't have TOO much of a problem compiling it), and its not for
the unix novice since I don't think we have a makefile at this point, but if
you'd like to check it out, please do!

--j


On 10/2/04 2:29 PM, in article
c371324e.0410021329.26d3e286@posting.google.com, "Jenny" <envi35@yahoo.ca>
wrote:

> Dear Listers,
> I'm a novice in IDL, not sure if my questions are totally improper. I
> want to use an Arcview format shapefile as a mask, to a huge number of
> raster images, which are in a polar stereographic grid format with
> separate image data files and lat/lon files. I would really appreciate
> if you could give me any hint about the following questions:
>
> 1. How to read the shapefile into an IDL variable?
> 2. How to tailor the shapefile to my raster image grid?
> 3. If the above questions are not proper or impossible in IDL, would
> you give me some suggestions to do the work?
>
> Thank you in advance,
> Jenny
Re: Apply a shapefile to raster images in IDL [message #41325 is a reply to message #41289] Fri, 08 October 2004 11:54 Go to previous messageGo to next message
envi35 is currently offline  envi35
Messages: 8
Registered: October 2004
Junior Member
Hi Everyone,
Thank you all very much. I've taken Chris+Lorenzo's suggestions, and
it works really well. Though just started to learn IDL a couple of
weeks ago, I found it is a golden mine, worthy to dig hard. :-(
With Fortran background, it seems not too hard for me to jump to IDL
direct graphics. Since the IDL object is more powerful, I think it is
time for me to learn object programming (really scared!). I'm
wondering if someone could give me some advices on how to start with
the object...

Best regards,
Jenny

lbusett@yahoo.it (Lorenzo Busetto) wrote in message news:<e4da268.0410070408.60d07040@posting.google.com>...
> Hi Jenny,
>
> If your images are all of the same size I think that you can solve
> your problem simply by using ENVI.
>
> 1: Open one of your images and load it in a display
> 2: Convert your shapefile to an ENVI vector file (EVF) by clicking
>> Vector > Open Vector File > Shapefile
> 3: Load your vector on the display where you have loaded your
> image (In the "available vectors list" select the vector, then click
> on "load" and then on "Diplay# (your_display)"
> 4:In the "Vector Parameters" window that appears, select "File >
> Export active layer to ROI"
> 5: Select "basic tools > masking > build mask" and select your
> display
> 6: Select "Options > Import ROIS", then select the ROI you created
> from your vector and click on "OK". Next, choose a name for the mask
> file that you want to create and click on "Apply". Now, in the
> "available bands list you should see a new image, which has value 0
> outside the vector and 1 inside it.
> 7: Now, you can use this "0-1" image as a mask for your image. Go
> to Basic tools > apply mask. Select one of the images that you want to
> mask, then click on "Select mask band" and select the mask image.
> Click on "OK".
>
> If you have many images and you don't want to repeat n-times the
> last step you can use an IDL procedure that automatically opens the
> images and apply the mask on each one.
> I think that something like this should work: it's a simple
> modification of the example program that you can find on the ENVI
> User's guide.
>
> pro multiple_mask
>
> ; Select input files (Select all your images)
>
> files_list = dialog_pickfile(/READ,title ='Select input$
> files',/multiple_files)
>
> ; Select the mask File
>
> mask_file = dialog_pickfile(/read, title = 'Select Mask File')
> envi_open_file, mask_file, r_fid=m_fid
>
> ; Count the number of files
>
> num_files = N_elements (files_list)
>
> for count = 0, num_files-1 do begin
>
> ; Selects the n- file. Output file name is
> "input_file_name"+"-masked"
>
> in_file = files_list [count]
> out_file =files_list [count]+'-masked'
> envi_open_file, in_file, r_fid=fid
> if (fid eq -1 or m_fid eq -1) then return
>
>
> ; get some useful information and set the output filename.
> envi_file_query, fid, ns=ns, nl=nl, nb=nb, bname=bname
>
> ; Set the keyword parameters
> dims = [-1l, 0, ns-1, 0, nl-1]
> pos = lindgen(nb)
> m_pos = [0]
>
> ; Call the 'doit' to apply the mask
>
> envi_mask_apply_doit, fid=fid, pos=pos, dims=dims,m_fid=m_fid,$
> m_pos=m_pos, value=0, out_name=out_file, in_memory=0, $
> r_fid=r_fid
>
> endfor
>
> end
>
> I hadn't fully tested it, but it should work.
>
> Hope this helps,
>
> Lorenzo
Re: Apply a shapefile to raster images in IDL [message #41326 is a reply to message #41289] Fri, 08 October 2004 11:38 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jenny writes:

> Thank you very much for your reply. I've taken Lorenzo's suggestion,
> and it works really well. This is a great group, especially to a
> novice... Though just began to use IDL a couple of weeks ago, I found
> it is a golden mine, worthy to dig hard :-(.

Oh, yes, lot's of great eccentrics here. You will like it. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http:/www.dfanning.com/
Phone: 970-221-0438, IDL Book Orders: 1-888-461-0155
Re: Apply a shapefile to raster images in IDL [message #41327 is a reply to message #41289] Fri, 08 October 2004 11:23 Go to previous messageGo to next message
envi35 is currently offline  envi35
Messages: 8
Registered: October 2004
Junior Member
Hi Everyone,
Thank you very much for your reply. I've taken Lorenzo's suggestion,
and it works really well. This is a great group, especially to a
novice... Though just began to use IDL a couple of weeks ago, I found
it is a golden mine, worthy to dig hard :-(.

Best Regards to all!
Jenny

lbusett@yahoo.it (Lorenzo Busetto) wrote in message news:<e4da268.0410070408.60d07040@posting.google.com>...
> Hi Jenny,
>
> If your images are all of the same size I think that you can solve
> your problem simply by using ENVI.
>
> 1: Open one of your images and load it in a display
> 2: Convert your shapefile to an ENVI vector file (EVF) by clicking
>> Vector > Open Vector File > Shapefile
> 3: Load your vector on the display where you have loaded your
> image (In the "available vectors list" select the vector, then click
> on "load" and then on "Diplay# (your_display)"
> 4:In the "Vector Parameters" window that appears, select "File >
> Export active layer to ROI"
> 5: Select "basic tools > masking > build mask" and select your
> display
> 6: Select "Options > Import ROIS", then select the ROI you created
> from your vector and click on "OK". Next, choose a name for the mask
> file that you want to create and click on "Apply". Now, in the
> "available bands list you should see a new image, which has value 0
> outside the vector and 1 inside it.
> 7: Now, you can use this "0-1" image as a mask for your image. Go
> to Basic tools > apply mask. Select one of the images that you want to
> mask, then click on "Select mask band" and select the mask image.
> Click on "OK".
>
> If you have many images and you don't want to repeat n-times the
> last step you can use an IDL procedure that automatically opens the
> images and apply the mask on each one.
> I think that something like this should work: it's a simple
> modification of the example program that you can find on the ENVI
> User's guide.
>
> pro multiple_mask
>
> ; Select input files (Select all your images)
>
> files_list = dialog_pickfile(/READ,title ='Select input$
> files',/multiple_files)
>
> ; Select the mask File
>
> mask_file = dialog_pickfile(/read, title = 'Select Mask File')
> envi_open_file, mask_file, r_fid=m_fid
>
> ; Count the number of files
>
> num_files = N_elements (files_list)
>
> for count = 0, num_files-1 do begin
>
> ; Selects the n- file. Output file name is
> "input_file_name"+"-masked"
>
> in_file = files_list [count]
> out_file =files_list [count]+'-masked'
> envi_open_file, in_file, r_fid=fid
> if (fid eq -1 or m_fid eq -1) then return
>
>
> ; get some useful information and set the output filename.
> envi_file_query, fid, ns=ns, nl=nl, nb=nb, bname=bname
>
> ; Set the keyword parameters
> dims = [-1l, 0, ns-1, 0, nl-1]
> pos = lindgen(nb)
> m_pos = [0]
>
> ; Call the 'doit' to apply the mask
>
> envi_mask_apply_doit, fid=fid, pos=pos, dims=dims,m_fid=m_fid,$
> m_pos=m_pos, value=0, out_name=out_file, in_memory=0, $
> r_fid=r_fid
>
> endfor
>
> end
>
> I hadn't fully tested it, but it should work.
>
> Hope this helps,
>
> Lorenzo
Re: Apply a shapefile to raster images in IDL [message #41337 is a reply to message #41289] Thu, 07 October 2004 05:08 Go to previous messageGo to next message
lbusett is currently offline  lbusett
Messages: 9
Registered: March 2004
Junior Member
Hi Jenny,

If your images are all of the same size I think that you can solve
your problem simply by using ENVI.

1: Open one of your images and load it in a display
2: Convert your shapefile to an ENVI vector file (EVF) by clicking
> Vector > Open Vector File > Shapefile
3: Load your vector on the display where you have loaded your
image (In the "available vectors list" select the vector, then click
on "load" and then on "Diplay# (your_display)"
4:In the "Vector Parameters" window that appears, select "File >
Export active layer to ROI"
5: Select "basic tools > masking > build mask" and select your
display
6: Select "Options > Import ROIS", then select the ROI you created
from your vector and click on "OK". Next, choose a name for the mask
file that you want to create and click on "Apply". Now, in the
"available bands list you should see a new image, which has value 0
outside the vector and 1 inside it.
7: Now, you can use this "0-1" image as a mask for your image. Go
to Basic tools > apply mask. Select one of the images that you want to
mask, then click on "Select mask band" and select the mask image.
Click on "OK".

If you have many images and you don't want to repeat n-times the
last step you can use an IDL procedure that automatically opens the
images and apply the mask on each one.
I think that something like this should work: it's a simple
modification of the example program that you can find on the ENVI
User's guide.

pro multiple_mask

; Select input files (Select all your images)

files_list = dialog_pickfile(/READ,title ='Select input$
files',/multiple_files)

; Select the mask File

mask_file = dialog_pickfile(/read, title = 'Select Mask File')
envi_open_file, mask_file, r_fid=m_fid

; Count the number of files

num_files = N_elements (files_list)

for count = 0, num_files-1 do begin

; Selects the n- file. Output file name is
"input_file_name"+"-masked"

in_file = files_list [count]
out_file =files_list [count]+'-masked'
envi_open_file, in_file, r_fid=fid
if (fid eq -1 or m_fid eq -1) then return


; get some useful information and set the output filename.
envi_file_query, fid, ns=ns, nl=nl, nb=nb, bname=bname

; Set the keyword parameters
dims = [-1l, 0, ns-1, 0, nl-1]
pos = lindgen(nb)
m_pos = [0]

; Call the 'doit' to apply the mask

envi_mask_apply_doit, fid=fid, pos=pos, dims=dims,m_fid=m_fid,$
m_pos=m_pos, value=0, out_name=out_file, in_memory=0, $
r_fid=r_fid

endfor

end

I hadn't fully tested it, but it should work.

Hope this helps,

Lorenzo
Re: Apply a shapefile to raster images in IDL [message #41346 is a reply to message #41289] Tue, 05 October 2004 09:18 Go to previous messageGo to next message
c_jengo is currently offline  c_jengo
Messages: 5
Registered: May 2004
Junior Member
Jenny,
This suggestion is based on three assumptions:
1. You have ENVI+IDL (sounds like it)
2. There is only one shapefile for all the files (also sounds like it)
3. Your image files are georeferenced or the lat/lon files give a
lat/lon point for every pixel in the image (known as an Internal
Geometry Model (IGM) file), or you can otherwise georeference them.

While not trivial (especially for a novice), there is a way to do this
using ENVI routines.

First, convert your shapefile to an ENVI vector file (EVF) by clicking
Vector > Open Vector File > Shapefile (I don't think there is a
documented way to do this programmatically).

Next, write an IDL program that iterates through your files and does
the following:
-Open your image and IGM files (ENVI_OPEN_FILE)
-Create a Geographic Lookup Table (GLT) file (ENVI_GLT_DOIT)
-Apply the GLT to create a georeferenced image
(ENVI_GEOREF_FROM_GLT_DOIT)
-Open the vector file (ENVI_EVF_OPEN)
-Loop through the records and extract the vector coordinates
(ENVI_EVF_READ_RECORD)
-Close the vector file (ENVI_EVF_CLOSE)
-Convert these lat/lon points to file coordinates referenced to your
georeferenced image (ENVI_CONVERT_FILE_COORDINATES)
-Create a region of interest (ENVI_CREATE_ROI)
-Populate the ROI with your points (ENVI_DEFINE_ROI)
-Get the address of every pixel within the ROI (ENVI_GET_ROI)
-Create an array with the same dimensions as your georeferenced image
(BYTARR)
-Set pixels within ROIs equal to 1 (ex: myImage[roi_addr] = 1)
-Save the mask to a temp file or memory (ENVI_WRITE_ENVI_FILE
ENVI_ENTER_DATA)
-Apply the mask to your image (ENVI_MASK_APPLY_DOIT)
-Be sure to clean up your files (ENVI_FILE_MNG)

And that's it! Nothing to it, eh? ;-) Sorry if I missed a step or
two, I was going off the top of my head. Hope this at least gets you
started...

Chris



envi35@yahoo.ca (Jenny) wrote in message news:<c371324e.0410021329.26d3e286@posting.google.com>...
> Dear Listers,
> I'm a novice in IDL, not sure if my questions are totally improper. I
> want to use an Arcview format shapefile as a mask, to a huge number of
> raster images, which are in a polar stereographic grid format with
> separate image data files and lat/lon files. I would really appreciate
> if you could give me any hint about the following questions:
>
> 1. How to read the shapefile into an IDL variable?
> 2. How to tailor the shapefile to my raster image grid?
> 3. If the above questions are not proper or impossible in IDL, would
> you give me some suggestions to do the work?
>
> Thank you in advance,
> Jenny
Re: Apply a shapefile to raster images in IDL [message #91746 is a reply to message #41318] Wed, 19 August 2015 15:03 Go to previous message
Adam Erickson is currently offline  Adam Erickson
Messages: 8
Registered: July 2015
Junior Member
On Monday, October 11, 2004 at 1:29:29 PM UTC-7, Jonathan Greenberg wrote:
> Jenny (and others):
>
> We've been developing a "bridge" between raster and vector formats
> (designed, primarily, for optimized extraction of raster data from vector
> coverages) -- if anyone wants to check it out, go to
> http://starspan.casil.ucdavis.edu/ -- this code is open source, and we'd
> love to get feedback on it. Right now its designed for unix boxes (macos x
> people shouldn't have TOO much of a problem compiling it), and its not for
> the unix novice since I don't think we have a makefile at this point, but if
> you'd like to check it out, please do!
>
> --j
>
>
> On 10/2/04 2:29 PM, in article
> c371324e.0410021329.26d3e286@posting.google.com, "Jenny" <envi35@yahoo.ca>
> wrote:
>
>> Dear Listers,
>> I'm a novice in IDL, not sure if my questions are totally improper. I
>> want to use an Arcview format shapefile as a mask, to a huge number of
>> raster images, which are in a polar stereographic grid format with
>> separate image data files and lat/lon files. I would really appreciate
>> if you could give me any hint about the following questions:
>>
>> 1. How to read the shapefile into an IDL variable?
>> 2. How to tailor the shapefile to my raster image grid?
>> 3. If the above questions are not proper or impossible in IDL, would
>> you give me some suggestions to do the work?
>>
>> Thank you in advance,
>> Jenny

I know this is an old message, but I suggest using QGIS for zonal statistics :) It's much more efficient. Read my reply here: https://groups.google.com/forum/#!topic/comp.lang.idl-pvwave /4E5kR9DxybQ

Cheers,

Adam
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: create oval shape
Next Topic: python, strange result

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:28:08 PDT 2025

Total time taken to generate the page: 0.39410 seconds