Incorrect Zoom-to Scale After AddSpatialIndex

199
2
04-19-2024 12:51 PM
ARO
by
New Contributor

I'm building an Add-in in ArcGIS Pro 3.2.2 and working on fixing the zoom-to extent after an imported 3D object (.OBJ file) multipatch geodatabase feature class has been moved to a set lat/long/elevation. When the object has been moved, the zoom scale becomes extreme (about the size of Africa) when moved from the original location (0, 0) to France (2, 48). This can be fixed within the ArcGIS UI by using the "Add Spatial Index" geoprocessing tool. However, when attempting to use this tool within the .NET SDK or using ArcPy, the spatial index is fixed, but only after closing ArcGIS Pro and opening the project back up.

public static async Task AddSpatialIndexAsync(string featureClassPath)
{
try
{

var arguments = Geoprocessing.MakeValueArray(featureClassPath);


IGPResult result = await Geoprocessing.ExecuteToolAsync("management.AddSpatialIndex", arguments);

if (result.IsFailed)
{

System.Diagnostics.Debug.WriteLine("Failed to add spatial index: " + result.ErrorCode);
foreach (var msg in result.Messages)
System.Diagnostics.Debug.WriteLine(msg.Text);
}
else
{
System.Diagnostics.Debug.WriteLine("Spatial index added successfully.");
}
}
catch (Exception ex)
{

System.Diagnostics.Debug.WriteLine("Error adding spatial index: " + ex.Message);
}
}

What's the difference between using the Geoprocessing tool directly and calling the Geoprocessing tool from the .NET SDK?

0 Kudos
2 Replies
Aashis
by Esri Contributor
Esri Contributor

Have you called the map view redraw after the index update?

0 Kudos
ARO
by
New Contributor

Yeah, I've tried that. Here's a list of various attempts at clearing caches, refreshing, and redrawing:

        public static void ForceRefreshLayer(FeatureLayer featureLayer)
        {
            if (featureLayer != null)
            {
                // Toggle visibility

                QueuedTask.Run(() => { featureLayer.SetVisibility(false); });
                System.Threading.Thread.Sleep(100); // Short delay to ensure UI updates
                QueuedTask.Run(() => { featureLayer.SetVisibility(true); });

                MapView.Active.Invalidate(featureLayer, null);
                QueuedTask.Run(() => { MapView.Active.Redraw(true); });

                QueuedTask.Run(() =>
                {
                    var renderer = featureLayer.GetRenderer();
                    featureLayer.SetRenderer(null);
                    System.Threading.Thread.Sleep(100); // Let UI catch up
                    featureLayer.SetRenderer(renderer);
                });

                var dbConnection = Project.Current.GetGeodatabases();
                QueuedTask.Run(() => dbConnection.Refresh());

                var contentItem = Project.Current.GetItems<FolderConnectionProjectItem>().First();
                if (contentItem.IsMainThreadRequired)
                {
                    //QueuedTask.Run must be used if item.IsMainThreadRequired
                    //returns true
                    QueuedTask.Run(() => contentItem.Refresh());
                }
                else
                {
                    contentItem.Refresh();

                    ArcGIS.Core.Threading.Tasks.BackgroundTask.Run(() =>
                      contentItem.Refresh(), ArcGIS.Core.Threading.Tasks.BackgroundProgressor.None);
                }
            }
        }
0 Kudos