2

I have added a layer in the ArcMap. I want to see the different values of the items of this layer using the "Time Slider". For this, I have prepared a table that contains a field named DateTime and its type is Date. After completing data preparation I have joined the table with the layer using ArcObjects C# .NET AddJoin tool. After this, when I calculate the layer time extent. It set start time and end time the same as the start time.

enter image description here enter image description here

If I remove join from the layer or skip the join operation using ArcObjects and join the table with the layer manually in ArcMap then it works fine.

enter image description here AddJoin Tool Code:

public AddJoin(string inputLayerName, string inputTableField, string tableToBeJoinedPath, string toBeJoinedField)
    {
        _inputLayerName = inputLayerName;
        _inputTableField = inputTableField;
        _tableToBeJoinedPath = tableToBeJoinedPath;
        _toBeJoinedField = toBeJoinedField;
    }

    public IGpResult Execute()
    {
        try
        {
            var addJoinTool = InitTool();
            var result = _gp.Execute(addJoinTool, null) as IGeoProcessorResult;
            return null;
        }
        catch (Exception exception)
        {
            return null;
        }
    }

    private ESRI.ArcGIS.DataManagementTools.AddJoin InitTool()
    {
        _gp = new Geoprocessor { OverwriteOutput = true, AddOutputsToMap = false };
        var addJoin = new ESRI.ArcGIS.DataManagementTools.AddJoin()
        {
            in_layer_or_view = _inputLayerName,
            in_field = _inputTableField,
            join_table = _tableToBeJoinedPath.Replace(@"\", @"\\"),
            join_field = _toBeJoinedField,
            join_type = "KEEP_ALL",
        };
        _gp.OverwriteOutput = true;
        return addJoin;
    }        
}

How can I join it using ArcObjects and make it workable?

11
  • 1
    I don't see any C# code, what AddJoin tool are you referring to? Is the field a datetime field or a string field with date text? Commented Jul 2, 2020 at 7:31
  • 2
    Please show the code where you set the time properties of the layer.
    – Hornbydd
    Commented Jul 2, 2020 at 8:42
  • 1
    This isn't ArcObjects code, it's a C# implementation of a geoprocessing tool. I think the interface you're after is IMapTimeDisplay resources.arcgis.com/en/help/arcobjects-net/componenthelp/… implemented by Map and ITimeData resources.arcgis.com/en/help/arcobjects-net/componenthelp/… implemented by IFeatureLayer but how to get there from where you are is not a trivial matter and requires real ArcObjects code. Commented Jul 3, 2020 at 0:08
  • 1
    I think you may be confused with what ArcObjects is and isn't, arcpy isn't ArcObjects even if it comes in a C# wrapper, ArcObjects derive from ArcMap.Application and are implemented with interfaces from ArcObjects resources.arcgis.com/en/help/arcobjects-net/componenthelp/… there is a massive gulf between where you are in the supplied code and what you want to achieve. Commented Jul 3, 2020 at 4:52
  • 2
    That is from the ArcObjects help but is a standalone geoprocessor interface, if you approach from the ArcObjects component tree it's a quick way to do some trivial tasks however calling it as isolated code is the same as running the arcpy version of the add join tool, I've done this in ArcObjects and it takes about twice as much code as you have there to get the IStandaloneTable and IDisplayRelationshipClass together to join, what code you have is nearly inconsequential, what we would need to see is how this relates to an ILayer that implements FeatureLayer. Commented Jul 3, 2020 at 5:40

1 Answer 1

2

Instead of AddJoin geoprocessor tool, I do it with IDisplayRelationshipClass and now it's working fine.
Code developed for this:

public void Join(IFeatureLayer featureLayer, string foreignKeyField, ITable table, string primaryKeyField)
    {
        try
        {                
           using (var comReleaser = new ComReleaser())
           {
               var memRelClassFactoryType = Type.GetTypeFromProgID("esriGeodatabase.MemoryRelationshipClassFactory");
               var memRelClassFactory = (IMemoryRelationshipClassFactory)Activator.CreateInstance(memRelClassFactoryType);
               var tableObjectClass = (ESRI.ArcGIS.Geodatabase.IObjectClass)table;
               var geoFeatureLayer = featureLayer as ESRI.ArcGIS.Carto.IGeoFeatureLayer;
               var pRelClass = memRelClassFactory.Open(table.Name + "To" + featureLayer.Name, tableObjectClass, primaryKeyField, geoFeatureLayer.DisplayFeatureClass, foreignKeyField, "ForwardPath", "BackwardPath",
                        esriRelCardinality.esriRelCardinalityOneToMany);
               comReleaser.ManageLifetime(pRelClass);
               var displayRelationshipClass = (ESRI.ArcGIS.Carto.IDisplayRelationshipClass)geoFeatureLayer;
               comReleaser.ManageLifetime(displayRelationshipClass);
                    displayRelationshipClass.DisplayRelationshipClass(pRelClass, esriJoinType.esriLeftOuterJoin);
           }
        }
        catch (COMException e)
        {
            Console.WriteLine(e);
        }
    }

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.