Skip to main content
Question

splitting string of coordiantes every 4 repetitions, regular expression help?

  • October 27, 2017
  • 4 replies
  • 10 views

Forum|alt.badge.img

Hi all

Im struggling to hit a specific gml setup and for this I need to split up a line of coordinates every 4 coordinates (I have no idea why the gml has to be this way.). I guessing i need to use regular expressions but im stumped as to how to write one that gives the right result.

an example string of coordinates that i have extracted using geometryextractor -> GML v2.1.2 looks like this:

711744.265,6175978.47 711791.544,6175982.446 711792.0123,6175979.7872 711792.5482,6175976.5078 711772.1563,6175974.7882 711755.5244,6175973.3985 711755.7058,6175970.729 711758.604,6175934.878 711722.2771,6175932.0269 711681.914,6175928.848 711683.786,6175998.563 711704.5651,6176000.163 711742.48,6176003.089 711744.265,6175978.47

but it needs to look like this for the gml to work for its intended purpose:

711744.265,6175978.47 711791.544,6175982.446 711792.0123,6175979.7872 711792.5482,6175976.5078 711772.1563,6175974.7882 711755.5244,6175973.3985 711755.7058,6175970.729 711758.604,6175934.878 711722.2771,6175932.0269 711681.914,6175928.848 711683.786,6175998.563 711704.5651,6176000.163 711742.48,6176003.089 711744.265,6175978.47

As you can see it repeats every 4 xxx.xxx,xxx.xxx untill only two are left.

Can anyone help me write and expression?

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
  • Author
  • 6 replies
  • October 27, 2017

coordinate-string.txt

I see the forum swallowed the white spaces every 4th repetition so i have uploaded a text file with before/after

basicaly i have to replace every 4th white space with 17 whitespaces.


jneujens
Forum|alt.badge.img
  • 189 replies
  • October 27, 2017

splitstringcoordinateexample.fmw

I have added a small workspace that does the tick (I think).

 

 

With a regex each coordinate is grouped and stored as a list. Each fourth element is then added a series of spaces, similar to your example. The latter is written to a new text file.

 

The example should work for the example .txt file you have added here.

 

 

 

Hopefully this solves your problem?


takashi
Celebrity
  • 7843 replies
  • October 27, 2017

The StringReplacer could also work for you.

  • Mode: Replace Regular Expression
  • Text to Replace: ((\\S+\\s+){3}\\S+)\\s+
  • Replacement Text: \\1<17 spaces>


Forum|alt.badge.img
  • Author
  • 6 replies
  • October 31, 2017

Hi all

Thank you so much for your time, i have been away over the weekend so just saw your replies now. Your solutions worked as a charm :) thank you!