使用多边形裁减影像
Public Function ClipRasterByPolgon(pInGeoDataset As IGeoDataset, pPolygon As IPolygon) As IRaster
Dim pRaster As IRaster
If TypeOf pInGeoDataset Is IRasterLayer Then
Dim pRasterlayer As IRasterLayer
Set pRasterlayer = pInGeoDataset
Set pRaster = pRasterlayer.Raster
ElseIf TypeOf pInGeoDataset Is IRasterDataset Then
Dim pRasterDataset As IRasterDataset
Set pRasterDataset = pInGeoDataset
Set pRaster = pRasterDataset.CreateDefaultRaster
ElseIf TypeOf pInGeoDataset Is IRaster Then
Set pRaster = pInGeoDataset
Else
Exit Function
End If
Dim pInputDataset As IGeoDataset
Set pInputDataset = pRaster
Dim pExtractionOp As IExtractionOp
Set pExtractionOp = New RasterExtractionOp
Dim pRasterAnalysisEnvironment As IRasterAnalysisEnvironment
Set pRasterAnalysisEnvironment = pExtractionOp
pRasterAnalysisEnvironment.SetCellSize esriRasterEnvValue, GetRasterCellSize(pRaster)
pRasterAnalysisEnvironment.SetExtent esriRasterEnvValue, pPolygon.Envelope
Dim pOutputDataset As IGeoDataset
Set pOutputDataset = pExtractionOp.Polygon(pInputDataset, pPolygon, True)
Set ClipRasterByPolgon = pOutputDataset
End Function
Public Function GetRasterCellSize(pRaster As IRaster) As Double
Dim pProps As IRasterProps
Set pProps = pRaster
GetRasterCellSize = pProps.MeanCellSize.X
End Function
注意:pPolygon 的ISpatialReference要与RASTER的一样如果不一样,可以使用
pGeometry.Project pRasterSpatialReference来设定