I have no idea what why i can't figure this out, but after hours of trying i am finally having to get some help. All I want to do is get the selected line feature from a FeatureLayer object so I can get the starting point (fromPoint). Here is my current version of code:
QueuedTask.Run(() =>
{
var gsSelection = gsFLayer.GetSelection();
using (ArcGIS.Core.Data.RowCursor rCursor = gsSelection.Search())
{
while (rCursor.MoveNext())
{
Feature gsFeature = rCursor.Current as Feature;
IPolyline6 gsPolyline = gsFeature as IPolyline6;
IPoint fromPoint = gsPolyline.FromPoint;
}
}
});
Earlier in my code I use this to get the layer, which appears to be working. I can get to the attributes of the selected feature without any issues.
gsFLayer = map.GetLayersAsFlattenedList().OfType<ArcGIS.Desktop.Mapping.FeatureLayer>().Where(l => l.Name.IndexOf("GISWRKS1.WORKS.GravitySewer", StringComparison.CurrentCultureIgnoreCase) >= 0).FirstOrDefault();
I get a NullReference exception at IPoint fromPoint = gsPolyline.FromPoint;
Any help is appreciated.
Thanks!
Solved! Go to Solution.
Brian,
The only IPolyline6 that I am aware of comes from the ArcObjects SDK. This is a Pro SDK program, right? If so, you should access the `Feature.GetShape()` method and then try casting that to an ArcGIS.Core.Geometry.Polyline feature.
--Rich
Brian,
The only IPolyline6 that I am aware of comes from the ArcObjects SDK. This is a Pro SDK program, right? If so, you should access the `Feature.GetShape()` method and then try casting that to an ArcGIS.Core.Geometry.Polyline feature.
--Rich
Ah, thanks Rich for giving my brain a kick and knocking some sense into me! Turns out i was looking at a block of code from an ArcObjects project I worked on where I knew I was doing a similar thing. I had converted that project to ArcGIS Pro, but was just looking at the wrong project.
I am good now!! This seems to work for anyone interested.
QueuedTask.Run(() =>
{
var gsSelection = gsFLayer.GetSelection();
IReadOnlyList<long> selectedOIDs = gsSelection.GetObjectIDs();
foreach (var oid in selectedOIDs)
{
var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
insp.Load(gsFLayer, oid);
//Get the To and From point of the currently selected feature
var pointCollection = ((ArcGIS.Core.Geometry.Multipart)insp.Shape).Points;
ArcGIS.Core.Geometry.MapPoint fromPoint = pointCollection[0];
ArcGIS.Core.Geometry.MapPoint toPoint = pointCollection[pointCollection.Count - 1];
MessageBox.Show(insp["FACILITYID"].ToString());
}
});
That's a relief to hear! You had me questioning my sanity for a few minutes. 🙂
--Rich