Skip to main content
Solved

Update a list element base on another list element


pauld
Contributor
Forum|alt.badge.img+1
  • Contributor

Hi.

I have a file of text strings that have multiple ‘parts’ that I have split into a _list. 

Example text string...

  •  LOT 9 DP 19723 LOT 12 DP 384274 LOT 8 DP 30287 LOT 9 DP 2402 PT RS 17343 17491 BLK VII X XI TENGAWAI SD-TIMBER NOT ASSESSED

Using string searcher, I have formed a list of the formatted string to push into the list using regex: (LOT \d+ DP \d+){1,}

The result is a list containing the:

  • appellation:LOT 9 DP 19723 LOT 12 DP 384274 LOT 8 DP 30287 LOT 9 DP 2402 PT RS 17343 17491 BLK VII X XI TENGAWAI SD-TIMBER NOT ASSESSED
  • matches: LOT 9 DP 19723  LOT 12 DP 384274  LOT 8 DP 30287  LOT 9 DP 2402 

What I want to be able to do is remove the matched part from appellation on the way through leaving me with both the matches as individual features, and a subset of appellation with the matches removed. The resultant appellation in this example would be: PT RS 17343 17491 BLK VII X XI TENGAWAI SD-TIMBER NOT ASSESSED

 

I would be very grateful for any help with this.

Regards, Paul

 

Best answer by geomancer

You can do this with a StringReplacer in Regex mode, using the regular expression you provided.

 

View original
Did this help you find an answer to your question?

3 replies

ctredinnick
Supporter
Forum|alt.badge.img+19
  • Supporter
  • April 17, 2024

I’d treat this like you want to remove every ‘found’ Lot/DP value from the original appellation string.

If the StringSearcher’s All Matches list is called ‘lots’, then this in python will remove those lots from the full appellation. 

    def input(self, feature):

        appellation = feature.getAttribute('appellation')
        lots_array = feature.getAttribute('lots{}.match',list)

        for lot in lots_array:
            appellation=appellation.replace(lot,'').lstrip()

        feature.setAttribute('appellation',appellation)
        self.pyoutput(feature)

 


geomancer
Evangelist
Forum|alt.badge.img+50
  • Evangelist
  • Best Answer
  • April 17, 2024

You can do this with a StringReplacer in Regex mode, using the regular expression you provided.

 


pauld
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • April 18, 2024

Thank you both for your responses.

Very much appreciated!🙂


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