Skip to main content

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

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...


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
 

 


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.

 


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. 


Reply