Jump to content
tturner

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.

 

Thanks

T

 

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.

T

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.

uniqueValueBasedOnName.png.40e5ff06513a6c5b10dbf1b9d6102bb6.png

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.

608e07bc457de_Screenshot2021-05-01215943.png.7d0e39918cf45770ee1899cfc1d13172.png

Note that this is slower with millions of points.
speedComparison.png.dc1eebd5f14fdb586414aa3334d92856.png

Hope that helps !

uniqueValueByName.hipnc

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

×