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);
}
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;
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);
4 个回复
刘峥 - ArcGIS多面手
赞同来自:
1.如何往Mosaicdatast里添加栅格?
2.如何获取Mosaicdataset里某个栅格的物理路径?
通过IMosaicDataset.Catalog获取feature,转为IRasterCatalogItem,获取RasterDataset,转为IRasterDatasetInfo,通过IRasterDatasetInfo.FileList获取路径。
3.如何删除Mosaicdataset里的某个栅格?
将raster catalog的featureclass里的feature删除即可。
刘峥 - ArcGIS多面手
赞同来自: 陈於立
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
赞同来自:
代码在走到这句时报错了
com.esri.arcgis.interop.NativeObjRef cannot be cast to com.esri.arcgis.datasourcesraster.IRasterType
请问这个怎么解决??
要回复问题请先登录或注册
发起人
ArcGIS多面手
相关问题
问题状态
—— 扫技术支持中心微信服务号!
—— 让GIS知乎问答随时随地!