Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I create a RelQueryTable like this to join a GeoFeatureLayer to an external table. Everything seems to work (no errors, I can look in the table and see the correct fields.) Silly question: what do I return from this that I can use as a GeoFeatureLayer? When I try to cast the table to GeoFeatureLayer it will not work. It was hard enough to riddle out how this even worked (and I still have many unanswered questions that the bathtub documentation doesn't help with while I'm adrift at sea.)

Does anyone have intelligent samples for these APIs? (Instead of changing 9.x to 10.x they should have released some code.)

Type memoryRelationshipClassFactory = Type.GetTypeFromProgID    
    ( "esriGeodatabase.MemoryRelationshipClassFactory" );
IMemoryRelationshipClassFactory memoryRelationshipFactory =
    Activator.CreateInstance( memoryRelationshipClassFactory ) as     

IRelationshipClass relationshipClass = memoryRelationshipFactory.Open(
geoFeatureLayer.DisplayFeatureClass as IObjectClass,
table as IObjectClass,
esriRelCardinality.esriRelCardinalityOneToOne );

Type rqtFactoryType = Type.GetTypeFromProgID( "esriGeodatabase.RelQueryTableFactory" );
IRelQueryTableFactory rqtFactory = Activator.CreateInstance( rqtFactoryType ) as 

IRelQueryTable relQueryTable = rqtFactory.Open(
    false ) as IRelQueryTable;
share|improve this question
Did you try setting geoFeaturelayer.Featureclass = relQueryTable at the end? – Kirk Kuykendall Oct 20 '11 at 20:51
Once I actually got the join to work that seems to work! (Had tried that before but the join was failing.) – Chaz Oct 21 '11 at 15:36
Also! Tried this but how do you use the DisplayFeatureClass? After this code it had the correct fields but they were not used during labeling. IDisplayRelationshipClass displayRelationshipClass = geoFeatureLayer as IDisplayRelationshipClass; displayRelationshipClass.DisplayRelationshipClass( relationshipClass, esriJoinType.esriLeftOuterJoin ); – Chaz Oct 21 '11 at 15:40
Do you have arcmap? If this is a configuration that gets set at startup, it sure would be easier to use arcmap to setup the joins, save the mxd, then have your engine app use the mxd. I think 60 day eval licenses are available. – Kirk Kuykendall Oct 21 '11 at 15:49
I grok that but I specifically want a dynamic join. (I am only using it for labeling.) The request is to enable labeling for 90+ fields and when I embedded the join with only 25 in the MXD it suddenly started taking 3 minutes plus to load the doc. – Chaz Oct 21 '11 at 21:14
up vote 1 down vote accepted

For the benefit of anyone interested. This works once you ensure that you have a good Table and FeatureClass to build the RelQueryTable:

geoFeatureLayer.FeatureClass = relQueryTable as IFeatureClass;
share|improve this answer

Chaz & Kirk -

I was unable to get the

geoFeatureLayer.FeatureClass = relQueryTable as IFeatureClass;

to work. I had to resort to creating a new FeatureLayer and removing the one originally added. it's a decent solution for now but if either of you could provide a little more insight on what you've done I would appreciate it.

share|improve this answer
This does not really answer the question (which was asked over 2 years ago, BTW). I would suggest asking your own question and referencing this one as needed. – blah238 Mar 26 '14 at 19:17
Yes, you're right. I didn't really think about that. I was in a tizzy. – kyle k Mar 27 '14 at 19:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.