X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



3731 Rate this article:
No rating

How to extract pixels within a vector boundary using POLYFILLV

This Help Article shows an example of how to use POLYFILLV to extract pixel locations within a polygon shapefile boundary. It also creates a polygon ROI from the shapefile vertices for comparison to the original shapefile.
===================
pro fill_polygon
compile_opt idl2

  ;open and query a file
  envi_open_file, 'bhtmref.img', r_fid=fid, /no_realize
  envi_file_query, fid, ns=ns, nl=nl

  ;clean up existing rois that are open, if any
  roi_cleanup = envi_get_roi_ids()
  envi_delete_rois, roi_cleanup

  ;open a shapefile - this was a multiple polygon shapefile 
  ;created from ENVI's sample dataset bhtmref.img
  myshape=OBJ_NEW('IDLffShape', 'bh_rois.shp')
  
  ; Get the number of entities so we can parse through them.
  myshape->GetProperty, N_ENTITIES=num_ent
  ; Read all the entities.

    FOR i=0, (num_ent-1) DO BEGIN
      ;Read the entity i
      ent = myshape->GetEntity(i)
      xmap=(*ent.vertices)[0, *]
      ymap =(*ent.vertices)[1, *]
      
      ;get the file coordinates
      envi_convert_file_coordinates, fid, xf, yf, xmap, ymap
      
      ;fill the polygon
      filled_poly = polyfillv(xf, yf, ns, nl)
      
      ind = array_indices([ns, nl], filled_poly, /dimensions)
      
      ;create a new ROI - point-based
      roi_id = envi_create_roi(color=i+2, $
          name = 'test roi_'+ strtrim(string(i+1), 2), $
          ns=ns, nl=nl)
      envi_define_roi, roi_id, /point, xpts=ind[0,*], ypts=ind[1,*]
    
      ;Clean-up of pointers 
      myshape->DestroyEntity, ent
    ENDFOR

  ; Close the Shapefile.
  OBJ_DESTROY, myshape
  
  ;save the ROIs
  roi_ids = envi_get_roi_ids()
  envi_save_rois, 'test.roi', roi_ids
  
  ;clean up open rois and reopen new file
  roi_cleanup = envi_get_roi_ids()
  envi_delete_rois, roi_cleanup
  envi_restore_rois, 'test.roi'
end
Review on 12/31/2013 MM

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »