I'm trying to join a featureclass contained inside a pgdb with a table created with an InMemory Workspace.
The in-memory table contains results that I want to use to define symbology on the featureclass.
The creation of the table goes well, I'm able to see the calculated data, but the IRelationshipClass created returns no records. I tried to use multiple fields to join the data without success. I also added the created table to ArcMap to create the join directcly in ArcMap, without success. It passes all the validations, but returns no records.
I tried to join my inmemory table with a shapefile featureclass instead and it worked.
Here's a sample of code
// Create an in-memory workspace factory.
IWorkspaceFactoryPtr ipWorkspaceFactory(CLSID_InMemoryWorkspaceFactory);
// Create a new in-memory workspace. This returns a name object.
IWorkspaceNamePtr ipWorkspaceName;
ipWorkspaceFactory->Create(NULL, L"ValeursCalculees", NULL, 0, &ipWorkspaceName);
INamePtr ipName(ipWorkspaceName);
// Open the workspace through the name object.
IUnknownPtr ipWorkspaceUnk;
ipName->Open(&ipWorkspaceUnk);
IWorkspacePtr ipWorkspace(ipWorkspaceUnk);
IFeatureWorkspacePtr ipMemoryFeatureWorkspace(ipWorkspace);
IDatasetPtr ipFeatureClassDataset(ipFeatureClass);
CComBSTR strNomFC;
ipFeatureClassDataset->get_Name(&strNomFC);
IFieldsEditPtr ipFieldsEdit(CLSID_Fields);
... Field creation code ...
ITablePtr ipTable;
ipMemoryFeatureWorkspace->CreateTable("InMemoryTable", ipFieldsEdit, NULL, NULL, NULL, &ipTable);
... Table Filling code ...
//IRelQueryTable
IFeatureWorkspacePtr ipFeatureWorkspace(CTools::GetWorkspaceFromFeatureClass(ipFeatureClass));
IObjectClassPtr ipObjectClass(ipTable);
IMemoryRelationshipClassFactoryPtr ipMemoryRelationshipClassFactory(CLSID_MemoryRelationshipClassFactory);
IRelationshipClassPtr ipRelClass;
HRESULT hr = ipMemoryRelationshipClassFactory->Open(L"Join", ipFeatureClass, L"Numero_AD", ipObjectClass, L"NumeroAD", L"forward", L"backward", esriRelCardinalityOneToMany, &ipRelClass);
IDisplayRelationshipClassPtr ipDisplayRelationshipClass(ipFeatureLayer);
ipDisplayRelationshipClass->DisplayRelationshipClass(ipRelClass, esriLeftOuterJoin);
//Add the table to ArcMap
IStandaloneTableCollectionPtr ipStandaloneTableCollection(CTools::GetMap(ipMxDocument));
IStandaloneTablePtr ipStandaloneTable(CLSID_StandaloneTable);
ipStandaloneTable->putref_Table(ipTable);
hr = ipStandaloneTableCollection->AddStandaloneTable(ipStandaloneTable);
ipMxDocument->UpdateContents();
Am-I trying to do something impossible?
Answer
After experimentation, no, it's not possible to create a valid join between a feature class and a table created with an InMemoryWorkspaceFactory. The join is created but it returns no records. It seems to be a limitation in the interaction between InMemoryWorkspace and Geodatabase workspace.
I found a workaround by replacing the InMemoryWorkspaceFactory with a FileGDBScratchWorkspaceFactory. It's a temporary FileGDB workspace stored in the user's temp folder.
The code looks like this
// Create a scratch (temporary) workspace factory.
IScratchWorkspaceFactory2Ptr ipWorkspaceFactory(CLSID_FileGDBScratchWorkspaceFactory);
// Create a new scratch (temporary) workspace. This returns a name object.
IWorkspaceNamePtr ipWorkspaceName;
IWorkspacePtr ipWorkspace;
ipWorkspaceFactory->CreateNewScratchWorkspace(&ipWorkspace);
No comments:
Post a Comment