}
private double[] worldClosest( int x1, int y1, ILayer layer ) throws FactoryException {
Coordinate coord = layer.getMap().getViewportModel().pixelToWorld(x1, y1);
CoordinateReferenceSystem crs = layer.getMap().getViewportModel().getCRS();
MathTransform mt = CRS.findMathTransform(DefaultGeographicCRS.WGS84, crs);
double[] gridSize = getStyle(layer).getGridSize();
try{
if( !mt.isIdentity() ){
double tx=gridSize[0]/2.0;
double ty=gridSize[1]/2.0;
double[] toTransform=new double[]{-tx,-ty,tx,ty};
double[] dest=new double[4];
mt.transform(toTransform,0,dest,0,2);
gridSize=new double[]{Math.abs(dest[2]-dest[0]), Math.abs(dest[3]-dest[1])};
}
}catch (Exception e) {
MapGraphicPlugin.log("",e); //$NON-NLS-1$
}