3

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 
 IMemoryRelationshipClassFactory;
IRelationshipClass relationshipClass = memoryRelationshipFactory.Open(
 "Join",
geoFeatureLayer.DisplayFeatureClass as IObjectClass,
layerField,
table as IObjectClass,
tableField,
"forward",
"backward",
esriRelCardinality.esriRelCardinalityOneToOne );
Type rqtFactoryType = Type.GetTypeFromProgID( "esriGeodatabase.RelQueryTableFactory" );
IRelQueryTableFactory rqtFactory = Activator.CreateInstance( rqtFactoryType ) as 
 IRelQueryTableFactory;
IRelQueryTable relQueryTable = rqtFactory.Open(
 relationshipClass,
 true,
 null,
 null,
 EXTERNAL_FIELDS,
 true,
 false ) as IRelQueryTable;
asked Oct 20, 2011 at 19:08
6
  • 1
    Did you try setting geoFeaturelayer.Featureclass = relQueryTable at the end? Commented Oct 20, 2011 at 20:51
  • Once I actually got the join to work that seems to work! (Had tried that before but the join was failing.) Commented Oct 21, 2011 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 ); Commented Oct 21, 2011 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. Commented Oct 21, 2011 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. Commented Oct 21, 2011 at 21:14

2 Answers 2

1

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;
answered Nov 2, 2011 at 15:14
-1

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.

answered Mar 26, 2014 at 18:53
2
  • 1
    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. Commented Mar 26, 2014 at 19:17
  • Yes, you're right. I didn't really think about that. I was in a tizzy. Commented Mar 27, 2014 at 19:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.