Select to view content in your preferred language

Get all edits in a version

1608
2
Jump to solution
10-29-2019 05:05 PM
JimmyBowden
Frequent Contributor

I'm in need of getting all the features (feature class and oid) that have been edited in a version.  I've seen the example of using a differences cursor ProConcepts Geodatabase · Esri/arcgis-pro-sdk Wiki · GitHub . I'm hoping there's a shortcut in the ArcGIS Pro SDK that prevents me from having to iterate all the feature classes with each difference type.  Any thoughts?  Thanks in advance.

0 Kudos
1 Solution

Accepted Solutions
RichRuh
Esri Regular Contributor

There’s no shortcut. If you’re calling this against a feature service, only one REST call is made. 

View solution in original post

0 Kudos
2 Replies
RichRuh
Esri Regular Contributor

There’s no shortcut. If you’re calling this against a feature service, only one REST call is made. 

0 Kudos
JimmyBowden
Frequent Contributor

Thanks for the quick response. I still have some concerns about getting the "right" list of feature classes to use but I have enough to work with.  Here's the code I came up with:  

using ArcGIS.Core.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Version = ArcGIS.Core.Data.Version;

namespace MyNameSpace
{
    public class VersionChangesService
    {
        public List<VersionChangesGetChanges(Version version, List<string> featureclassnames)
        {
            List<VersionChanges> retval = new List<VersionChanges>();

            foreach (var item in featureclassnames)
            {
                retval.Add(GetVersionChangesByFeatureClass(versionitem));
            }
            return retval;
        }

        private VersionChanges GetVersionChangesByFeatureClass(Version version, string featureclassname)
        {
            using (Geodatabase versiongdb = version.Connect())
            {
                using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
                {
                    using (FeatureClass defaultFc = geodatabase.OpenDataset<FeatureClass>(featureclassname))
                    {
                        using (FeatureClass versionFc = versiongdb.OpenDataset<FeatureClass>(featureclassname))
                        {
                            List<VersionChange> diffs = GetAllDifferences(defaultFcversionFc);
                            return new VersionChanges { featureClass = versionFcChanges = diffs };
                        }
                    }
                }
            }
        }

        private List<VersionChangeGetAllDifferences(FeatureClass defaultFc, FeatureClass versionFc)
        {
            List<VersionChange> retval = new List<VersionChange>();
            retval.AddRange(GetDifferences(defaultFcversionFcDifferenceType.DeleteNoChange));
            retval.AddRange(GetDifferences(defaultFcversionFcDifferenceType.DeleteUpdate));
            retval.AddRange(GetDifferences(defaultFcversionFcDifferenceType.Insert));
            retval.AddRange(GetDifferences(defaultFcversionFcDifferenceType.UpdateDelete));
            retval.AddRange(GetDifferences(defaultFcversionFcDifferenceType.UpdateNoChange));
            retval.AddRange(GetDifferences(defaultFcversionFcDifferenceType.UpdateUpdate));

            return retval;
        }

        private List<VersionChangeGetDifferences(FeatureClass defaultFc, FeatureClass versionFc, DifferenceType differenceType)
        {
            List<VersionChange> retval = new List<VersionChange>();
            using (DifferenceCursor differenceCursor = versionFc.Differences(defaultFcdifferenceType))
            {
                List<long> diffs = new List<long>();
                while (differenceCursor.MoveNext())
                {
                    using (Row current = differenceCursor.Current)
                    {
                        diffs.Add(differenceCursor.ObjectID);
                    }

                }
                retval.AddRange(diffs.Select(s => new VersionChange { objectId = sdifferenceType = DifferenceType.DeleteNoChange }));
            }
            return retval;
        }
    }

    public class VersionChange
    {
        public DifferenceType differenceType { getset; }

        public long objectId { getset; }
    }

    public class VersionChanges
    {
        public FeatureClass featureClass { getset; }
        public List<VersionChange> Changes { getset; }
    }
}
0 Kudos