There are several examples of clicking on a map and obtaining the layer name and it's feature count ...
var lyrs = mv.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
foreach (var lyr in lyrs)
{
var fCnt = features.ContainsKey(lyr) ? features[lyr].Count : 0;
sb.AppendLine($@"{fCnt} {(fCnt == 1 ? "record" : "records")} for {lyr.Name}");
}
or using kvp.Key.Name, kvp.Value.Count
... but I have not found any examples of obtaining the attributes themselves ...
Maybe something similar to the old school way of ...
lfieldindex = pfeature.Fields.FindField("XYZfield")
pfeature.value(lfieldindex)
I'm new programming in Pro and having a hard time finding out how to access the data for my selected feature. In my instance it would be a single feature based off a point sketch. Does "MapMember" play a role here?
Hi Karen,
So somewhere along the line I am thinking you saw "Map.GetSelection()" - perhaps in a sample - and decided on that as "the" way to go. In your case, I would suggest selecting directly off the layer - "parcels" - instead. Similar to arcobjects, feature layers support both a Select and a Search method - the select will highlight the features on the map whereas search does not and applies the selection to the underlying feature class (with no visible highlight).
To retrieve the list of layers from a Pro map or scene use the method "GetLayersAsFlattenedList" which I show below.
I also encourage you to google "LINQ expressions" and read a few tutorials on it - the syntax can be a little intimidating at first - a lot of the Pro SDK samples use LINQ as it is the preferred technique for selecting items from a .NET collection. The most common LINQ methods are "Where", "FirstOrDefault", and "OfType". In the code below, I use the Pro SDK method "GetlayersAsFlattenedList()" on the Map, which I mentioned above, to return the collection of the map's layers. I then use a LINQ expression "FirstOrDefault" and that funky "lambda" syntax "lyr => lyr.Name ..." to select, from the returned list, either the first layer with a matching name of "parcels" or null (that is the purpose of "FirstOrDefault").
The final code looks like this:
To help you answer these questions:
I suggest the following sample to help you with understanding how to populate a form:
DockpaneSimple sample
It will introduce you to something called MVVM and how to add properties to your dock pane view model that get displayed on your dock pane view.
Finding the nearest feature can be quite complicated. Geoprocessing has Proximity tools and spatial joins are also possible. You could also use a brute force approach progressively selecting on the street layer with an incrementally increased buffer applied to your selection geometry and then filter the "hits" for the closest feature (see ProSnippets Geometry#nearest-point-versus-nearest-vertex)