ENVI\IDL shp转换evf 由于shp中polygon的岛导致的问题的解决办法

在shp文件转换为evf的时候。如果shp文件的polygon存在岛的话,转换的evf是有问题的。解决方法,是读取shp中的所有部分。

pro shapefileToEvf
compile_opt idl2
ENVI, /RESTORE_BASE_SAVE_FILES
ENVI_BATCH_INIT, LOG_FILE='batch.txt'
;打开shp文件
shapefile='C:\Users\younglimpo\Desktop\掩膜\sheng.shp'
;读取投影信息,并由此创建投影文件
projstr='C:\Users\younglimpo\Desktop\掩膜\sheng.prj'
openr,lun,projstr,/get_lun
shpPrjString=''
readf,lun,shpPrjString
free_lun,lun
shapfeProjection=envi_proj_create(type=42,pe_coord_sys_str=shpPrjString)
;读取shp文件的信息

  oshp=OBJ_NEW('IDLffShape',shapefile)
  oshp->getproperty,n_entities=n_ent,Attribute_info=attr_info,n_attributes=n_attr,Entity_type=ent_type

;创建evf文件
ent=oshp->GetEntity(0)
N_VERTICES=ent.N_VERTICES  
;错误解决办法
;就是是加入下面的两句代码

;
parts=*(ent.parts)
parts_ptr=[0,parts[1],-(parts[2]),-(parts[3]),-(N_VERTICES-1)]
vert=*(ent.vertices)
evfpath= 'd:\dhfTwoTest.evf'
evf_ptr = envi_evf_define_init(evfpath,$
          projection=shapfeProjection,data_type=5,$
          layer_name='')
envi_evf_define_add_record,evf_ptr,vert,parts_ptr=parts_ptr,type=5
evf_id = envi_evf_define_close(evf_ptr,/return_id) 
envi_evf_close,evf_id
attr=oshp->GetAttributes(/All)
;写入属性
envi_write_dbf_file, 'dhfTwoTest.dbf', attr
Obj_destroy,oshp

end
posted @ 2012-07-04 21:55  suwenjiang  阅读(5302)  评论(2编辑  收藏  举报