Parse ArcGISAttribute.Data from float attributes

125
1
Jump to solution
04-16-2024 08:19 AM
OwenGebhardt
New Contributor II

I have a hosted 3D scene layer with attribute data that I want to run calculations on inside a Unity script. Specifically, the layer is a network of lines (or rather cylinders generated with the 3D buffer tool, since the Maps SDK can't read attributes from a vector tile layer, but that's an idea post for another day) with attributes created from the Generate Near Table tool. Each line has information about its start and end points' position and FID, as well as the distance between them.

Data.PNG

My issue is that seemingly the only thing the SDK lets you do with a layer's attributes is directly changing that layer's material by automatically plugging the attribute value verbatim into a shader variable. This doesn't help me, since I want to first extract the data, run Dijkstra's algorithm on it to find each edge's distance from a given vertex, then use the result for each edge to modify the material. I have a plan for how to implement this, and the only thing I'm missing is having direct access the layer's attributes.

The Material By Attribute sample scene provided by Esri has code that parses string attributes using a custom AttributeProcessor, specifically the ForEachString() and IsBuildingOfInterest() methods. IsBuildingOfInterest() receives attribute data as a string, so it can be fairly easily modified to send this data to other methods. Unfortunately, because the SDK can handle numeric datatypes directly without the need for a custom AttributeProcessor, there's no example code for me to work from.

I know this could be solved by converting the attribute columns I want from floats/ints to strings inside ArcGIS Pro, retrieving those strings with the AttributeProcessor in Unity, and using float.Parse() to have C# convert the strings back into floats. However, I'd rather keep the data in the layer itself in a datatype that's sensible for it, to make future maintenance easier and to cut out unnecessary steps. I'd be willing to do this as a last resort though.

I've been trying to reverse-engineer a way to parse the ArcGISAttribute.Data stream as floats. I can get the byte stream the float attributes are sent as with ArcGISAttribute.Data, but I don't have much experience working directly with streamed data like this. I've been looking for a pattern that lines up with the mantissa + sign + exponent format C# stores floats in so I can know where to start parsing the stream as floats, but so far no luck.

BinaryStream.PNG

I'd greatly appreciate any advice, suggestions, or expertise you can offer!

0 Kudos
1 Solution

Accepted Solutions
OwenGebhardt
New Contributor II

Aaand not one hour later I realized what I'd been doing wrong this whole time! The attribute was actually a double, not a float! Using the correct datatype in NativeArray.Reinterpret() parses the data stream easily. 😛

View solution in original post

0 Kudos
1 Reply
OwenGebhardt
New Contributor II

Aaand not one hour later I realized what I'd been doing wrong this whole time! The attribute was actually a double, not a float! Using the correct datatype in NativeArray.Reinterpret() parses the data stream easily. 😛

0 Kudos