Skip to main content
Solved

Separating comma separated values in a field to create new records

  • October 20, 2015
  • 1 reply
  • 167 views

I have a table of data that has two fields that have comma separated values in them. Each value is related to each other. So the first comma separted value in Neighbour Code field is related to the first comma separated value in Neighbour Angle field and so on.... The table looks like this

 

 

 

 

How do I separate these values and create a new record for each value in the fields so the table would look like this:

 

 

 

 

Thanks 

 

Matt

 

 

 

Best answer by takashi

Hi Matt,

 

 

I think this data flow is a basic solution.

 

 

Notes:

 

"Neighbour Angle" should be removed in the upper flow, not to conflict with Supplier's "Neighbour Angle" at the FeatureMerger.

 

"Conflict Resolution" parameter of the ListExploders should be set to "Use Incoming List".

 

 

In addition, the PythonCaller may also be effective in this case.

 

-----

 

# Python script example

 

class FeatureProcessor(object):

 

    def input(self, feature):

 

        codes = str(feature.getAttribute('Neighbour Code')).split(',')

 

        angles = str(feature.getAttribute('Neighbour Angle')).split(',')

 

        for c, a in zip(codes, angles):

 

            f = feature.clone()

 

            f.setAttribute('Neighbour Code', c)

 

            f.setAttribute('Neighbour Angle', a)

 

            self.pyoutput(f)

 

-----

 

 

Takashi
View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

1 reply

takashi
Influencer
  • Best Answer
  • October 20, 2015
Hi Matt,

 

 

I think this data flow is a basic solution.

 

 

Notes:

 

"Neighbour Angle" should be removed in the upper flow, not to conflict with Supplier's "Neighbour Angle" at the FeatureMerger.

 

"Conflict Resolution" parameter of the ListExploders should be set to "Use Incoming List".

 

 

In addition, the PythonCaller may also be effective in this case.

 

-----

 

# Python script example

 

class FeatureProcessor(object):

 

    def input(self, feature):

 

        codes = str(feature.getAttribute('Neighbour Code')).split(',')

 

        angles = str(feature.getAttribute('Neighbour Angle')).split(',')

 

        for c, a in zip(codes, angles):

 

            f = feature.clone()

 

            f.setAttribute('Neighbour Code', c)

 

            f.setAttribute('Neighbour Angle', a)

 

            self.pyoutput(f)

 

-----

 

 

Takashi

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings