I am attempting to extract an irregular polygon from a Mosaic Dataset using ArcObjects in C#. This sample shows how to open a mosaic dataset in ArcObjects. Referencing existing (VB) code, this snippet is from a working tool which uses IPixelOperation to reduce the raster to only the portion covered by a polygon:
Dim pRaster As IRaster = pRasLayer.Raster
Dim pPixOp As IPixelOperation = pRaster
Dim pShapeWS As IWorkspace = pShapeWSfact.OpenFromFile(pFolderPath, 0)
Dim pShapeFws As IFeatureWorkspace = pShapeWS
Dim pShapeFC As IFeatureClass = pShapeFws.OpenFeatureClass(pFileName & ".shp")
Dim pFeatCur As IFeatureCursor = pShapeFC.Search(Nothing, True)
Dim pFeat As IFeature = pFeatCur.NextFeature
Dim pClipFilter As IClipFilter = New ClipFilterClass()
Dim pGeom As IGeometry
Do Until pFeat Is Nothing
pGeom = pFeat.ShapeCopy
If pGeom.SpatialReference.FactoryCode <> pMap.SpatialReference.FactoryCode Then pGeom.Project(pMap.SpatialReference)
pClipFilter.Add(pGeom)
pFeat = pFeatCur.NextFeature
Loop
pPixOp.PixelFilter = pClipFilter
Which illustrates how an IClipFilter can be used to restrict the display of a raster... I am attempting to use IClipFilter as IPixelFilter to return the irregular portion of a raster within a polygon:
IMosaicWorkspaceExtensionHelper mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass();
IMosaicWorkspaceExtension mosaicExt = mosaicExtHelper.FindExtension(gMosDSsrcWorkspace);
IMosaicDataset pMosDS = mosaicExt.OpenMosaicDataset(gMosDSname);
IRasterDataset3 pInDS = (IRasterDataset3)pMosDS;
IRaster pInRaster = pInDS.CreateFullRaster();
IPixelOperation pPixOp = (IPixelOperation)pInRaster;
IClipFilter pClipFilter = new ClipFilterClass();
// add some geometries to the clip filter, in the same spatial reference as the raster
pPixOp.PixelFilter = (IPixelFilter) pClipFilter;
// then read/write the raster
IPnt ReadBlockSize = new PntClass();
IPnt SrcUpperLeft = new PntClass();
IPnt DestUpperLeft = new PntClass();
// create the pixel block for read/write
ReadBlockSize.SetCoords(pDestCols, RowsToRead);
IPixelBlock pReadBlock = pInRaster.CreatePixelBlock(ReadBlockSize);
IRasterEdit pWriteEdit = (IRasterEdit)pWriteRaster;
for (int RowMin = 0; RowMin < pDestRows; RowMin += RowsToRead)
{
SrcUpperLeft.SetCoords(pSrcColOffset, pSrcRowOffset + RowMin);
DestUpperLeft.SetCoords(0, RowMin);
pInRaster.Read(SrcUpperLeft, pReadBlock);
//(pClipFilter as IPixelFilter).Filter(pReadBlock);// tried this too, but it still didn't work
pWriteEdit.Write(DestUpperLeft, pReadBlock);
}
The result:
The image is the size of the dataset which is correct but the pixels are unfiltered. Does IPixelOperation, IClipFilter only work in ArcMap or with IRasterLayer? Do I need to supply the geometries in cell coordinates? Is there an updated/different interface required to work with an IMosaicDataset?... I've tried several different combinations of readers/writers/filterers and none of them seem to have any affect - What am I missing?