码迷,mamicode.com
首页 > 其他好文 > 详细

影像数据的裁切和保存

时间:2017-06-11 22:17:20      阅读:330      评论:0      收藏:0      [点我收藏+]

标签:cas   arcgis   source   href   tin   provider   dataset   des   png   

 

 ArcGIS 的栅格影像可以供保存的格式有:

The format strings used for the supported formats are below, and they are case sensitive:

Format NameString 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 = Type.Missing;
pRasterAnaEnvir.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData);
IGeoDataset pOutputDataset = pExtractionOp.Polygon(pInputDataset, clipGeo as IPolygon, true);
IRaster clipRaster; //裁切后得到的IRaster
if (pOutputDataset is IRasterLayer)
{
IRasterLayer rasterLayer = pOutputDataset as IRasterLayer;
clipRaster = rasterLayer.Raster;
}
else if (pOutputDataset is IRasterDataset)
{
IRasterDataset rasterDataset = pOutputDataset as IRasterDataset;
clipRaster = rasterDataset.CreateDefaultRaster();
}
else if (pOutputDataset is IRaster)
{
clipRaster = pOutputDataset as IRaster;
}
else
{
return;
}
 




//保存裁切后得到的clipRaster
 
//如果直接保存为img影像文件
IWorkspaceFactory pWKSF = new RasterWorkspaceFactoryClass();
IWorkspace pWorkspace = pWKSF.OpenFromFile(@"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.esriRasterCom
pressionJPEG2000;
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

 

影像数据的裁切和保存

标签:cas   arcgis   source   href   tin   provider   dataset   des   png   

原文地址:http://www.cnblogs.com/arxive/p/6986491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!