Skip to main content
Question

Extract Coordinates using Regular Expression

  • July 26, 2018
  • 4 replies
  • 233 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
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, 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.

4 replies

Forum|alt.badge.img+2
  • 719 replies
  • July 26, 2018
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!

 

 


Forum|alt.badge.img+2
  • 719 replies
  • July 26, 2018
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!

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3430 replies
  • July 27, 2018
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.