Cannot open a mosaic dataset with ArcObjects / Java

4692
2
10-23-2014 10:44 PM
PeterBarrs
New Contributor

Hello,

 

I would be most grateful for help with the following. Below is some annotated Java code and output for two different attempts at opening a mosaic dataset, neither of which work for me. Further below is the equivalent C# code and output, which does work. I've tried with both ArcGIS Desktop 10.2.1 and 10.2.2, standard edition.

 

Thanks, Peter Barrs.

       

// JAVA static void accessMosaicDataset() throws IOException {          IWorkspaceFactory wf              = new FileGDBWorkspaceFactory();          IWorkspace ws              = wf.openFromFile("C:\\temp\\DataArchiveCatalog.gdb", 0);                  // below is the recommended access method and aligns with the object diagram         // "DataSourcesRaster Object Model (Mosaic Dataset)"          IMosaicWorkspaceExtensionHelper helper = new MosaicWorkspaceExtensionHelper();         IMosaicWorkspaceExtension mwex = helper                 .findExtension(ws);                  System.out.println("\nMethod 1 - direct open");                  // fails here (md is always null, no error), no exception is thrown         // if the name is changed to a non existent mosaic dataset name, an exception is         // thrown to that effect                  // However, it is possible to delete the mosaic dataset                  IMosaicDataset md = mwex.openMosaicDataset("DataArchiveImageCatalog");                  if (md == null)             System.out.println("md = null");         else             System.out.println("md catalog oid name = " + md.getCatalog().getOIDFieldName());                   System.out.println("\nMethod 2 - open using an IWorkspaceName obtained by enumeration");                  IDatasetContainer3 dscntr = (IDatasetContainer3) mwex;         IEnumDatasetName dns = dscntr                 .getDatasetNames(esriDatasetType.esriDTMosaicDataset);                  IDatasetName dn = dns.next(); // actually gives a IDatasetNameProxy             // which cannot be cast to IMosaicDatasetName                  while (dn != null) {                          // prints mosaic dataset name             System.out.println("dataset name: " + dn.getName());                           // prints geodatabase name             IWorkspaceName wn = dn.getWorkspaceName();             System.out.println("workspace name = " + wn.getBrowseName());                          MosaicDatasetName mdn = new MosaicDatasetName();                          mdn.setWorkspaceNameByRef(wn);             mdn.setName(dn.getName());              Object o = mdn.open();                          // In the eclipse debugger, o is shown as an RasterDataset             // and it can indeed be opened as a RasterDataset                          IRasterDataset rd = (IRasterDataset) mdn.open();                          System.out.println("as raster dataset, format = " + rd.getFormat());              // Attempting to open it as an IMosaicDataset fails             // com.esri.arcgis.datasourcesraster.RasterDataset cannot be cast to com.esri.arcgis.datasourcesraster.IMosaicDataset                          md = (IMosaicDataset) mdn.open();             System.out.println("md catalog oid name = " + md.getCatalog().getOIDFieldName());             dn = dns.next();         }            }

 

Java output

Method 1 - direct open

md = null

 

Method 2 - open using an IWorkspaceName obtained by enumeration

dataset name: DataArchiveImageCatalog

workspace name = DataArchiveCatalog

as raster dataset, format = AMD

Exception in thread "main" java.lang.ClassCastException: com.esri.arcgis.datasourcesraster.RasterDataset cannot be cast to com.esri.arcgis.datasourcesraster.IMosaicDataset

    at mosaicDataset.Main.accessMosaicDataset(Main.java:117)

    at mosaicDataset.Main.main(Main.java:43)

 

C# Version

 

// C# equivalent static void accessMosaicDataset() {     IWorkspaceFactory wf         = new FileGDBWorkspaceFactory();     IWorkspace ws         = wf.OpenFromFile("C:\\temp\\DataArchiveCatalog.gdb", 0);      IMosaicWorkspaceExtensionHelper helper = new MosaicWorkspaceExtensionHelper();     IMosaicWorkspaceExtension mwex = helper             .FindExtension(ws);      Debug.WriteLine("\nMethod 1 - direct open - works fine");      IMosaicDataset md = mwex.OpenMosaicDataset("DataArchiveImageCatalog");      Debug.WriteLine("md catalog oid name = " + md.Catalog.OIDFieldName);       Debug.WriteLine("\nMethod 2 - open using an IWorkspaceName obtained by enumeration - works fine");      IDatasetContainer3 dscntr = (IDatasetContainer3)mwex;     IEnumDatasetName dns = dscntr             .get_DatasetNames(esriDatasetType.esriDTMosaicDataset);      IDatasetName dn = dns.Next();      while (dn != null)     {          // prints mosaic dataset name         Debug.WriteLine("dataset name: " + dn.Name);          // prints geodatabase name         IWorkspaceName wn = dn.WorkspaceName;         Debug.WriteLine("workspace name = " + wn.BrowseName);          MosaicDatasetNameClass mdn = new MosaicDatasetNameClass();          mdn.WorkspaceName = wn;         mdn.Name = dn.Name;          IMosaicDataset md2 = (IMosaicDataset)mdn.Open();          IFeatureClass cat = md2.Catalog;         Debug.WriteLine("md catalog oid name = " + md2.Catalog.OIDFieldName);          dn = dns.Next();     } }

 

C# output

Method 1 - direct open - works fine

md catalog oid name = OBJECTID

 

Method 2 - open using an IWorkspaceName obtained by enumeration - works fine

dataset name: DataArchiveImageCatalog

workspace name = DataArchiveCatalog

md catalog oid name = OBJECTID

2 Replies
ChrisGreen
New Contributor III

Hi Peter!  Were you ever able to figure this out?  I've bumped into this too, and I am close to rewriting this process of mine using a different API.  I greatly appreciate you putting this question out there. -cg

0 Kudos
PeterBarrs
New Contributor

Hi Chris,

No I didn't, I just continued doing that particular part in C# (batch

environment).

I'm going to look at it again however, as I do need to bring the code

together - maybe looking at the proxy classes. If I don't get anywhere

with that I'll raise it with ESRI. It's possibly changed for the better

in 10.3, as well.

I had a similar problem with creating layer files for individual rasters

from a mosaic dataset (use the "lock" method) - that would only work in

Java, not C# !!

Cheers, pb

0 Kudos