How to get Object Attributes at Runtime using ArcGIS Runtime SDK for .NET in WPF App

334
5
10-28-2021 03:38 AM
KarthikS
New Contributor II

Hi,

I created the sample WPF application using ArcGIS Runtime SDK for Dot Net.

I load the local slpk file with one building.

I cannot able to get that building attributes at runtime.

How to get that building information, when I click that building?

like following figure. 

1.png

 

 Please give us advice

Thanks

0 Kudos
5 Replies
dotMorten_esri
Esri Frequent Contributor

You would use the Identify operation to find/inspect/select/ a feature. See this example:
https://developers.arcgis.com/net/wpf/sample-code/scene-layer-selection/

0 Kudos
KarthikS
New Contributor II

Hi dotMorten

Thank you for your valuable response

the following example link is used to layer selection

https://developers.arcgis.com/net/wpf/sample-code/scene-layer-selection/

But, I needs to get the object attributes , Which is given by the city engine object attributes in WPF application using ArcGIS Runtime SDK.

see following figure

City Engine SceneCity Engine Scene

 

Please give us advice

Thank You 

0 Kudos
KoushikHajra
Esri Contributor

You can also see this sample as an example on how to get attributes for a feature. The example is in a 2D map, but the concept is not dependent on the view type (Map/SceneView). https://developers.arcgis.com/net/wpf/sample-code/update-attributes-feature-service/

Conceptually, as Morten suggested above, you need to perform an identify operation from which you can get a list of GeoElements from your IdentifyResults, and once you get the GeoElement you want from the list, you can ask for it's attributes (geoElement.attribute). Something like this would give you the attribute value:

string currentAttributeValue = _selectedFeature.Attributes[AttributeFieldName].ToString();

0 Kudos
KarthikS
New Contributor II

Hi KoushikHajra

Thank you for your valuable response.

I cannot able to get the object attributes using following code.

string currentAttributeValue = _selectedFeature.Attributes[AttributeFieldName].ToString();

I needs to get the  attributes values in WPF application, which is given by City Engine Object Attributes.

see following figure

2.png

 

My code is below

ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer();

foreach (var sl in MySceneView.Scene.OperationalLayers)
{
if (!string.IsNullOrEmpty(sl.Id))
{
sceneLayer = (ArcGISSceneLayer)sl;

sceneLayer.ClearSelection();

IdentifyLayerResult identifyResult = await MySceneView.IdentifyLayerAsync(sceneLayer, e.Position, 1, false, 1);

IReadOnlyList<GeoElement> geoElements = identifyResult.GeoElements;

if (geoElements.Any())
{
GeoElement geoElement = geoElements.FirstOrDefault();
if (geoElement != null)
{
sceneLayer.SelectFeature((Feature)geoElement);

var _selectedFeature = (ArcGISFeature)identifyResult.GeoElements.First();

string currentAttributeValue = _selectedFeature.Attributes["City"].ToString();
}
}
}
}

above code raise the following exception

The given key 'City' was not present in the dictionary.

Please give us advice

Thanks

 

0 Kudos
KoushikHajra
Esri Contributor

Hi,

Not sure if you were able to resolve your issue or not. Without looking at your data it's hard to tell what's going wrong. But I noticed one small thing in your code when you select. You already have a geoElement (sceneLayer.SelectFeature((Feature)geoElement);) and you can try getting the attribute using the same object rather than trying to get it again?

In any case, if it hasn't resolved for you, it would help if you can share a small sample dataset and I can try it out on my end. 

0 Kudos