Using Transformer to Create a Segment Points Field

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

Here the input for Transformer is a string field of latitude/longitude locations in a row (x1,y1,x2,y2,x3,y3….). The output will be a SegmentPoints field. This can also be used to create a LineSegments field for polygons without holes.

To create a SegmentPoints field:

  1. In Enterprise Designer, create a new dataflow and add a Read From File stage. Double-click to open the Options dialog. In the File Properties tab, specify the input file containing the location information, for example:
    -73.0,40.5,-73.0,40.7,-72.0,41.3,-73.0,40.5
  2. In the Fields tab, click Detect Type, if necessary, to automatically determine the fields. Modify the column name to be called points.
  3. Add a Transformer stage to the workflow. Rename the stage to "Prepare Segments Point list." 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 Segment Points list.
    2. In the Custom Script text box, add the following Groovy script. The input points field is a string of longitude and latitude coordinates.
      //'points' field is '-73.0,40.5,-73.0,40.7,-72.0,41.3,-73.0,40.5'
      String pointsString = data['points']
      String[] coords = pointsString.split(",");
      def SegmentPoints = []
      def point = [:]
      for (int i = 0; i < coords.length; i=i+2) {
            point = [ 'Longitude': coords[i], 'Latitude': coords[i+1]] 
            SegmentPoints.add(point)
      }
      
      data['SegmentPoints'] = SegmentPoints
      
    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 SegmentPoints (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 Segment Points list as the custom transform. Click OK to leave the Options dialog box.
  5. To use the Prepare Segment Points list in a dataflow, add a Spatial Calculator stage (renamed to Create Line). Double-click the stage to open the Spatial Calculator Options dialog. Select Create Line 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.