Saving Geometries with a Custom Transform

To access spatial geometries using a custom transform, create a dataflow following the steps below. This process will read the geometries and save them as Well-Known Text files using Groovy scripts.

  1. Create a job in Enterprise Designer and place a Read Spatial Data stage on it.
    The stage is configured to read the heterogeneous geometry file and include only the Geometry field in the flow.
  2. Create a Transformer stage 'setGeomType' that uses a custom transform. This transform will use Groovy to get the type of IGeometry from the Geometry field and add a new field to the flow of type String that indicates the type of geometry.
    def geometry = data['Geometry']
    
    def geometryType = geometry.getType()
    
    data['GeometryType'] = geometryType.toString()
    
  3. Add a Conditional Router 'geomTypeRouter' to the flow. It routes fields to other parts of the flow based on the value of the GeometryType field.
  4. Create custom transforms for each IGeometry you want to convert to WKT. Each port of the setGeomType router will go to a different transform.

    For example, use this Groovy code to convert the IPointGeometry to a WKT POINT:

    def point = data['Geometry']
    
    data['WKT'] = 'POINT(' + point.getX() + ', ' + point.getY() + ')'
    

    Use this Groovy code to convert the IMultiCurve into a WKT MULTILINESTRING:

    def multiCurve = data['Geometry']
    
    def wkt = new StringBuffer('MULTILINESTRING (')
    
    def dp = new com.mapinfo.midev.geometry.DirectPosition()
    
    multiCurve.each {com.mapinfo.midev.geometry.ICurve curve ->
      wkt << '('
    
      def lineString = curve.asLineString()
      
      lineString.each{curveSegment ->
        def controlPointIterator = curveSegment.getControlPointIterator()
        while (controlPointIterator.hasNext()) {
          controlPointIterator.nextDirectPosition(dp)
          wkt << dp.getX() << ', ' << dp.getY() << ','
        }
      }
      
      wkt.setCharAt(wkt.size() - 1, (char)')')
    }
    
    wkt << ')'
    
    data['WKT'] = wkt.toString()
    
  5. Connect each WKT transform stage to its own Write to File stage.
The final dataflow looks like this: