When I change data source properties of a layer using ArcObjects in C#, I lose the extent set for that layer. How can I reset the layer extent?

Below is the code in which I am resetting database connection properties for a layer causing to loose layer extent values like top, left, bottom, right.

            ESRI.ArcGIS.Carto.ILayer layer = pLayer;

            var dataLayer = (ESRI.ArcGIS.Carto.IDataLayer)layer;
            var datasetName = (IDatasetName)dataLayer.DataSourceName;
            var newWorkspaceName = (IWorkspaceName)((IDataset)targetWorkspace).FullName;

            datasetName.WorkspaceName = newWorkspaceName;
            dataLayer.DataSourceName = (IName)datasetName; ;
            layer = (ESRI.ArcGIS.Carto.ILayer)dataLayer;
  • Does the feature class you're repointing the feature layer to have a valid extent? There is a method to recalculate the extent of a feature class in IFeatureClassManage resources.arcgis.com/en/help/arcobjects-net/componenthelp/… which is implemented by IFeatureClass i.e. ((dataLayer as IFeatureLayer).FeatureClass as IFeatureClassManage).UpdateExtent() which should refresh the extent of the feature class in your IFeatureLayer. – Michael Stimson May 28 '18 at 3:26
  • @MichaelStimson, I added the following code but featureClass.Extent throws an exception. ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (ESRI.ArcGIS.Carto.IFeatureLayer)layer; ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass; ESRI.ArcGIS.Geodatabase.IFeatureClassManage featureClassManage = (ESRI.ArcGIS.Geodatabase.IFeatureClassManage)featureClass; featureClassManage.UpdateExtent(); – jay May 28 '18 at 3:34
  • @MichaelStimson, i get this message in Extent property of my current layer featureclass : Extent = '((ESRI.ArcGIS.Geodatabase.IGeoDataset)(featureClass)).Extent' threw an exception of type 'System.Runtime.InteropServices.COMException' – jay May 28 '18 at 3:43
  • That's odd, what type of data storage is your feature class? – Michael Stimson May 28 '18 at 3:53
  • @MichaelStimson, It does not have a specific featureclass. Under source section in ArcMAp for this layer, it says "FeatureType" as "Simple" and "GeometryType" as "Polygon" – jay May 28 '18 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.