Question

How to change List to attribute (with ListIndexer transformer loop or another way)?

  • 21 November 2017
  • 18 replies
  • 135 views

Badge

Hi,

I know that there are a lot of questions in the forum about that but I’m not able to find how I can use it correctly. So, for extract my attributes from a list I’m using ListIndexer after the aggregator (10 listIndexer if I have 10 lines aggregated) to add a prefix to my attribute (index 0 with prefix for example x0_ and so on). That works but I think that is not a good way to do that (especially if the data change and I need to add more ListIndexer).

Is-there a way to do that with loop or another method (a dynamic way to extract the attributes)

P.s: I have many attributes, so expose elements will be more complicated.

Thanks


18 replies

Badge +1

Try the ListExploder transformer - that gives you a feature for every list member of every element

Badge

thanks. ListExploder will give me the same numbers of geometry before doing aggregate. Example : if I have 10 lines in the same position, then I want to have one line with all attributes of the 10 lines (without doing concatenate).

Badge +3

@miladahmad

Your requirement only needs indeed a listexploder, it gives u a _element_index after exploding.You can concatenate on that.

Be careful extracting listelements or exploding lists after aggregating if sorting the list is involved. (at least up to 2016 version something)

If u sort the list, elements can end up on the wrong geomtry. Sorting should be done prior to aggregating.

Best to use part extractor or deaggregator.

Userlevel 2
Badge +17

Hi @miladahmad, you can rename list elements to attribute names with a common format containing corresponding index using the BulkAttributeRenamer. Also, if you have exposed the list elements in a transformer interface beforehand, the new names will also be exposed.

Badge

thanks for all.

@gio : ListExploder give me many geometries which I do not want. ListAttributEexploder give me a strange things. Also, I do not want to use concatenate (if I want to concatenate then I can do it directly with the aggregator). What I need is one line with many fields of all the lines example : index_1_attribute1,

index_2_attribute1, index_3_attribute1, etc.

I thought it should be easier with python or loop (but I'm not good enough to do it)

I will try the solution of @takashi and then I will write again.

Badge

Hi @miladahmad, you can rename list elements to attribute names with a common format containing corresponding index using the BulkAttributeRenamer. Also, if you have exposed the list elements in a transformer interface beforehand, the new names will also be exposed.

thanks a lot for your help. It's works and It's exactly what i need.

 

Badge +3

ah, you want to merge the attributes of the overlaps to one record (1 line)

problem is dynamicaly exposing the creted attribute.

Bulkattribute renamer does not rename a existing attribute in @takashi 's example. Just adding listelement index to a string.

You would need a attribute exploder to get the actual attribute name.

And there is the problem, you cant use them (attributes) in the replacer.

Badge

ah, you want to merge the attributes of the overlaps to one record (1 line)

problem is dynamicaly exposing the creted attribute.

Bulkattribute renamer does not rename a existing attribute in @takashi 's example. Just adding listelement index to a string.

You would need a attribute exploder to get the actual attribute name.

And there is the problem, you cant use them (attributes) in the replacer.

it works. it give me x0_ActualAttribute1, x1_ActualAttribute1, x2_ActualAttribute1, etc. the bulkAttributeRenamer parameter from Takashi is the secret :)

 

Badge

@takashi:

I can see the attributes in feature information (inspector) but when I export the result to shapes I do not see them!!

Userlevel 2
Badge +17

@takashi:

I can see the attributes in feature information (inspector) but when I export the result to shapes I do not see them!!

How did you configure the destination schema for the Shapefile writer feature type?

 

 

Badge

@takashi:

I can see the attributes in feature information (inspector) but when I export the result to shapes I do not see them!!

I just exported the result from the inspector. And Now I tried to copy attribute from BulkAtttributeRenamer but it does not work. How should i configure the destination (shape or gdb)? thanks

 

 

Userlevel 2
Badge +17

@takashi:

I can see the attributes in feature information (inspector) but when I export the result to shapes I do not see them!!

A possible reason is that the attribute names are longer than 10 bytes (characters). According to the Shapefile format specification, the length of field names should be up to 10 bytes

 

If a field name was longer than 10 bytes, it would not be mapped to the writer feature type schema automatically when you copied it from the BulkAttributeRenamer. You will have to make each field name 10 bytes or less, or map them manually like the second writer feature type in this screenshot.

 

Additionally, in the File Geodatabse specification, the length of field names is limit to 64 characters.
Badge

@takashi:

I can see the attributes in feature information (inspector) but when I export the result to shapes I do not see them!!

it did not work even with gdb. I hope that there is no misunderstanding (sorry). So the Feature information give the good result but the table view is not what I want. Actually I do not want to separate information like shape1 and shape2. Lets say we have 3 lines with id, color, type and cod. What I'm doing is aggregate and generate a list to have only one line. I want to have x0_color, x0_type, x0_cod, x1_color, x1_type, x1_cod, x2_color, x2_type, x2_cod.

 

 

Userlevel 2
Badge +17

@takashi:

I can see the attributes in feature information (inspector) but when I export the result to shapes I do not see them!!

Since you can see desired attributes in the Feature Information window of Data Inspector, those could be written into the destination dataset if you configured user attributes in the writer feature type appropriately.

 

How did you configure the destination schema for the writer feature type? Do the writer feature type have those attribute definitions?

 

 

Badge

@takashi:

I can see the attributes in feature information (inspector) but when I export the result to shapes I do not see them!!

but why I do not see the same information in the table view (inspector)? I think in the feature information we can see them because we change the word _list{} to x but it still a list.

 

 

Userlevel 2
Badge +17
but why I do not see the same information in the table view (inspector)? I think in the feature information we can see them because we change the word _list{} to x but it still a list.

 

 

The Table View shows exposed attributes only. If you haven't exposed the attributes in the workflow on the Canvas, naturally they don't appear on the Table View.

 

 

Badge

@takashi:

I can see the attributes in feature information (inspector) but when I export the result to shapes I do not see them!!

ok. then If I have 5 attribute then I should expose them one by one (it should work now because I exposed _list{} without specifying the attribute (that what I hoped to have with my question from the begining :)).

 

I'm thankfull for your time and your help.

 

 

Badge +2

Hi @miladahmad, you can rename list elements to attribute names with a common format containing corresponding index using the BulkAttributeRenamer. Also, if you have exposed the list elements in a transformer interface beforehand, the new names will also be exposed.

Thanks Takashi!

Reply