Skip to main content
I have thousands of lines and I want to transfer an attribute from some lines to another.. Example: line1, line2, line3, line 4 are connected to each other. I want to do a test if line2 has the attribute attr1-line2 with null data then I want to compare the attr1-line1 with attr1-line3 and copy the max of them to attr1-line2..If the attr1-line1 and attr1-line2 has a data (not null) then I want to compare between line2, line3 and line4 and so on..

 

Any idea .. Thanks

 

 
Hi,

 

 

You can use the LineJoiner to create a list attribute which contains all the attributes of connected lines, and also use the PathSplitter to restore the original lines, like this.

 

 

The point is to connect the lines as a Path object.

 

And then, you will have to add some list operation to accomplish the purpose, between the two transformers or after the PathSplitter.

 

"how to" depends on your requirement, but I'm still unclear the requirement, so cannot provide a concrete way.

 

Could you please illustrate your requirement more strictly?

 

 

Takashi
hi, thanks for answer (sorry for my english).. Actually what I think is to use a loop.. for evry line I want to search the 2 lines connected to it and copy the attribute from the both then compare them and keep the max of them.. I do not know if the list will give me the same result (if i jion thousend of line).. May be it is easier to say I want to copy the attribute of the precedding and the following line for every line (:(.. not easy to explain)
For example, assuming that line1, line2, and line3 can be connected, and

 

"attr1" of line1 has value "5",

 

"attr1" of line2 has value "10",

 

"attr1" of line3 has value "0".

 

 

In this example, do you need to give "10" (the maximum value among all the "attr1" of connected lines) to every line?

 

If so, the ListRangeExtractor in this data flow might help you.

 

 

Loop in a custom transformer might also be a solution, but I think list operation is easier in this case.
yes and no 🙂... If the attr1 has a value I do not want to change it.. in your second example I want to have the value 3 from line1 to put it in the attr1 of the line2. thanks again
I understood, maybe...

 

 

In a set of 3 lines that are consecutively arranged,

 

- if the "attr1" of the 2nd line is "null", replace it with max value of "attr1" of the 1st line and "attr1" of the 3rd line.

 

- otherwise (i.e. if "attr1" of the 2nd line is not "null"), do nothing.

 

Do it for every set of adjoining 3 lines sequentially from the beginning to the end, in the connected lines.

 

0 is considered as "null".

 

 

Therefore,

 

"3,0,1,2,4" should become "3,3,1,2,4",

 

"1,0,3,0,2" should become "1,3,3,3,2".

 

 

Is it correct?

 

If so, in these example?

 

 

"0,1,0,2,<null>" => "0,1,2,2,<null>" (not change first/last "null"?)

 

"1,<null>,<null>,<null>,2" => "1,1,1,2,2" (real <null> is less than any value?)

 


More. Are these correct?

 

"0,0,0,1,2" => "0,0,1,1,2"?

 

"1,0,0,0,0" => "1,1,1,1,0"?
For your example of 3,0,1,2,4 and 1,0,3,0,2 is correct waht you wrote (my data is about roads and it is all connected together and there is no set of 3 lines).

 

For 0,0,0,1,2 should give 1,1,1,1,2 and the second should give 1,1,1,1,1 (I do want to ha ve a zéro or null)   ..  thanks
Assuming that the lines have been already sorted in the comparison order and also they have group identifier attribute (e.g. "_group") which identifies a group of connected lines.

 

This data flow would be a solution.

 

 

The Counter adds 1-based sequential number to the lines for each group (_index).

 

The StatisticsCaluclator counts the number of lines in a group (_count).

 

The NullAttributeMapper replaces <null>, <empty>, <missing> "attr1" with 0.

 

The AttributeCreator replaces 0 "attr1" with:

 

- "attr1" of the subsequent line if the line is the first one in a group,

 

- "attr1" of the prior line if the line is the last one in a group,

 

- otherwise, the maximum "attr1" in prior and subsequent lines.

 

 

But it doesn't support the case like "0,0,0,1,2" (i.e. there are consecutive zeros in the first part). To resolve such a case, add this data flow.

 

 

The Tester and the Sampler selects the first feature having non-zero "attr1" for each group.

 

The FeatureMerger merges the first non-zero value to every feature as a new attribute named "first_attr1" for each group.

 

The AttributeCreator_2 replaces 0 "attr1" with the "first_sttr1" value.

 

 

Hope this helps.
thanks a lot.. I will test it and write again..
thanks a lot.. it works for me..

Reply