Skip to main content
I have an Osmosis .poly file that I wold like to translate to a shape file.  It is fairly simply formatted as a text list (see below) but I am having difficulty associating the Polygone number (first line) with the list of coordinates.  This seems like it should be really simple but I've tried several text to csv transformers and I can not get the Polygon number to be an attribute of every coordinate.  I was trying that so I could use it as the "Connection break attribute" on  POINT CONNECTOR, to connect the dots to build my polygon.  Am I on the wrong track? 

 

 

Text data format:

 

76

 

    9.71250000000003  54.4940260000001

 

    9.71416700000003  54.493474

 

    9.71361300000007  54.4931940000001

 

    9.71416700000003  54.4920840000001

 

    9.71027800000007  54.4926380000001

 

    9.71083400000003  54.4937520000001

 

    9.71250000000003  54.4940260000001

 

END

 

 

Any pointers or hints would be appreciated.
Hi,

 

 

The VariableSetter / VariableRetriever can be used to add the polygon ID to each point. If the polygon ID always occurs at the first line in the block of a polygon data lines and also the second column of the ID line is empty, one possible workflow is like this:

 

 

Alternatively a PythonCaller also can be used. For example:

 

-----

 

import fmeobjects   class OsmosisPolygonCreator(object):     def __init__(self):         self.polygon_id = None         self.coords = Â]              def input(self, feature):         x = feature.getAttribute('col0')         y = feature.getAttribute('col1')         if x == 'END':             boundary = fmeobjects.FMELine(self.coords)             polygon = fmeobjects.FMEPolygon(boundary)             feature.setGeometry(polygon)             feature.setAttribute('polygon_id', self.polygon_id)             self.pyoutput(feature)             self.coords = Â]         elif not y or y == '':             self.polygon_id = x         else:             self.coords.append((float(x), float(y)))              def close(self):         pass

 

-----

 

  The results of these 2 ways are almost same, but the 2DPointReplacer seems to round the coordinate value by certain precision. I think the Python script is effective if necessary to keep precision.

 

 

Takashi
Hi Takashi,

 

Yes I see.  I had most of the components but for the initial tester, where you are testing col1 for null or blank values, I was trying to test col0 for non-decimal numbers (in contrast to the decimal degree, coordinates).  I gave up because I couldn't find a way to do that.  Well,  I hadn't thought of Variable Setter/Retriever either 🙂. 

 

 

Thanks for giving me another way to look at it.

 

 

-FSJ
Hi,

 

 

It's possible to test whether the attribute value is a number of a decimal point or not: Left Value: col0 Operator: Matches Regex Right Value (Regular expression): :0-9]*\\.\0-9]*   In addition, Multiple Feature Attribute Support functionality of the AttributeCreator (FME 2013 SP2) could be also used instead of the VariableSetter / VariableRetriever. There are several ways to do same thing in many cases 🙂

 

Takashi
Thank you Takashi the regex and attribute retriever worked great.

Reply