FME tip: create point from text

We’ve all been there: there’s an attribute containing an x coordinate, a space and a y coordinate, like this:

12.544 23.323

How to build geometry from that using FME? The most obvious route, one that I used for years, was to use an AttributeSplitter and split that attribute using the space as delimiter character. This would yield a list with 2 elements, one being the x and the other one being the y. Then a VertexCreator (or in older versions a 2DPointReplacer) could be used to build geometry from this.

There is an easier way though, it just so happens that space separated coordinate values is exactly how GML stores geometry. So by changing that attribute into a proper GML geometry representation, the GeometryReplacer can be used. Your initial reaction may be to use the AttributeCreator to set up that GML string, but it can also be done directly in the GeometryReplacer like this:
This is made possible by the inline attribute creation that was introduced in FME 2013. We simply add the bits of GML that appear around the coordinate list and let the GeometryReplacer do the rest, making sure we’ve set the geometry encoding parameter to “GML” and the SRS axis order to “1,2”. In this case we’d need only 1 transformer instead of 2 so it’s a solution that leaves your workspace less cluttered. Now this may seem trivial when creating points, but I’ve recently come across lines and polygons being stored in a similar fashion (i.e. a space-separated list of coordinate values) which would be very difficult to solve the old-fashioned way. Making sure the proper GML syntax is used those cases can be solved with just the GeometryReplacer as well.

This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.