Hello,
Is there a way to select an object and show its attributes?
Thanks in advance.
Hi Mazen, did you see the ArcGIS Hit test sample in our plugin? That shows you how to show the Object ID. After that you can reference our Feature Layer sample in the samples repo to see how to query additional information from the Feature Service's rest end point
Hello Matt,
Thanks for your reply, I did try the ArcGIS Hit test sample and got the featureId but it is different from Object ID. (screenshots 1 and 2)I also noticed that the featureId changes depending on the number of objects seen by the camera. (screenshots 2 and 3)
Did I misunderstand something?
Regards.
So what you are seeing is that the feature ID is different based off the LOD that we are showing. In other words this is different than the Object ID.
From what I understand, ArcGIS Hit test sample shows the featureId which is based off the LOD and the Feature Layer sample returns all the features with their attributes.
So how can I relate between the clicked object and its attributes without having the Object ID?Maybe by comparing the latitude and longitude of the hit object?
Hello again,
I tried updating the function but kept getting errors because featureIndex wasn't defined, so my approach is as follows:
ArcGIS Pro side:* I uploaded a Scene Layer to show the 3D objects and Feature Layer to use the query operation on.* The Feature Layer has some attributes like name, lon and lat.
Unity side:
1. I added the 3D layer to the scene and did the query operation while adding each feature attributes to a list.2. When clicking a 3D object, I compare its location(lon, lat) with the location(lon, lat) in the list.3. If the condition is true, I can break and get the rest of the attributes.
I still have one more issue, I can't get the location of the 3D object to be exactly the same as in the Feature layer every time so the comparison sometimes returns false in all iterations.
Here is how I get the location for the 3D object what I do:I tried getting the ArcGISLocationComponent but it returns null, so I got the HPTransform.UniversePosition of the 3D object then converted it to ArcGISPoint by using arcGISMapComponent.View.WorldToGeographic( )
We get the featureId from v1.1.0 but is there a way to retrieve the attribute info from a 3DObject scene layer?
I searched the REST API but could not figure out a way to query this piece of info from a scene layer.
Hello dun82,
Matt mentioned using the AttributeProcessor to store all the attributes, I tried to do that but I could only read string data.
Thank you dun82 for sharing your code in the other thread!
Finally, I managed to process the attributes and show the data, here are the used functions to do so.(OBJECTID can be processed as Int)
private void Setup3DAttributes(ArcGIS3DObjectSceneLayer Layer) { if (Layer == null) { return; } var layerAttributes = ArcGISImmutableArray<String>.CreateBuilder(); layerAttributes.Add("OBJECTID"); var renderAttributeDescriptions = ArcGISImmutableArray<Esri.GameEngine.Attributes.ArcGISVisualizationAttributeDescription>.CreateBuilder(); renderAttributeDescriptions.Add(new Esri.GameEngine.Attributes.ArcGISVisualizationAttributeDescription("IsBuildingOfInterest", Esri.GameEngine.Attributes.ArcGISVisualizationAttributeType.Float32)); attributeProcessor = new Esri.GameEngine.Attributes.ArcGISAttributeProcessor(); attributeProcessor.ProcessEvent += (ArcGISImmutableArray<Esri.GameEngine.Attributes.ArcGISAttribute> layerNodeAttributes, ArcGISImmutableArray<Esri.GameEngine.Attributes.ArcGISVisualizationAttribute> renderNodeAttributes) => { var fidAttribute = layerNodeAttributes.At(0); /* Choose a function to process the data depending on the type ForEachInt64(fidAttribute, (Int64 element, Int32 index) => { //save in a list or print }); ForEachString(fidAttribute, (string element, Int32 index) => { //save in a list or print }); ForEachDouble(fidAttribute, (float element, Int32 index) => { //save in a list or print }); */ }; Layer.SetAttributesToVisualize(layerAttributes.MoveToArray(), renderAttributeDescriptions.MoveToArray(), attributeProcessor); } private void ForEachString(Esri.GameEngine.Attributes.ArcGISAttribute attribute, Action<string, Int32> predicate) { unsafe { var buffer = attribute.Data; var unsafePtr = NativeArrayUnsafeUtility.GetUnsafePtr(buffer); var metadata = (int*)unsafePtr; var count = metadata[0]; // First integer = number of string on this array // Second integer = sum(strings length) // Next N-values (N = value of index 0 ) = Length of each string IntPtr stringPtr = (IntPtr)unsafePtr + (2 + count) * sizeof(int); for (var i = 0; i < count; ++i) { string element = null; // If the length of the string element is 0, it means the element is null if (metadata[2 + i] > 0) { element = Marshal.PtrToStringAnsi(stringPtr, metadata[2 + i] - 1); } predicate(element, i); stringPtr += metadata[2 + i]; } } } void ForEachInt64(Esri.GameEngine.Attributes.ArcGISAttribute attribute, Action<Int64, Int32> predicate) { unsafe { var buffer = attribute.Data; var unsafePtr = NativeArrayUnsafeUtility.GetUnsafePtr(buffer); var metadata = (int*)unsafePtr; var count = attribute.Data.Length/4; for (var i = 0; i < count; ++i) { predicate((Int64)metadata[i], i); } } } void ForEachDouble(Esri.GameEngine.Attributes.ArcGISAttribute attribute, Action<float, Int32> predicate) { unsafe { var buffer = attribute.Data; var unsafePtr = NativeArrayUnsafeUtility.GetUnsafePtr(buffer); var metadata = (double*)unsafePtr; var count = attribute.Data.Length / 8; for (var i = 0; i < count; ++i) { predicate((float)metadata[i], i); } } }
Thanks Mazen, but can you link the string data with the feature ID?
Hello MazenTalaat,
I also have a Unity project with ArcGIS layers and with a raycast i get a Feature ID (with the Hit test example). Now i want to make the attribuut values visible in a text field of that Feature. Is adding your code above enough to get this values?
RaycastHit hit;
if (Physics.Raycast(ray, out hit)){var arcGISRaycastHit = arcGISMapComponent.GetArcGISRaycastHit(hit);var layer = arcGISRaycastHit.layer;var featureId = arcGISRaycastHit.featureId;
if (layer != null && featureId != -1){featureText.text = featureId.ToString();
}}}}
Hello @MazenTalaat , could you please help me on how you used the AttributeProcessor ?Thank you in advance
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.