2.4.3 BasicFeatureLayer Search Subfield ObjectID Fail

710
4
01-03-2020 10:54 AM
MKa
by
Occasional Contributor III

I am in the process of upgrading my users from ArcGIS Pro 2.2.3 to 2.4.3.  I have run into this issue.  I have a function that returns only the ObjectIDs for a where clause applied to a basicfeaturelayer.  I do this in order to get a quick list of features based on a simple where clause.  I just return the SubFields of OBJECTID in the query filter to optimize the efficiency of the return rowcursor.

When I moved to ArcGIS Pro 2.4.3, the queryfilter subfields value of "OBJECTID" seems to not work any longer.  In fact, the resulting rowcursor seems to return all records.  In order to get the query to work correctly I added shape to the subfields value and now the query works again.  "Shape, OBJECTID".  However, I think this might be affecting my efficiency as I only need the OBJECTIDS.  Is this a bug or is there a different way to return the rowcursor of just the subfields of ObjectID?

BasicFeatureLayer searchLayer = GetBasicFeaturLayer(layerName);

//This subfields fails in 2.4.3  I cant use just objectid in the subfield after the upgrade
//string inSubFields = "OBJECTID";

//This subFields works, i had to add an additional field in order for this to work in //2.4.3
string inSubFields = "Shape, OBJECTID";

var queryFilter = new QueryFilter
{
   WhereClause = string.Format("{0} IN ('{1}')", inIDFieldName, ContainsClause);,
   SubFields = inSubFields
};

// apply the spatial filter to the feature layer in question
RowCursor rowCursor = null;
rowCursor = searchLayer.Search(queryFilter);

//*******************************
//This loop fails after the upgrade from 2.2, when i just use 
// objectid in the subfield the rowcurser seems to return every feature
//*******************************
//Add all the resulting objectIDs to a list to later load or use
while (rowCursor != null && rowCursor.MoveNext())
{
   if (rowCursor.Current != null)
   {
      featuresByIDList.Add(rowCursor.Current.GetObjectID());
   }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (1)
4 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi M,

 I tried your code using ArcGIS Pro 2.4.3 and the FeatureTest project from the community samples data set and was not able to duplicate the problem you ran into.  This is the code that i used to test:

protected override async void OnClick()
{
    BasicFeatureLayer searchLayer = GetBasicFeaturLayer("TestPoint");

    //This subfields fails in 2.4.3  I cant use just objectid in the subfield after the upgrade
    string inSubFields = "OBJECTID";

    //This subFields works, i had to add an additional field in order for this to work in //2.4.3
    //string inSubFields = "Shape, OBJECTID";

    var queryFilter = new QueryFilter
    {
        WhereClause = string.Format("{0} IN ('{1}')", "Description", "Update 2 on: 2015-06-26T10:46:40"),
        SubFields = inSubFields
    };

    var oidList = await QueuedTask.Run<List<long>>(() =>
    {

        // apply the spatial filter to the feature layer in question
        RowCursor rowCursor = null;
        rowCursor = searchLayer.Search(queryFilter);

        List<long> featuresByIDList = new List<long>();
        //*******************************
        //This loop fails after the upgrade from 2.2, when i just use 
        // objectid in the subfield the rowcursor seems to return every feature
        //*******************************
        //Add all the resulting objectIDs to a list to later load or use
        while (rowCursor != null && rowCursor.MoveNext())
        {
            if (rowCursor.Current != null)
            {
                featuresByIDList.Add(rowCursor.Current.GetObjectID());
            }
        }
        return featuresByIDList;
    });
    MessageBox.Show($@"Feature count: {oidList.Count}");
}

private BasicFeatureLayer GetBasicFeaturLayer(string layerName)
{
    return MapView.Active?.Map?.GetLayersAsFlattenedList().OfType<BasicFeatureLayer>().Where(fl => fl.Name.Contains(layerName)).FirstOrDefault();
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I get exactly one record regardless of the number of subfields.  I should mention this the feature layer I used is from a file geodatabase.  Maybe you used a Database or Service as the datasource?

0 Kudos
MKa
by
Occasional Contributor III

I am using a service as the datasource.  It only happens when I use "OBJECTID" as the only subfield.  If I use "GlobalID" for instance, I don't have any problems either.  I have switch all of my subfield requests from "OBJECTID" to "GlobalID, OBJECTID" until I can figure this out.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

i setup a feature service (data is stored in a registered SQL Server enterprise GDB) and i am not able to duplicate the problem you are seeing.  I tried a file Geodatabase, SQL server enterprise Geodatabase, and a feature service.  I can't get it to fail.  all using version 2.4.3.

0 Kudos
AKGIS
by
New Contributor

I had a similar issue that seemed to resolve after removing "OBJECTID" from the SubField. "OBJECTID" was the only thing assigned to SubField. 

When I searched the feature layer, it seemed to get stuck in the while loop and kept getting the same objectId from the row cursor repeatedly.

Pro 2.9.6. Working in a named branch version. The layers are coming from a feature service.

                var basicFeatureLayer = layer as BasicFeatureLayer;
                try
                {
                    using (var selection = basicFeatureLayer.Search(qf))
                    {
                        List<long> oids = new List<long>();
                        while (selection.MoveNext())
                        {
                            oids.Add(selection.Current.GetObjectID());
                        }
                        if (oids.Count > 0)
                        {
                            features.Add(basicFeatureLayer, oids);
                        }

                    }
                }

 

0 Kudos