Thursday, May 21, 2009

Close "unclosed" polygons with FME

Sometimes I get ASCII text files of polygons but with unclosed vertices. What I mean is that the first point and last point of the polygon in the ASCII file are not the same. An example is shown in the figure below.
When I load this polygon ASCII file into Global Mapper or GeoMedia, the polygon is displayed as an unclosed line string. An example is shown in the figure below.
To close such cases of unclosed polygons, I decided to use FME 2009. Here are the steps I took to form a close polygon from the unclosed polygon ASCII file. There is a LineCloser Transformer in FME that will do the job.
  1. Start up the FME Workbench by selecting Start > All Programs > FME > FME Workbench. Choose to work with the Translation Workspace Wizard.

    The Create Translation Workspace Wizard dialog box appears.


  2. In the text box, choose Comma Separated Value (CSV) as the source data format. Click Next.

    The Locate Source Data page appears.
  3. Browse or type in the location and name of the source ASCII file e.g. C:\Temp\polygon.csv. Click Settings.

    The Input Settings for Comma Separated Value dialog box appears.


  4. In the Separator character drop down list, choose space. Click OK. Click Next.

    The Select Destination Format page appears.


  5. Choose ESRI Shape. Click Next until the Wizard is completed.

    The Workbench is filled in with the source and destination datasets.

  6. In the FME Workbench, add in the 2DPointAdder, PointConnector, LineCloser Transformers. Connect them to the source and destination datasets as shown in the figure below.

  7. Open up the 2DPointAdder Parameters.

  8. In the X Value drop down list, choose col0. In the Y Value drop down list, choose col1. Click OK.

  9. Open up the destination dataset Feature Type Properties.

  10. In the Allowed Geometries drop down list, choose shape_polygon. Click OK.
  11. Run the translation.

    The unclosed polygon ASCII file is transformed to a closed polygon in Shapefile format.

No comments:

Related Posts with Thumbnails