Select to view content in your preferred language

Feature.GetShape error: "The geometry parameter was of the wrong type for the method"

1005
3
Jump to solution
09-16-2022 09:24 AM
succip
by
Occasional Contributor

Hello all,

I'm building a dockpane with two datagrids that collect user features from user input in a mapview. I'd like to draw a connection arrow from the selected feature in the origin datagrid to the selected feature in the destination datagrid. I can't understand why sometimes this works, and sometimes it doesn't using the exact same features. The features I'm querying are in an SDE if that matters and I can confirm the Feature is populated when I inspect it. Here's my code for the connection arrow block:

 

 

 

        public void drawConnectionArrow()
        {
            QueuedTask.Run(() =>
            {
                var mapView = MapView.Active;
                Geometry startGeom = SelectedOriginFeature.Feature.GetShape();
                Geometry endGeom = SelectedDestinationFeature.Feature.GetShape();
                var startPt = MapPointBuilderEx.CreateMapPoint(SelectedOriginFeature.Feature.GetShape().Extent.Center);
                var endPt = MapPointBuilderEx.CreateMapPoint(SelectedDestinationFeature.Feature.GetShape().Extent.Center);
                List<MapPoint> list = new List<MapPoint>();
                list.Add(startPt);
                list.Add(endPt);
                Polyline polyline = PolylineBuilderEx.CreatePolyline(list, mapView.Map.SpatialReference);
                var arrowGraphic = GraphicFactory.Instance.CreateArrowGraphic(polyline, new ArrowInfo());
                mapView.AddOverlay(arrowGraphic);
            });
        }

 

 

 

I added the startGeom/endGeom for testing as it usually fails there to grab the Geometry object from GetShape(). Note sometimes it fails to grab the startGeom, and sometimes it fails to grab the endGeom.

Am I implementing this properly? I've attached a screencap of the error I'm getting back.

Thanks in advance!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

To answer your question, it's important to know where SelectedOriginFeature.Feature is coming from.  

There are multiple causes that can lead to this exception:

Features can contain null or empty geometries, empty envelopes, and may optionally include geometries that are not simple this could lead to this error.   Also, it depends on how you populate your datagrid and then populate the 'Feature' property.   If you use a FeatureCursor as a returned by the Search method for example, you have to make sure that the cursor is not recycling.   The default for recycling is True, which can lead to this problem.   Search Method (Table)—ArcGIS Pro.  

Having populated datagrids in the past i usually populate a custom class for each feature (added to an ObservableCollection) where i store the attribute data that i like to display.  If i have need for the geometry i use the Geometry's Clone method (when iterating through the cursor) to keep a copy of the geometry for later use.  This way i don't have to worry about recycling cursors etc.  Another way to avoid this problem is to retrieve the geometry only once you select a feature row using the object id (or global id).  Here is a sample that is doing just that:  Esri/arcgis-pro-sdk-community-samples: ArcGIS Pro SDK for Microsoft .NET Framework Community Samples...

View solution in original post

3 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

To answer your question, it's important to know where SelectedOriginFeature.Feature is coming from.  

There are multiple causes that can lead to this exception:

Features can contain null or empty geometries, empty envelopes, and may optionally include geometries that are not simple this could lead to this error.   Also, it depends on how you populate your datagrid and then populate the 'Feature' property.   If you use a FeatureCursor as a returned by the Search method for example, you have to make sure that the cursor is not recycling.   The default for recycling is True, which can lead to this problem.   Search Method (Table)—ArcGIS Pro.  

Having populated datagrids in the past i usually populate a custom class for each feature (added to an ObservableCollection) where i store the attribute data that i like to display.  If i have need for the geometry i use the Geometry's Clone method (when iterating through the cursor) to keep a copy of the geometry for later use.  This way i don't have to worry about recycling cursors etc.  Another way to avoid this problem is to retrieve the geometry only once you select a feature row using the object id (or global id).  Here is a sample that is doing just that:  Esri/arcgis-pro-sdk-community-samples: ArcGIS Pro SDK for Microsoft .NET Framework Community Samples...

succip
by
Occasional Contributor

Hey Wolf, thanks for your help. I've cloned the geometry as a new property on my custom class and that seems to have fixed it. 

To elaborate on that first point: I indeed used the Search method to populate my datagrid, but on the FeatureLayer and not the Table. Am I correct in understanding the FeatureLayer's Search method doesn't use recycling? 

0 Kudos
CharlesMacleod
Esri Regular Contributor

the opposite. The search on the feature layer _does_ use recycling