Using Transformer to Create a Line Segments Field

The Transformer stage modifies field values and formatting. This procedure describes how to create a custom transform to create a LineSegment field. The LineSegment is then used as the input to a Create Polygon Geometry operation using Spatial Calculator.

Here the input for Transformer is a string field of latitude/longitude locations in a row in the format 'x1,y1,x2,y2,x3,y3….; x1,y1,x2,y2,x3,y3….;…’. The output will be a LineSegments field for polygons with holes.

To create a LineSegment field:

  1. In Enterprise Designer, create a new dataflow and add a Read From File stage. Double-click to display the Options dialog. In the File Properties tab, specify the input file containing the location information, for example:
    0.0,0.0,0.0,10.0,10.0,10.0,10.0,0.0,0.0,0.0;2.0,2.0,2.0,8.0,8.0,8.0,8.0,2.0,2.0,2.0
  2. In the Fields tab, click Detect Type, if necessary, to automatically determine the fields. Modify the column name to be called lines.
  3. Add a Transformer stage to the workflow. Rename the stage to "Prepare LineSegments." Double-click the stage to open the Options dialog. Click Add to open the Add Transform dialog box. Choose Custom to display the Custom dialog box.
  4. In the Custom dialog box do the following:
    1. In the Custom Transform Name text box, type Prepare LineSegments list.
    2. In the Custom Script text box, add the following Groovy script. The input lines field is a string of longitude and latitude coordinates representing an inner and outer polygon.
      //'lines' field is '0.0,0.0,0.0,10.0,10.0,10.0,10.0,0.0,0.0,0.0;2.0,2.0,2.0,8.0,8.0,8.0,8.0,2.0,2.0,2.0'
      String pointsString = data['lines']
      String[] lineStrings = pointsString.split(";");
      
      def LineSegments = []
      def polygon = [:]
      def point = [:]
      for (int n = 0; n < lineStrings.length; n++) {
            String[] coords = lineStrings[n].split(",");
            def line = []
            for (int i = 0; i < coords.length; i=i+2) {
                  point = [ 'Longitude': coords[i], 'Latitude': coords[i+1]] 
                  line.add(point)
            }
            polygon.put(String.valueOf, line)
      }
      
      LineSegments = [polygon]
      
      data['LineSegments'] = LineSegments
      
    3. To the right of Output fields, click Add to open the Add Custom Field dialog then click Add to open the Add Field dialog. In the Field name text box type LineSegments (to match the output indicated in the custom Groovy script). Check the Data type is a list type of checkbox and choose Segment from the drop-down list.
    4. Click OK, then click OK again in the Add Custom Field dialog to return to the Add Transform dialog. At the bottom of the dialog, click Add then click Close to return to the Options dialog. The dialog now lists the Prepare LineSegments list as the custom transform. Click OK to leave the Options dialog box.
  5. To use Prepare LineSegments list in a dataflow, add a Spatial Calculator stage (renamed to Create Polygon) Double-click the stage to open the Spatial Calculator Options dialog. Select Create Polygon Geometry, then select the coordinate system and click OK.
  6. Add a Write to Null stage to complete the dataflow. To test the dataflow, add an Inspection Point and run Inspect Current Flow.