Question

Extract Coordinates using Regular Expression

  • 26 July 2018
  • 4 replies
  • 27 views

Hi all,

 

 

I'm very new to regular expressions but need to use one to extract coordinates from a single field into their individual elements.

 

The number of characters varies for each feature, so I can't use a substring extractor.

 

Essentially I want a regex to extract the first coordinate in the brackets, and the second as their own attributes.

 

 

Some examples:

 

 

POINT (1764887.456903827 5905612.28425431)

 

POINT (1749937.56 5913840.62)

 

 

Where I want separate attributes:

 

X: 1764887.456903827

 

Y: 5905612.28425431

 

Many thanks,

 

Kieran

4 replies

Badge +2
Hi @kieranodonnell

 

 

 

I am not to familiar with regular expressions myself but I think this would work (although it may not be the cleanest regex ever): 

 

\d{2,}.\d{2,}
\d = any digit and {2,} = 2 or more of \d

 

I don't believe you can use regex in a substring extractor so instead I would suggest using a string searcher and writing the matched attributes out into a list. 

 

0684Q00000ArK8sQAF.png

Then in an Attribute Manager or Attribute Creator you can assign list(0) to X and list(1) to Y. 

 

0684Q00000ArKAnQAN.png

This regex worked for both examples so should do the trick!

 

 

Badge +2
Hi @kieranodonnell

 

 

 

I am not to familiar with regular expressions myself but I think this would work (although it may not be the cleanest regex ever): 

 

\d{2,}.\d{2,}
\d = any digit and {2,} = 2 or more of \d

 

I don't believe you can use regex in a substring extractor so instead I would suggest using a string searcher and writing the matched attributes out into a list. 

 

0684Q00000ArK8sQAF.png

Then in an Attribute Manager or Attribute Creator you can assign list(0) to X and list(1) to Y. 

 

0684Q00000ArKAnQAN.png

This regex worked for both examples so should do the trick!

 

 

PS. There are lots of good online tools to test a regex string and breakdown what each component is selecting to help when you are learning! e.g. https://regex101.com/

 

 

Hi @kieranodonnell

 

 

 

I am not to familiar with regular expressions myself but I think this would work (although it may not be the cleanest regex ever): 

 

\d{2,}.\d{2,}
\d = any digit and {2,} = 2 or more of \d

 

I don't believe you can use regex in a substring extractor so instead I would suggest using a string searcher and writing the matched attributes out into a list. 

 

0684Q00000ArK8sQAF.png

Then in an Attribute Manager or Attribute Creator you can assign list(0) to X and list(1) to Y. 

 

0684Q00000ArKAnQAN.png

This regex worked for both examples so should do the trick!

 

 

Thanks @hollyatsafe this is exactly what I was after.

 

Much appreciated!
Userlevel 1
Badge +21
It looks like your geometries are well known text, so you could also use a GeometryReplacer followed by a CoordinateExtractor to get your x y attributes.

 

 

Reply