Solved

Separating comma separated values in a field to create new records

  • 20 October 2015
  • 1 reply
  • 25 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

 

 

 
icon

Best answer by takashi 20 October 2015, 11:10

View original

1 reply

Userlevel 2
Badge +17
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

Reply