ENVI/IDL 批量裁剪同一地区的多幅影像-第五篇

上一篇文章采用的是regrid的方法,适合将不同分辨率、不同坐标系的影像转到同一坐标系,而对于同一分辨率和相同坐标系的影像而言,会进行采样!这不同于裁剪。对此,下面提供了一种 利用参考影像的地理范围进行裁剪的方法:

function y_geoclip, raster_base, raster, respath

; Author: Yinxia Cao

;Date: 2020.8.19

; Define the spatial range of the subRect

subRect = [0, 0, $

  raster_base.nSamples-1, raster_base.nLines-1] ; 默认处理参考影像的全部范围

; Get the spatial reference of the raster

SpatialRef = raster_base.SPATIALREF

; Convert file coordinates to map coordinates

SpatialRef.ConvertFileToMap, subRect[0], subRect[1], ULx, ULy

SpatialRef.ConvertFileToMap, subRect[0], subRect[3], LLx, LLy

SpatialRef.ConvertFileToMap, subRect[2], subRect[1], URx, URy

SpatialRef.ConvertFileToMap, subRect[2], subRect[3], LRx, LRy

geoRect = [ LLx, LLy, URx, URy ]

; Get the task from the catalog of ENVITasks

Task = ENVITask('GeographicSubsetRaster')

; Define inputs

Task.INPUT_RASTER = Raster

Task.SUB_RECT = geoRect

; Define outputs

Task.OUTPUT_RASTER_URI = respath

; Run the task

Task.Execute

return, 1
end

调用方法:

raster_base=e.openraster('img1.dat')

raster=e.openraster('img2.dat')

respath='img2_clip.dat'

t = y_geoclip( raster_base, raster, respath)

 

你可能感兴趣的:(ENVI/IDL)