GeoTools : TransformationCoordinateFilter

A coordinate filter that can be used to tranform each coordinate in a geometry. This is applied to each individual coordinate, so it does not work well when the polygon goes accross 180 + central lat or 90 + lat of origin. There are also some problems with projections that have issues with 90 lat.


package org.geotools.demo.referencing;

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.CoordinateFilter;
import org.geotools.ct.MathTransform;
import org.geotools.pt.CoordinatePoint;

/**
 * @version $Id:
 * @author rschulz
 */
public class TransformationCoordinateFilter implements CoordinateFilter{
    /* Transform to apply to each coordinate*/
    private MathTransform transform;
    
    /** Creates a new instance of TransformationCoordinateFilter */
    public TransformationCoordinateFilter(MathTransform transform) {
        this.transform = transform;
    }
    
    /*performs a transformation on a coordinate*/
    public void filter(com.vividsolutions.jts.geom.Coordinate coordinate) {
        CoordinatePoint point = new CoordinatePoint(coordinate.x, coordinate.y);
        try {
            point = transform.transform(point, point);
        }
        catch (org.opengis.referencing.operation.TransformException e) {
            System.out.println("Error in transformation: " + e);
        }
        
        coordinate.x = point.ord[0];
        coordinate.y = point.ord[1];
    }
    
}