Skip to main content
Question

Create triangles using attributes

  • 20 February 2013
  • 5 replies
  • 44 views

Hello!

 

 

I have CSV data which contains triangles. Each row contains one triangle. The triangle is defined by 6 attributes, x0, y0, x1, y1, x2 and y2. Is there a way to create polygon geometry using a transformer from those 6 attributes? I'm using StringConcatenator to create FME XML Geometry and GeometryReplacer. It works, but it would be useful to have a transformer, which could do that, something like Creator, but with INPUT port, since Creator doesn't have INPUT.
Hi,

 

 

My idea is: expose csv_line_number format attribute, connect the CSV reader to three 2D/3DPointReplacers parallel to create 3 points per a line, join them into a Sorter and sort points by csv_line_number, and connect each 3 points by PointConnector (Group by csv_line_number).   
Thank you Takashi, I was just thinking too complicated solution. Simple is the best. I had to add fourth 2DPointReplacer to get polygons from PointConnector.

 

 

What if I don't have triangles, but polygons in the CSV file, and I wouldn't know the vertex number of a polygon. I guess I would need some kind of loop structure with each feature having the vertices in a list.
That should work as long as you can loop to the end of the list creating one point each time. I'd probably go for variablesetters and retrievers though. Read each line and explode all the X&Y values into features and use the csv line number as the feature ID. Then as Takashi says a PointConnector perhaps followed by a GeometryCoercer to create the polygons.
Alternatively, LineCloser is also available to change a line consisting of 3 or more vertices to a polygon.
If you use the 2DPointAdder (instead of replacer) and keep adding to the same feature, FME will automatically turn it into a polygon.

 

 

The other method of changing a closed line to a polygon is the GeometryCoercer

Reply