Isaveas. saveas Method

Source: Internet
Author: User

 

Creates a new persistent dataset of a given format.

[Visual Basic .NET]Public Function SaveAs ( _    ByVal Name As String, _    ByVal Workspace As IWorkspace, _    ByVal Format As String _) As IDataset
[C#]public IDataset SaveAs (    string Name,    IWorkspace Workspace,    string Format);
[C++]HRESULT SaveAs(  BSTR Name,  IWorkspace* Workspace,  BSTR Format,  IDataset** Dataset);
[C ++]

Parameters

 

Name[In]

NameIs a parameter of TypeBSTR

 

Workspace[In]

WorkspaceIs a parameter of TypeIworkspace

 

Format[In]

FormatIs a parameter of TypeBSTR

 

Dataset[Out, retval]

DatasetIs a parameter of TypeIdataset

Product availabilityavailable with ArcGIS Engine, ArcGIS desktop, and ArcGIS Server. Remarks

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"

 

How to saveas Raster Data Summary

This article shows how to save a raster to various raster formats (Save As), how to set up storage properties if saved to a Geodatabase, and how to control Pyramid building when saved as IMG, tiff, grid, and Geodatabase formats.

 

Development Licensing Deployment Licensing
ArcView ArcView
Arceditor Arceditor
ArcInfo ArcInfo
Engine developer Kit Engine Runtime

 

 

Additional requirements

  • Add the following references to your Visual Studio project and the corresponding using (C #) or imports (VB. NET) statements:
  • Imports ESRI. ArcGIS. datasourcesgdb
  • Imports ESRI. ArcGIS. datasourcesraster
  • Imports ESRI. ArcGIS. Geodatabase
  • Imports ESRI. ArcGIS. esrisystem

 

Saving as Raster DataBy using the isaveas interface, you can save a raster dataset or a raster into initialize raster formats. you can also save to a Geodatabase if the output workspace is one of the Geodatabase workspaces. see the following code example:

[C #] de>

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;}

 

De>

[VB. NET] de>

 Public Sub SaveAs(ByVal rasterDataset As IRasterDataset, ByVal workspace As IWorkspace, ByVal sFormat As String, ByVal sName As String)        '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.    Dim saveAs As ISaveAs = TryCast(rasterDataset, ISaveAs)    saveAs.SaveAs(sName, workspace, sFormat)    End SubPublic Sub SaveAsWithCompressionAndTile(ByVal rasterDataset As IRasterDataset)        'rasterDataset can be created from any data source, file system, or geodatabase.    'It could also be a raster object (IRaster).    Dim saveAs2 As ISaveAs2 = CType(rasterDataset, ISaveAs2)        'Set storage.    Dim rasterStorageDef As IRasterStorageDef = New RasterStorageDefClass    Dim rasterStorageDef2 As IRasterStorageDef2 = CType(rasterStorageDef, IRasterStorageDef2)        rasterStorageDef2.CompressionType = esriRasterCompressionType.esriRasterCompressionJPEG2000    rasterStorageDef2.CompressionQuality = 50    rasterStorageDef2.Tiled = True    rasterStorageDef2.TileHeight = 128    rasterStorageDef2.TileWidth = 128        'Set output workspace.    Dim rasterWorkspaceEx As IRasterWorkspaceEx = OpenFileGDBWorkspace("c:/temp/fgdb.gdb")    Dim workspace As IWorkspace = CType(rasterWorkspaceEx, IWorkspace)        saveAs2.SaveAsRasterDataset("filegdbRaster", workspace, "gdb", rasterStorageDef2)    End SubPublic Function OpenFileGDBWorkspace(ByVal sPath As String) As IRasterWorkspaceEx        Dim workspaceFactory As IWorkspaceFactory = New FileGDBWorkspaceFactoryClass    Dim workspace As IWorkspace = workspaceFactory.OpenFromFile(sPath, 0)    Dim rasterWorkspaceEx As IRasterWorkspaceEx = CType(workspace, IRasterWorkspaceEx)        Return rasterWorkspaceEx    End Function
 
  
Turning off Pyramid buildingYou can also turn off Pyramid building for outputs, such as IMG, grid, And Tiff formats using the isaveas2 interface. See the following code example: 

 

[C #] de>

 
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;}

 

De>

[VB. NET] de>

 
Public Sub SaveAsWithoutBuildingPyramids(ByVal raster As IRaster)        Dim saveAs2 As ISaveAs2 = CType(raster, ISaveAs2)        Dim rasterStorageDef As IRasterStorageDef = New RasterStorageDefClass    Dim rasterStorageDef2 As IRasterStorageDef2 = CType(rasterStorageDef, IRasterStorageDef2)        rasterStorageDef2.PyramidLevel = 0        Dim rasterWorkspace As IRasterWorkspace = SetRasterWorkspace("c:/temp")    Dim workspace As IWorkspace = CType(rasterWorkspace, IWorkspace)        saveAs2.SaveAsRasterDataset("image1.img", workspace, "IMAGINE Image", rasterStorageDef2)    End SubPublic Function SetRasterWorkspace(ByVal sPath As String) As IRasterWorkspace        Dim workspaceFactory As IWorkspaceFactory = New RasterWorkspaceFactoryClass    Dim workspace As IWorkspace = workspaceFactory.OpenFromFile(sPath, 0)    Dim rasterWorkspace As IRasterWorkspace = CType(workspace, IRasterWorkspace)        Return rasterWorkspace    End Function

 

 

This article from: http://changqingnew.blog.163.com/blog/static/1075233820103474425849/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.