Skip to main content
Solved

How to create geometry based on an attribute

  • September 23, 2024
  • 4 replies
  • 583 views

limo
Supporter
Forum|alt.badge.img+8

Hi,

 

I do some requests over an api to get some features.

As result I have some attributes for each feature. One of them is containing the coordinates (lat,lon)

Something like this:

52.2413243,10.5215958,52.2411936,10.5215612,52.2410751,10.5215738,52.2409598,10.5215146...

Is there a simple way to use the geometry attribute with structure lat,lon,lat,lon… and convert these values to vertices? I assume I have to use vertexcreator? But I do not want to define all nodes separate.

 

Does someone know a smart way to do this in fme ?

 

Thanks in advance

Best answer by bwn

Agree with @s.jager , there are a couple of ways to do it.  One involves RegEx to get a string in WKT format.  Another involves using AttributeSplitter to build the values into a list and then separate the “Odd” list index values for Longitude values and the “Even” list index values for Latitude to send these to a VertexCreator → LineBuilder

To build out the original great idea though is to need probably some RegEx, as there are two issues  in the raw API string preventing easily building a WKT:

  • In the raw string the latitude values (Y) are before the longitude values (X).  These need to be swapped around for WKT as X Y.
  • In the raw string, the same delimiter “,” is used between the X Y value-tuple and also between the coordinate pairs.  The X,Y value separator in WKT needs to be a space character instead of “,”  so only these commas, and not the other commas, need to be replaced with a space character.

 

Now, below this is not the most precise of RegEx expressions to use in StringReplacer (and there are way more capable RegEx people than me on this forum! 😉), but it should do the job

Sample Data

 

The core component is then a StringReplacer to transform the string into an inner WKT tuple type format.  These swaps the positions of the Y string value (RegEx Group \1) for the X string value (RegEx Group \2) and puts a space character as the separator.  If there is a “,” after them (RegEx Group \3) then put that back in as well after the X Y value pair.
 



This gives on the Output Eg.
 

 

From here it is trivial to wrap this inside a WKT LINESTRING(...) and send to a WKT GeometryReplacer
 

 

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

s.jager
Influencer
Forum|alt.badge.img+22
  • Influencer
  • September 23, 2024

There’s a couple of ways to do that, but I would probably use a StringConcatenator to turn the attribute into WKT, then use a GeometryReplacer...


bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • Best Answer
  • September 23, 2024

Agree with @s.jager , there are a couple of ways to do it.  One involves RegEx to get a string in WKT format.  Another involves using AttributeSplitter to build the values into a list and then separate the “Odd” list index values for Longitude values and the “Even” list index values for Latitude to send these to a VertexCreator → LineBuilder

To build out the original great idea though is to need probably some RegEx, as there are two issues  in the raw API string preventing easily building a WKT:

  • In the raw string the latitude values (Y) are before the longitude values (X).  These need to be swapped around for WKT as X Y.
  • In the raw string, the same delimiter “,” is used between the X Y value-tuple and also between the coordinate pairs.  The X,Y value separator in WKT needs to be a space character instead of “,”  so only these commas, and not the other commas, need to be replaced with a space character.

 

Now, below this is not the most precise of RegEx expressions to use in StringReplacer (and there are way more capable RegEx people than me on this forum! 😉), but it should do the job

Sample Data

 

The core component is then a StringReplacer to transform the string into an inner WKT tuple type format.  These swaps the positions of the Y string value (RegEx Group \1) for the X string value (RegEx Group \2) and puts a space character as the separator.  If there is a “,” after them (RegEx Group \3) then put that back in as well after the X Y value pair.
 



This gives on the Output Eg.
 

 

From here it is trivial to wrap this inside a WKT LINESTRING(...) and send to a WKT GeometryReplacer
 

 


geomancer
Evangelist
Forum|alt.badge.img+60
  • Evangelist
  • September 23, 2024

Another approach using regular expressions:

  1. Replace the FIRST comma with a space. The first comma can be found with the regular expression ^.*?\K,
  2. In the resulting string, replace EVERY SECOND comma with a space. Every second comma can be found with the regular expression .*?,.*?\K,
  3. Turn the string into WKT
  4. Create the geometry from the WKT
  5. Flip the object using a CoordinateSwapper

For a more compact workspace, steps 1-3 can be done in one Attributemanager using the string function @ReplaceRegularExpression twice.

 


limo
Supporter
Forum|alt.badge.img+8
  • Author
  • Supporter
  • September 23, 2024

thanks a lot for your help.

It works for me with RegularExpressions to create a wkt geometry and afterwards using GeometryReplacer. Sometimes it is difficult to find the correct syntax of the RegEx.