跳转至

ENVI:在显示界面添加自定义多边形

原文链接: https://www.nv5geospatialsoftware.com/Learn/Blogs/Blog-Details/envi-adding-custom-polygons-to-the-display

19183 给本文评分:

4.5

ENVI:在显示界面添加自定义多边形

匿名 2016年10月28日 星期五

我最近参与的一个项目需要在 ENVI 显示界面添加自定义多边形——这些多边形由我的应用程序控制。以下代码定义了一个对象类,允许用户使用窗口坐标将多边形放置到 ENVI 显示界面中。要运行该应用程序:

  1. 将以下代码保存到名为 envi_polygon_example.pro 的文件中
  2. 在 IDLDE 中打开并编译该文件
  3. 在 IDL 命令行提示符下执行以下命令: envi_polygon_example

;------------------------------------------------------------------------------

;+

; 用于销毁对象的生命周期方法

;-

pro my_polygon::Cleanup

compile_opt idl2, logical_predicate

self->Destruct

end

;------------------------------------------------------------------------------

;+

; 清理对象类的成员变量

;-

pro my_polygon::Destruct

compile_opt idl2, logical_predicate

self->IDLmiManipGraphicOverlay::Cleanup

self->IDLmiManipLayer::Cleanup

self->IDLgrPolygon::Cleanup

end

;------------------------------------------------------------------------------

;+

; 用于初始化类的生命周期方法

;

; :返回值:

;   如果对象初始化成功则返回 1,否则返回 0

;  

; :参数:

;   xy: 输入,可选,类型="int"

;     一个包含窗口坐标中 [x,y] 点的 [2,n] 数组

;  

; :关键字:

;   POLYGONS: 输入,可选,类型="int"

;     一个或多个多边形描述的整数数组。有关更多信息,请参阅

;     IDL 帮助中关于 IDLgrPolygon 的部分

;   _REF_EXTRA: 用于设置继承的 IDLgrPolygon 的属性

;-

function my_polygon::Init, xy, $

POLYGONS=poly, $

_REF_EXTRA=refExtra

compile_opt idl2, logical_predicate

void = self->IDLmiManipGraphicOverlay::Init(_EXTRA=refExtra)

if ~void then begin

return, 0

endif

self->InitializeDataspace

self->SetupManipulatorGraphics

self->InitializeGraphics

if n_elements(xy) then begin

self->SetProperty, DATA=xy, POLYGONS=poly

endif

if n_elements(refExtra) then begin

self->SetProperty, _EXTRA=refExtra

endif

return, 1

end

;------------------------------------------------------------------------------

;+

; 此方法初始化图形层使用的数据空间

;-

pro my_polygon::InitializeDataspace

compile_opt idl2, logical_predicate

e = envi(/CURRENT)

eView = e->GetView()

eView->GetProperty, _COMPONENT=ecfViewGroup

oDS = ecfViewGroup->GetDescendants(BY_TYPE='DATASPACE', /FIRST_ONLY)

self._oTargetDS = oDS

end

;------------------------------------------------------------------------------

;+

; 初始化类的图形组件

;-

pro my_polygon::InitializeGraphics

compile_opt idl2, logical_predicate

void = self->IDLgrPolygon::Init(COLOR=[255,0,0], /PRIVATE, THICK=2)

self._oGrOverlay->IDLmiContainer::Add, self

end

;------------------------------------------------------------------------------

;+

; 此方法用于设置类属性

;-

pro my_polygon::SetProperty, $

DATA=data, $

POLYGONS=poly, $

_REF_EXTRA=refExtra

compile_opt idl2, logical_predicate

if n_elements(data) then begin

self->SetData, data, POLYGONS=poly

endif

if n_elements(refExtra) then begin

self->IDLgrPolygon::SetProperty, _EXTRA=refExtra

self->IDLmiManipLayer::SetProperty, _EXTRA=refExtra

endif

end

;------------------------------------------------------------------------------

;+

; 此方法将点从窗口坐标映射到地图坐标,并将映射后的点添加到 IDLgrPolygon。

;

; :参数:

;   xy: 输入,必需,类型="int"

;     要添加到多边形中的点的 [2,n] 数组(窗口坐标)

;

; :关键字:

;   POLYGONS: 输入,可选,类型="int"

;     一个或多个多边形描述的整数数组。有关更多信息,请参阅

;     IDL 帮助中关于 IDLgrPolygon 的部分

;-

pro my_polygon::SetData, xy, $

POLYGONS=poly

compile_opt idl2, logical_predicate

self._oTargetDS->WindowToVis, reform(xy[0,*]), reform(xy[1,*]), xVis, yVis

self->IDLgrPolygon::SetProperty, DATA=transpose([[xVis],[yVis]]), $

POLYGONS=poly

end

;------------------------------------------------------------------------------

;+

; 类结构定义

;-

pro my_polygon__define

compile_opt idl2, logical_predicate

void = {my_polygon                    $

, inherits IDLmiManipGraphicOverlay $

, inherits IDLmiManipLayer          $

, inherits IDLgrPolygon             $

}

end

;------------------------------------------------------------------------------

;+

;-

pro envi_polygon_example

compile_opt idl2, logical_predicate

e = envi(/CURRENT)

if ~isa(e, 'envi') then begin

e = envi()

endif

file = FILEPATH('qb_boulder_msi', ROOT_DIR=e.ROOT_DIR, SUBDIRECTORY=['data'])

eRaster = e->OpenRaster(file)

eView = e->GetView()

eLayer = eView->CreateLayer(eRaster)

xy = [[470,140],[560,140],[560,230],[470,230], $

[750,115],[1200,115],[1200,665],[750,665]]

conn = [4,0,1,2,3,4,4,5,6,7]

oPolygon = obj_new('my_polygon', xy, LINESTYLE=5, POLYGONS=conn, STYLE=1)

end

使用 Node.js 定制地理空间服务框架 使用深度学习进行特征提取