GeoToolkit project, reprojecting coordinates example

I would like to have written this post some time ago but time is not something I have in exces.

This post starts when my friend Johann let me know the creation of the GeoToolkit project, a fork of GeoTools, started by one of the originals GeoTools authors. Take a look at project's history to know more details about the reasons.

Next is a simple example showing how to reproject coordinates from WSG84(EPSG:4326) to EPSG:3068 that, for those interested, I used in a program to render CityGML files in a Java 3D viewer called pTolemy3D.

public static boolean translate(GeneralDirectPosition source, GeneralDirectPosition target) { CRSAuthorityFactory factory = AuthorityFactoryFinder.getCRSAuthorityFactory("EPSG", null); try { ProjectedCRS projSource = factory.createProjectedCRS("3068"); GeodeticCRS projTarget = factory.createGeographicCRS("4326"); // NOTE: This is another way to create the right projection: // ProjectedCRS proj = (ProjectedCRS) CRS.decode("EPSG:3068"); // System.out.println("Orig: " + projSource); // System.out.println("Target: " + projTarget); MathTransform transform = CRS.findMathTransform(projSource, projTarget); // System.out.println("Transform: " + transform); try { transform.transform(source, target); return true; // System.out.println("Point Source: " + psource); // System.out.println("Point Target: " + ptarget); } catch (MismatchedDimensionException ex) { Logger.getLogger(GeoUtil.class.getName()).log(Level.SEVERE, null, ex); } catch (TransformException ex) { Logger.getLogger(GeoUtil.class.getName()).log(Level.SEVERE, null, ex); } } catch (NoSuchAuthorityCodeException ex) { Logger.getLogger(GeoUtil.class.getName()).log(Level.SEVERE, null, ex); } catch (FactoryException ex) { Logger.getLogger(GeoUtil.class.getName()).log(Level.SEVERE, null, ex); } return false; }

Not so much, but hope it will be useful for someone and hope more users start to use GeoToolkit.

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.