Hey all,
Is there a way to delete all empty attributes? I googled and didn't find any solution for this, it seams like it should be pretty straight forward.
Delete empty attributes
6937 12 2- stinzen
- Member
- 36 posts
- Joined: March 2014
- Offline
- -Pietro-
- Member
- 14 posts
- Joined: Nov. 2019
- Offline
- stinzen
- Member
- 36 posts
- Joined: March 2014
- Offline
- BabaJ
- Member
- 2039 posts
- Joined: Sept. 2015
- Online
All attributes have some information in some form, whether that's a float with a value of 0, or even an empty int array - which would be of a length of zero. I mention that because from such information you can create groups or other attributes based on that information.
However, if what you want to do is what I think - You can't say, with points, delete the attribute (based on a condition like it having a value of 0) for only some of the points, and have the other points retain that attribute with other values.
I haven't worked with OSM data but I'm assuming they can have high loads on memory and your wanting to reduce that to make it more workable?
You might want to be more specific on what it is your wanting to do or having issues with.
Otherwise why can't you use attribute delete node? If those attributes ‘don’t hold any information'.
However, if what you want to do is what I think - You can't say, with points, delete the attribute (based on a condition like it having a value of 0) for only some of the points, and have the other points retain that attribute with other values.
I haven't worked with OSM data but I'm assuming they can have high loads on memory and your wanting to reduce that to make it more workable?
You might want to be more specific on what it is your wanting to do or having issues with.
Otherwise why can't you use attribute delete node? If those attributes ‘don’t hold any information'.
- stinzen
- Member
- 36 posts
- Joined: March 2014
- Offline
Hi BabaJ,
Thanks for your answer. I will try to explain more in detail what it is I want. From the OSM data I have a lot of prim attributes in string form, there is about 100 or more. A lot of the attributes don't have any entries on any of the prims, as in the picture, “diet_vegan”, “diet_vegetarian”, “display”, “drink_club_mate”, “drink_water_legal” for example, and I'm looking to delete the whole attribute-“category” if that is the case.
As I understood it with the attribute delete I can write all the attributes I want to delete but as they are so many that would take a long time. So how would I delete all prim-string attributes that has no text?
Thanks for your answer. I will try to explain more in detail what it is I want. From the OSM data I have a lot of prim attributes in string form, there is about 100 or more. A lot of the attributes don't have any entries on any of the prims, as in the picture, “diet_vegan”, “diet_vegetarian”, “display”, “drink_club_mate”, “drink_water_legal” for example, and I'm looking to delete the whole attribute-“category” if that is the case.
As I understood it with the attribute delete I can write all the attributes I want to delete but as they are so many that would take a long time. So how would I delete all prim-string attributes that has no text?
I haven't worked with OSM data but I'm assuming they can have high loads on memory and your wanting to reduce that to make it more workable?Exactly
Edited by stinzen - Nov. 7, 2019 11:20:28
- Andr
- Member
- 900 posts
- Joined: Feb. 2016
- Offline
hello, try the following code in a python sop
This is very crude, for example it would throw an error if you have non-string attributes.
Up to you to build the exceptions.
Cheers.
geo = node.geometry() prim_attribs = list(geo.primAttribs()) allprims = geo.prims() for p in allprims: for attrib in prim_attribs: if p.stringAttribValue(attrib) != "" : prim_attribs.remove(attrib) break for attrib in prim_attribs: attrib.destroy()
This is very crude, for example it would throw an error if you have non-string attributes.
Up to you to build the exceptions.
Cheers.
- Andr
- Member
- 900 posts
- Joined: Feb. 2016
- Offline
ps.
note that this is a post-fix.
Ideally you should be able to clean the OSM file at import stage. Before the parsing occurs. That would be more efficient than creating unnecessary attribs and then remove them.
So maybe you want to mess with the OSM_import node itself.
note that this is a post-fix.
Ideally you should be able to clean the OSM file at import stage. Before the parsing occurs. That would be more efficient than creating unnecessary attribs and then remove them.
So maybe you want to mess with the OSM_import node itself.
Edited by Andr - Nov. 7, 2019 12:52:14
- jlait
- Staff
- 6202 posts
- Joined: July 2005
- Offline
Faster way might be to use nuniqueval/uniqueval to see if the string attribute has only blank strings in it. Can do it in a detail wrangle that builds up a detail string of attributes to delete that the attribute delete brings in with a details() expression. Bonus points is to wire your geometry to test to the *second* input of the detail wrangle so you have no copy costs for generating this.
- Andr
- Member
- 900 posts
- Joined: Feb. 2016
- Offline
jlait
Faster way might be to use nuniqueval/uniqueval to see if the string attribute has only blank strings in it. Can do it in a detail wrangle that builds up a detail string of attributes to delete that the attribute delete brings in with a details() expression. Bonus points is to wire your geometry to test to the *second* input of the detail wrangle so you have no copy costs for generating this.
I've been trying to use vex on first instance, but I wasn't aware of these functions you mentioned. Very handy.
It should be definitely faster.
But now I'm curious, how does nuniqueval() even work, doesn't it have to iterate over all prims as well?
- jsmack
- Member
- 7762 posts
- Joined: Sept. 2011
- Offline
Andrjlait
Faster way might be to use nuniqueval/uniqueval to see if the string attribute has only blank strings in it. Can do it in a detail wrangle that builds up a detail string of attributes to delete that the attribute delete brings in with a details() expression. Bonus points is to wire your geometry to test to the *second* input of the detail wrangle so you have no copy costs for generating this.
I've been trying to use vex on first instance, but I wasn't aware of these functions you mentioned. Very handy.
It should be definitely faster.
But now I'm curious, how does nuniqueval() even work, doesn't it have to iterate over all prims as well?
String attributes do not store a value per element, rather they store a list of unique values. This makes it trivial to get the number of unique values for string attributes.
- BabaJ
- Member
- 2039 posts
- Joined: Sept. 2015
- Online
- Andr
- Member
- 900 posts
- Joined: Feb. 2016
- Offline
jsmackthanks for the insightAndrjlait
Faster way might be to use nuniqueval/uniqueval to see if the string attribute has only blank strings in it. Can do it in a detail wrangle that builds up a detail string of attributes to delete that the attribute delete brings in with a details() expression. Bonus points is to wire your geometry to test to the *second* input of the detail wrangle so you have no copy costs for generating this.
I've been trying to use vex on first instance, but I wasn't aware of these functions you mentioned. Very handy.
It should be definitely faster.
But now I'm curious, how does nuniqueval() even work, doesn't it have to iterate over all prims as well?
String attributes do not store a value per element, rather they store a list of unique values. This makes it trivial to get the number of unique values for string attributes.
- AlanZ
- Member
- 41 posts
- Joined: Feb. 2018
- Offline
Late to the OSM party and just found this post. I wanna report that python is (surprisingly) 5+ times faster in my case. Code based on Andr's:
node = hou.pwd() geo = node.geometry() prim_attribs = geo.primAttribs() for attr in prim_attribs: if attr.dataType() != hou.attribData.String: continue allValues = set(geo.primStringAttribValues(attr.name())) if allValues == set([""]): attr.destroy()
-
- Quick Links