This sample shows how to create an empty raster dataset in a geodatabase.
How to use
- Add these functions to your project.
- Call the top-level function (first one listed) from your code.
Public Function createSDERasterDs(pWs As IRasterWorkspaceEx, sDsName As String, _
iNBands As Integer, iPixelType As Integer, _
Optional pSR As ISpatialReference, _
Optional pRasterStoreDef As IRasterStorageDef, _
Optional pRasterDef As IRasterDef, _
Optional sKeyword As String) As IRasterDataset
' Create a raster dataset in a geodatabase workspace
' pWs == destination geodatabase workspace (personal or ArcSDE)
' sCatalogName == name of the raster catalog
' sRatserFldName == name of the raster column
' sShapeFldName == name of the geometry column
' pShpSpatialRef == spatial reference of the geometry column
' pRasterSpatialRef == spatial reference fo the raster column
' isManaged == for personal geodatabase only, if true, the rasters are managed by the GDB
' pFields == fields of the raster catalog table
' sKeyword == ArcSDE only, configuration keyword
Dim pRasterDs As IRasterDataset
Dim pGeoDef As IGeometryDef
' ++ if rasterdef is missing, create one with specified/unknown spatialreference
If pRasterDef Is Nothing Then
Set pRasterDef = createRasterDef(False, pSR)
End If
' ++ if rasterstoragedef is missing, use default parameters
If pRasterStoreDef Is Nothing Then
Set pRasterStoreDef = createRasterStorageDef
End If
' ++ create geodef
Set pGeoDef = createGeoDef(pSR)
' ++ if keyword is missing, use default
If Len(sKeyword) = 0 Then sKeyword = "DEFAULTS"
Set pRasterDs = pWs.CreateRasterDataset(sDsName, iNBands, iPixelType, _
pRasterStoreDef, sKeyword, pRasterDef, pGeoDef)
Set createSDERasterDs = pRasterDs
Set pRasterDs = Nothing
End Function
Public Function createRasterDef(bByref As Boolean, Optional pSpatialRef As ISpatialReference) As IRasterDef
' Create rasterdef
Dim pRasterDef As IRasterDef
Set pRasterDef = New RasterDef
pRasterDef.Description = "rasterdataset"
If pSpatialRef Is Nothing Then
Set pSpatialRef = New UnknownCoordinateSystem
End If
Set pRasterDef.SpatialReference = pSpatialRef
Set createRasterDef = pRasterDef
Set pRasterDef = Nothing
End Function
Public Function createRasterStorageDef() As IRasterStorageDef
' Create rasterstoragedef
Dim pRasterStorageDef As IRasterStorageDef
Set pRasterStorageDef = New RasterStorageDef
pRasterStorageDef.CompressionType = esriRasterSdeCompressionTypeRunLength
pRasterStorageDef.PyramidLevel = 2
pRasterStorageDef.PyramidResampleType = RSP_BilinearInterpolation
pRasterStorageDef.TileHeight = 128
pRasterStorageDef.TileWidth = 128
Set createRasterStorageDef = pRasterStorageDef
Set pRasterStorageDef = Nothing
End Function
Public Function createGeoDef(pSpatialRef As ISpatialReference) As IGeometryDef
' Create GeometryDef
Dim pGeoDef As IGeometryDef
Dim pGeoEdit As IGeometryDefEdit
Set pGeoDef = New GeometryDef
Set pGeoEdit = pGeoDef
pGeoEdit.GeometryType = esriGeometryPolygon
pGeoEdit.AvgNumPoints = 4
pGeoEdit.GridCount = 1
pGeoEdit.GridSize(0) = 1000
' Set unknown spatial reference is not set
If pSpatialRef Is Nothing Then
Set pSpatialRef = New UnknownCoordinateSystem
End If
Set pGeoEdit.SpatialReference = pSpatialRef
Set createGeoDef = pGeoDef
Set pGeoDef = Nothing
Set pGeoEdit = Nothing
End Function