This sample shows how to export the footprints of the rasters in a raster catalog to a featureclass.
How to use
- Add these functions to your project.
- Call the top-level function (first one listed) from your code.
Public Sub ExportFootprint(pCatalog As IRasterCatalog, pOutWs As IFeatureWorkspace, sName As String)
' This procedure exports the footprint column of a raster catalog to a featureclass
Dim pFeatCls As IFeatureClass
Dim pFldsEdit As IFieldsEdit
Dim pFldEdit As IFieldEdit
Dim pOutFeatCls As IFeatureClass
Dim pCursor As IFeatureCursor
Dim pFeature As IFeature
Dim pRow As IRow
' QI IFeatureClass
Set pFeatCls = pCatalog
' Create fields with OID, NAME and SHAPE columns
Set pFldsEdit = New Fields
Set pFldEdit = New Field
pFldEdit.Name = "OBJECTID"
pFldEdit.Type = esriFieldTypeOID
pFldsEdit.AddField pFldEdit
Set pFldEdit = New Field
pFldEdit.Name = "NAME"
pFldEdit.Type = esriFieldTypeString
pFldsEdit.AddField pFldEdit
Set pFldEdit = New Field
pFldEdit.Name = "SHAPE"
pFldEdit.Type = esriFieldTypeGeometry
' Get shape fieldname and index from the rastercatalog
Dim sGeo As String
sGeo = pFeatCls.ShapeFieldName
Dim iShape As Integer
iShape = pFeatCls.FindField(sGeo)
' Set the geometrydef from the shape field in the raster catalog
Set pFldEdit.GeometryDef = pFeatCls.Fields.Field(iShape).GeometryDef
pFldsEdit.AddField pFldEdit
' Create output featureclass
Set pOutFeatCls = pOutWs.CreateFeatureClass(sName, pFldsEdit, Nothing, Nothing, esriFTSimple, "SHAPE", "")
' Get cursor from the raster catalog
Set pCursor = pFeatCls.Search(Nothing, False)
Set pFeature = pCursor.NextFeature
' Loop through all items and extract NAME and SHAPE column values
Do While Not pFeature Is Nothing
Set pRow = pOutFeatCls.CreateFeature
'NAME column
pRow.Value(1) = pFeature.Value(pCatalog.NameFieldIndex)
'SAHPE column
pRow.Value(2) = pFeature.Value(iShape)
pRow.Store
Set pFeature = pCursor.NextFeature
Loop
'Cleanup
Set pFeatCls = Nothing
Set pFldsEdit = Nothing
Set pFldEdit = Nothing
Set pOutFeatCls = Nothing
Set pCursor = Nothing
Set pFeature = Nothing
Set pRow = Nothing
End Sub