Solved

Stringreplacer

  • 4 December 2014
  • 6 replies
  • 10 views

Hi all,

 

 

I have a column containing the coordinates information such as:

 

54960000.0 643600000.63 0.0

 

....

 

 

I am wondering to know if there is any way to extract the first four integers for the X and Y values.

 

At the end, I need to have the value like "5496,6436"

 

 

One possibility is for example using attributesplitter. But Is it also possible to use stringreplacer doing it only in one step?

 

 

Thank you,

 

Mani
icon

Best answer by takashi 5 December 2014, 00:43

View original

6 replies

Userlevel 4
Hi,

 

 

you can use the StringSearcher, e.g. like this for the "x" attribute:

 

 

 

 

Then do the same once more for the "y" value.

 

 

David
Hi David and thank you.

 

 

well I think the same can be using attributesplitter and putting 4s to split the attribute but because I have x,y and z all together separated by space so I need first to split them into x and y and then either use your way or attributesplitter and then again concatenate them. Yes. This can be done.

 

 

But this question just came in my mind if this is possible to do these all in one step like searching for a series of numbers(dynamic) ended with space and then replace them with comma ",".

 

 

Thanks,

 

Mani
Userlevel 2
Badge +17
HI Mani,

 

 

Try the StringReplacer with this setting.

 

Text to Match: ^([0-9]{4})[^\\s]*\\s+([0-9]{4}).*$

 

Replacement Text: \\1,\\2

 

Use Regular Expressions: yes

 

 

Takashi
Badge +1
Hi,

 

You can use String Formatting code using Python scripting. Here is a case:

 

 

>>> '%.2f' % 1.234

 

'1.23'

 

>>> '%.2f' % 5.0

 

'5.00'

 

This will work out with python 3 syntax.

 

You can changethe number '%.*f%' according to your usage. (:
Thank you Takashi :)
Userlevel 2
Badge +17
In this case, the AttributeCreator with FME String Functions could also be useful.

 

If the source string (space-separated coordinates) is stored by an attribute called "coord", for example, this expression written in the "Value" column of an AttributeCreator returns the required string.

 

@Left(@Value(coord),4),@Left(@GetWord(@Value(coord),1),4)

 

 

This may be easier to understand than the regular expression.

 

See here to learn more about FME String Functions.

 

FME Workbench Transformers > FME String Functions (http://docs.safe.com/fme/html/FME_Transformers/Default.htm#transformer_parameters/StringFunctions.htm)

Reply