Scenario:
Editing Feature Layers in an SDE database. The SDE data is being edited in a single workspace edit session (does not seem likely that this matters). When a feature is created, that feature is intersected against a reference layer. The reference layer is a Feature Layer hosted in Portal. Both the SDE and the Portal hosted layers are included in a Pro project. The reference layer needs to be not visible when the Pro project opens. To intersect, the following code runs within a QueuedTask. The featureLayer variable is the Portal hosted Feature Layer included in the Pro project. The geometry variable is coming from the feature created in the SDE Feature Layer.
var spatialQueryFilter = new SpatialQueryFilter()
{
FilterGeometry = geometry,
SpatialRelationship = SpatialRelationship.Intersects,
SubFields = "globalid"
};
using var rowCursor = featureLayer.Search(spatialQueryFilter);
while (rowCursor.MoveNext())
{
Row row = rowCursor.Current;
Feature feature = row as Feature;
Geometry geometryIntersectingFeature = feature.GetShape();
var intersectionGeometry = GeometryEngine.Instance.Intersection(geometry, geometryIntersectingFeature);
// … do stuff with intersectionGeometry
}
Issue:
If the Portal hosted Feature Layer is not visible when the Pro project opens, GeometryEngine.Instance.Intersection fails because geometryIntersectingFeature is null.
Error:
ArgumentNullException
Geometry is null (Parameter 'geometry2')
I have verified that it is geometryIntersectingFeature that is null and not the geometry variable.
What I have tried:
Turning the visibility of the Portal hosted Feature Layer on manually in Contents resolves the null geometry error.
If the visibility on the Portal hosted Feature Layer is turned off again after turning it on, the null geometry error does not fire.
If the visibility on the Portal hosted Feature Layer is turned on in the saved Pro project and then turned off manually in Contents before performing the edit, the null geometry error does not fire.
I tried having the Portal hosted Feature Layer visibility turned on in the saved Pro project and then programmatically turning it off (FeatureLayer.SetVisibility(false)) after the DrawCompleteEvent fires, but that still results in the null geometry error.
I tried learning about how Portal hosted Feature Layer geometry is initially loaded but could not find any documentation.
Forcing the user to turn off the visibility manually in Contents is not an option.
Questions:
Is this expected behavior? Is there a workaround? Maybe another event I could listen for to turn off the visibility after the geometry is loaded? Or something I could change about the Portal hosted Feature Layer in the Pro project that would make it load the geometry even though it is not visible on project open?