首页 > 代码库 > 影像数据的裁切和保存
影像数据的裁切和保存
ArcGIS 的栅格影像可以供保存的格式有:
The format strings used for the supported formats are below, and they are case sensitive:
Format Name | String Used |
---|---|
Imagine | "IMAGINE Image" |
TIFF | "TIFF" |
GRID | "GRID" |
JPEG | "JPG" |
JP2000 | "JP2" |
BMP | "BMP" |
PNG | "PNG" |
GIF | "GIF" |
PCI Raster | "PIX" |
X11 Pixmap | "XPM" |
PCRaster | "MAP" |
Memory Raster | "MEM" |
HDF4 | "HDF4" |
BIL | "BIL" |
BIP | "BIP" |
BSQ | "BSQ" |
Idrisi Raster Format | "RST" |
ENVI Raster Format | "ENVI" |
Geodatabase Raster | "GDB" |
保存栅格影像的方法
public void SaveAs(IRasterDataset rasterDataset, IWorkspace workspace, string sFormat, string sName)
{
//Using ISaveAs2, you can specify the storage property for the output raster, such as tile size, compression,
//and pyramid building, etc. for geodatabase raster, some also applies to output as a file format.
ISaveAs saveAs = rasterDataset as ISaveAs;
saveAs.SaveAs(sName, workspace, sFormat);
}
public void SaveAsWithCompressionAndTile(IRasterDataset rasterDataset)
{ //rasterDataset can be created from any data source, file system, or geodatabase.
//It could also be a raster object (IRaster).
ISaveAs2 saveAs2 = (ISaveAs2)rasterDataset; //Set storage.
IRasterStorageDef rasterStorageDef = new RasterStorageDefClass();
IRasterStorageDef2 rasterStorageDef2 = (IRasterStorageDef2)rasterStorageDef;
rasterStorageDef2.CompressionType = esriRasterCompressionType.esriRasterCompressionJPEG2000;
rasterStorageDef2.CompressionQuality = 50;
rasterStorageDef2.Tiled = true;
rasterStorageDef2.TileHeight = 128;
rasterStorageDef2.TileWidth = 128;
//Set output workspace.
IRasterWorkspaceEx rasterWorkspaceEx = OpenFileGDBWorkspace("c:\\temp\\fgdb.gdb") ;
IWorkspace workspace = (IWorkspace)rasterWorkspaceEx;
saveAs2.SaveAsRasterDataset("filegdbRaster", workspace, "gdb", rasterStorageDef2) ;
}
public IRasterWorkspaceEx OpenFileGDBWorkspace(string sPath)
{
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
IWorkspace workspace = workspaceFactory.OpenFromFile(sPath, 0);
IRasterWorkspaceEx rasterWorkspaceEx = (IRasterWorkspaceEx)workspace;
return rasterWorkspaceEx;
}
Turning off pyramid building
You can also turn off pyramid building for outputs, such as IMG, GRID, and TIFF formats using the ISaveAs2
interface. See the following code example:
public void SaveAsWithoutBuildingPyramids(IRaster raster)
{
ISaveAs2 saveAs2 = (ISaveAs2)raster;
IRasterStorageDef rasterStorageDef = new RasterStorageDefClass();
IRasterStorageDef2 rasterStorageDef2 = (IRasterStorageDef2)rasterStorageDef;
rasterStorageDef2.PyramidLevel = 0;
IRasterWorkspace rasterWorkspace = SetRasterWorkspace("c:\\temp");
IWorkspace workspace = (IWorkspace)rasterWorkspace;
saveAs2.SaveAsRasterDataset("image1.img", workspace, "IMAGINE Image", rasterStorageDef2);
}
public IRasterWorkspace SetRasterWorkspace(string sPath)
{
IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
IWorkspace workspace = workspaceFactory.OpenFromFile(sPath, 0);
IRasterWorkspace rasterWorkspace = (IRasterWorkspace)workspace;
return rasterWorkspace;
}
影像裁剪和保存 示例2
//影像裁切IGeometry clipGeo = axMapControl1.TrackPolygon(); //ILayer layer = axMapControl1.get_Layer(i); //要裁切的影像图层IRasterLayer pRasterLayer = layer as IRasterLayer;IRaster pRaster = pRasterLayer.Raster;IRasterProps pProps = pRaster as IRasterProps;object cellSizeProvider = pProps.MeanCellSize().X;IGeoDataset pInputDataset = pRaster as IGeoDataset;IExtractionOp pExtractionOp = new RasterExtractionOpClass();IRasterAnalysisEnvironment pRasterAnaEnvir = pExtractionOp as IRasterAnalysisEnvironment;pRasterAnaEnvir.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);object extentProvider = clipGeo.Envelope;object snapRasterData = http://www.mamicode.com/Type.Missing;"C:\temp", 0);ISaveAs pSaveAs = clipRaster as ISaveAs;pSaveAs.SaveAs("test.img", pWorkspace, "IMAGINE Image"); //如果保存在mdb中IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass();pRasterStorageDef.CompressionType = esriRasterCompressionType.esriRasterCompressionJPEG2000;pRasterStorageDef.CompressionQuality = 50;pRasterStorageDef.TileHeight = 128;pRasterStorageDef.TileWidth = 128;IWorkspaceFactory pWKSF = new AccessWorkspaceFactoryClass();IWorkspace pWorkspace = pWKSF.OpenFromFile(@"C:\temp\test.mdb", 0);ISaveAs2 pSaveAs = clipRaster as ISaveAs2;pSaveAs.SaveAsRasterDataset("test", pWorkspace, "gdb", pRasterStorageDef); //也可以使用IRasterWorkspaceEx的SaveAsRasterDataset方法保存到mdb中IWorkspaceFactory pWKSF = new AccessWorkspaceFactoryClass();IWorkspace pWorkspace = pWKSF.OpenFromFile(@"C:\temp\test.mdb", 0);IRasterWorkspaceEx pRasterWKS = pWorkspace as IRasterWorkspaceEx;IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass();pRasterStorageDef.CompressionType = esriRasterCompressionType.esriRasterCompressionJPEG2000;pRasterStorageDef.CompressionQuality = 50;pRasterStorageDef.PyramidLevel = 2;pRasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;pRasterStorageDef.TileHeight = 128;pRasterStorageDef.TileWidth = 128;IRasterDef pRasterDef = new RasterDefClass();pRasterDef.Description = "rasterdataset";pRasterDef.SpatialReference = axMapControl1.SpatialReference;IGeometryDef pGeoDef = new GeometryDefClass();IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;pGeoDefEdit.AvgNumPoints_2 = 4;pGeoDefEdit.GridCount_2 = 1;pGeoDefEdit.set_GridSize(0, 1000);pGeoDefEdit.SpatialReference_2 = axMapControl1.SpatialReference;IRasterDataset pRasterDataset = pRasterWKS.SaveAsRasterDataset("test", clipRaster, pRasterStorageDef, "", pRasterDef,pGeoDef);//其实参数可以不用设置,直接:IRasterDataset pRasterDataset = pRasterWKS.SaveAsRasterDataset("test", clipRaster, null, "", null, null);
参考文章
影像数据的裁切和保存
保存栅格数据 ISaveAs.SaveAs Method
影像数据的裁切和保存
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。