Jump to content

Turn string values into numbers

Recommended Posts

I have a point cloud with a string attribute "name" and unique values, like C, C1, N, VAX, etc

how do just turn each unique name attribute into unique numerical values? so all of the "C" would be 1, C1 would be 2, etc

input point cloud will change and so will the actual names.  Could be hundred of unique names.





Share this post

Link to post
Share on other sites

A hack I figured out is to convert the strings to their UTF-8 code and add each array position plus and offset to get a unique number for each string.

A benefit is that similar names are numerically close together.


Share this post

Link to post
Share on other sites

Hey Tim,

What I'd do is do a for each loop with the name attribute as a piece
Create a Meta Import, plug this into a wrangle, and use the iteration value as the unique value.


If you just need unique values, that'll work.
But if you need the value to be consistent with the names between the point clouds, it won't be.

A side effect of this method is that it will sort the points based on the name.
If you don't want the points to be reordered, you can do this instead, might be simpler.


Note that this is slower with millions of points.

Hope that helps !


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now