Engine中对MosaicDataset的操作:添加、获取、删除

1.如何往Mosaicdatast里添加栅格?
2.如何获取Mosaicdataset里某个栅格的物理路径?
3.如何删除Mosaicdataset里的某个栅格?
已邀请:

刘峥 - ArcGIS多面手

赞同来自:

【解决办法】:
1.如何往Mosaicdatast里添加栅格?
public void AddRastersToMD(IMosaicDataset theMosaicDataset, IRasterType theRasterType)
{
// Create a file crawler.
IDataSourceCrawler myCrawler = new FileCrawlerClass();
// Specify the source path.
((IFileCrawler)myCrawler).Path = @C:TestData;
// Specify whether to search subdirectories.
((IFileCrawler)myCrawler).Recurse = true;
// Specify a file filter.
((IFileCrawler)myCrawler).Filters = .TIF;

// The mosaic dataset operation interface is used to perform operations on
// a mosaic dataset.
IMosaicDatasetOperation theMosaicDatasetOperation =
(IMosaicDatasetOperation)(theMosaicDataset);
// Create an AddRaster parameters object.
IAddRastersParameters AddRastersArgs = new AddRastersParametersClass();
// Specify the data crawler to use to crawl the data.
AddRastersArgs.Crawler = myCrawler;
// Specify the raster type to use to add the data.
AddRastersArgs.RasterType = theRasterType;
// Use the mosaic dataset operation interface to add
// rasters to the mosaic dataset.
theMosaicDatasetOperation.AddRasters(AddRastersArgs, null);
}

2.如何获取Mosaicdataset里某个栅格的物理路径?

通过IMosaicDataset.Catalog获取feature,转为IRasterCatalogItem,获取RasterDataset,转为IRasterDatasetInfo,通过IRasterDatasetInfo.FileList获取路径。
Public IRasterDataset GetRasterCatalogItem(IRasterCatalog catalog, int oid)
{
//OID is the ObjectID of the raster dataset in the raster catalog.
IFeatureClass featureClass = (IFeatureClass)catalog;
IRasterCatalogItem rasterCatalogItem = (IRasterCatalogItem)
featureClass.GetFeature(oid);
IRasterDataset rasterDataset = rasterCatalogItem.rasterdataset;
IRasterDatasetInfo rasterDatasetInfo = (IRasterDatasetInfo)rasterDataset;

for(int ind=0;ind<rasterDatasetInfo.FileList.Count;ind++)
{
string strName = rasterDatasetInfo.FileList.get_Element(ind);
MessageBox.Show(strName);
}

3.如何删除Mosaicdataset里的某个栅格?

将raster catalog的featureclass里的feature删除即可。
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
IWorkspace fgdbWorkspace = workspaceFactory.OpenFromFile(@E:scratch.gdb, 0);
// Create the mosaic workspace extension helper class.
IMosaicWorkspaceExtensionHelper mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass();
// Find the right extension from the workspace.
IMosaicWorkspaceExtension mosaicExt = mosaicExtHelper.FindExtension(fgdbWorkspace);
// Use the extension to open the mosaic dataset.
IMosaicDataset theMosaicDataset = mosaicExt.OpenMosaicDataset(mosaicdataset);

IFeatureClass fc = theMosaicDataset.Catalog;
ITable table = fc as ITable;
IQueryFilter qf = new QueryFilterClass();
string whereclause = Name = 'test';
qf.WhereClause = whereclause;
table.DeleteSearchedRows(qf);

刘峥 - ArcGIS多面手

赞同来自: 陈於立

第一个参数IMosaicDataset是已有的镶嵌数据集,也就是被插入的镶嵌数据集,可以用以下代码获取:
 IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass(); 
IWorkspace fgdbWorkspace = workspaceFactory.OpenFromFile(@"C:\testGdb.gdb", 0); IMosaicWorkspaceExtensionHelper mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass(); IMosaicWorkspaceExtension mosaicExt = mosaicExtHelper.FindExtension(fgdbWorkspace); IMosaicDataset theMosaicDataset = mosaicExt.OpenMosaicDataset("testMD");
 
第二个参数是要插入的栅格数据类型,比如要插入的栅格是*.tif格式的:
string dataSourceFilter = "*.tif"; 
IRasterTypeName theRasterTypeName = new RasterTypeNameClass(); 
theRasterTypeName.Name = "Raster Dataset"; 
IRasterType theRasterType = (IRasterType)(((IName)theRasterTypeName).Open()); 
((IRasterTypeProperties)theRasterType).DataSourceFilter = dataSourceFilter; 

liyuan

赞同来自:

请问 添加栅格方法的两个参数对象  可以怎么生成?  就是说如何使用??

liyuan

赞同来自:

IRasterType theRasterType = (IRasterType)(((IName)theRasterTypeName).Open()); 
代码在走到这句时报错了
com.esri.arcgis.interop.NativeObjRef cannot be cast to com.esri.arcgis.datasourcesraster.IRasterType
请问这个怎么解决??

要回复问题请先登录注册