This sample shows how to create an empty raster catalog in a geodatabase.
How to use
- Add these functions to your project.
- Call the high-level function (the first one listed) from your code.
Public Function createCatalog(pWs As IRasterWorkspaceEx, sCatalogName As String, _
sRasterFldName As String, sShapeFldName As String, _
Optional pShpSpatialRef As ISpatialReference, _
Optional pRasterSpatialRef As ISpatialReference, _
Optional isManaged As Boolean, _
Optional pFields As IFields, _
Optional sKeyword As String) As IRasterCatalog
' Create a raster catalog 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
If pFields Is Nothing Then
Set pFields = createFields(sRasterFldName, sShapeFldName, isManaged, pShpSpatialRef, pRasterSpatialRef)
End If
If Len(sKeyword) = 0 Then
sKeyword = "defaults"
End If
'create raster catalog
Set createCatalog = pWs.CreateRasterCatalog(sCatalogName, pFields, sShapeFldName, sRasterFldName, skeyword)
End Function
Public Function createFields(sRasterFld As String, sShapeFld As String, bIsManaged As Boolean, _
Optional pShpSpatialRef As ISpatialReference, _
Optional pRasterSpatialRef As ISpatialReference) As IFields
' create Fields
Dim pFieldsEdit As IFieldsEdit
Dim pFields As IFields
' add OID field
Set pFieldsEdit = New Fields
pFieldsEdit.AddField createOIDField("ObjectID")
' add NAME field
pFieldsEdit.AddField createNameField("name")
' add RASTER field
pFieldsEdit.AddField createRasterField(sRasterFld, bIsManaged, pRasterSpatialRef)
' add SHAPE field
pFieldsEdit.AddField createShapeField(sShapeFld, pShpSpatialRef)
' add XML field for METADATA
pFieldsEdit.AddField createXMLField
Set pFields = pFieldsEdit
Set createFields = pFields
Set pFields = Nothing
Set pFieldsEdit = Nothing
End Function
Public Function createNameField(sName As String) As IField
' create Name field
Dim pField As IField
Dim pFieldEdit As IFieldEdit
Set pField = New Field
Set pFieldEdit = pField
pFieldEdit.Name = sName
pFieldEdit.Type = esriFieldTypeString
Set createNameField = pField
Set pField = Nothing
Set pFieldEdit = Nothing
End Function
Public Function createOIDField(sOIDFldName As String) As IField
' Create OID field
Dim pField As IField
Dim pFieldEdit As IFieldEdit
Set pField = New Field
Set pFieldEdit = pField
pFieldEdit.Name = sOIDFldName
pFieldEdit.Type = esriFieldTypeOID
Set createOIDField = pField
Set pField = Nothing
Set pFieldEdit = Nothing
End Function
Public Function createRasterField(sRasterFldName As String, bIsManaged As Boolean, pSpatialRef As ISpatialReference) As IField2
' create Raster field
Dim pRField As IField2
Dim pRFieldEdit As IFieldEdit2
Dim pRDef As IRasterDef
If Len(sRasterFldName) = 0 Then
sRasterFldName = "RASTER"
End If
Set pRField = New Field
Set pRFieldEdit = pRField
pRFieldEdit.Name = sRasterFldName
pRFieldEdit.Type = esriFieldTypeRaster
Set pRDef = New RasterDef
pRDef.Description = "this is a raster catalog"
' only for PGDB
pRDef.IsManaged = bIsManaged
' Set unknown spatial reference if not set
If pSpatialRef Is Nothing Then
Set pSpatialRef = New UnknownCoordinateSystem
End If
Set pRDef.SpatialReference = pSpatialRef
' Set rasterdef
Set pRFieldEdit.RasterDef = pRDef
Set createRasterField = pRField
Set pRField = Nothing
Set pRFieldEdit = Nothing
Set pRDef = Nothing
End Function
Public Function createShapeField(sShapeFldName As String, pSpatialRef As ISpatialReference) As IField
' Create Shape field
Dim pField As IField
Dim pFieldEdit As IFieldEdit
If Len(sShapeFldName) = 0 Then
sShapeFldName = "SHAPE"
End If
Set pField = New Field
Set pFieldEdit = pField
pFieldEdit.Name = sShapeFldName
pFieldEdit.Type = esriFieldTypeGeometry
Set pFieldEdit.GeometryDef = createGeoDef(pSpatialRef)
Set createShapeField = pField
Set pField = Nothing
Set pFieldEdit = Nothing
End Function
Public Function createXMLField()
' create METADATA field
Dim pField As IField
Dim pFieldEdit As IFieldEdit
Set pField = New Field
Set pFieldEdit = pField
pFieldEdit.Name = "METADATA"
pFieldEdit.Type = esriFieldTypeBlob
Set createXMLField = pField
Set pField = Nothing
Set pFieldEdit = 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