2

At the moment I've a personal geodatabase with two imported feature classes from shape files and an own created table. This table has columns for the IDs of the elements in the two feature classes. With ArcCatalog I've created two relationship classes between each sfeature class and the table. Both are 1:1 relationsships. Within ArcMap the user can open the table and get access to more detailed informations by using this relationsships (menu -> Related Tables).

Background: One feature class holds features consisting of Polylines, the other features consisting of Points. With the Table I can create a logical relationship between one Point and one Polyline and can add more informations in this table which are only valid for this special relation.

Now I've to work with this table in C# and I've to access the other feature classes too. It's no problem to read the IDs out of the table and start a QueryFilter for the feature class where I need the informations from.

Sure, this is one possible way but there must exist a more efficient way where I can use the relationship classes for faster operations.

Does anybody know how I can query the relationship classes to get all informations at the same time without querying two different tables "manually"?

Thanks a lot!

Edit:

To be more specific. If the table has the two fields ID_EdgeTo and ID_EdgeFrom and one field has a relationship to the feature class EdgesTo and the other to EdgesFrom.

When I get through the rows and see a combination of ID_EdgeTo and ID_EdgeFrom I want to query the relationship classes to get more information for the ID's in this specific row.

Its more about whether the relationship classes are retrievable and how this has to be done. The table in the database has the form like a "manually created" relationship class with relationship attributes

12
  • 1
    Are these Simple Relationship Classes or Attributed Relationship Classes? Perhaps if you posted screenshots from the properties dialog in ArcCatalog that would help.
    – blah238
    Commented Feb 10, 2013 at 10:23
  • Both are "normal" Simple Relationship Classes. In ArcMap the user can query the table of the geodatabase using this relationships to get the rows (and the information) displayed from the attribut table of the shape files.
    – FredFloete
    Commented Feb 10, 2013 at 10:27
  • When you say shapefiles, you mean feature classes, right? Shapefiles cannot participate in a relationship class (except an in-memory one through RelQueryTable).
    – blah238
    Commented Feb 10, 2013 at 10:29
  • Yes. I've created a personal geodatabase and import the "Shape Files" so the feature classes of the shape files are a part of the geodatabase. I used the terms for a better understanding to get a clear separation between the table created by my own an the imported classes.I hope you understand me right. The selection which the user makes on the user interface in ArcMAP to get the rows and information of out of the feature classes are the steps which I want to perform in C#. In this case for the "easy" example but in the future for more complex cases
    – FredFloete
    Commented Feb 10, 2013 at 10:43
  • Always use the most relevant terms for the type of workspace you are talking about. Shapefiles cannot exist in geodatabases, hence my confusion. I understand now though.
    – blah238
    Commented Feb 10, 2013 at 10:50

2 Answers 2

2

Based on your additional notes it sounds like you will want to use the IRelationshipClass.GetObjectsRelatedToObject method, at least for starters.

For better performance you might consider using one of the other methods, such as GetObjectsRelatedToObjectSet that takes a set of input objects though. This will reduce the number of round trips to the database if you are doing this in batch.

Additionally if you want to specify a QueryFilter over a given set of input objects (this might not be necessary if your cursor is already being filtered), take a look at IRelationshipClass2.GetObjectsMatchingObjectSetEx.

For code examples I would suggest searching the ESRI forums (new and old), as well as this site: Example search

Some relevant results:

Without having a relevant sample dataset I am reluctant to write a code example myself. Perhaps you could upload an ESRI XML Workspace document for a subset of your data, and describe the desired user interaction workflow, inputs and outputs.

Also refer to the available documentation:

Relationship Objects
(source: arcgis.com)

1
  • Thanks for you reply I know the "Help topic on relationship classes" and the "Creating relationship classes" topic but in my case this two links carry not the information I need. The Object Model Diagrams is a good overview over the interfaces.
    – FredFloete
    Commented Feb 10, 2013 at 10:24
0

Take a look at the following example:

//IRelationship Example
public void IRelationship_Example(IFeature feature)
{
    //assumes that only one RelationshipClass exists for the Origin feature class
    IEnumRelationshipClass enumRelClass = feature.Class.get_RelationshipClasses(esriRelRole.esriRelRoleAny);
    IRelationshipClass relClass = enumRelClass.Next();
    //if a feature with no Relationships established has been selected, exit
    if (relClass == null)
    {
        return;
    }
    ESRI.ArcGIS.esriSystem.ISet relSet = relClass.GetObjectsRelatedToObject((IObject)feature);
    relSet.Reset();
    //If an Attributed Relationship does not exist, exit
    if (relClass.IsAttributed != true)
    {
        return;
    }
    IFeature destinationFeature = (IFeature)relSet.Next();
    while (destinationFeature != null)
    {
        IRelationship relationship = relClass.GetRelationship((IObject)feature, (IObject)destinationFeature);
        IRow row = (IRow)relationship;
        object attributeValue;
        if (row.get_Value(0) == null)
        {
            attributeValue = "0";
        }
        else
        {
            attributeValue = row.get_Value(0);
        }
        Console.WriteLine("Destination OID: {0}  Origin OID:  {1}  Attribute value:  {2}", relationship.DestinationObject.get_Value(0), relationship.OriginObject.get_Value(0), attributeValue);
        destinationFeature = (IFeature)relSet.Next();
    }
}

This piece of code (taken from here) helped me a lot to archieve the goal you have carried out in your initial question. I have tested it and I am using it for ArcMap 10.x/ArcObjects SDK for .NET Framework 10.x.

Your Answer

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

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