ProjectionHelper implements PointTransformer { public static Point transformPoint(final double lon, final double lat, final String sourceSRS, final String targetSRS) { return transformPoint(new Point(lon, lat), sourceSRS, targetSRS); }  static Point transformPoint(final double lon, final double lat, final String sourceSRS, final String targetSRS); Point reproject(final Point point, final String sourceSRS, final String targetSRS); static Point transformPoint(final Point point, final String sourceSRS, final String targetSRS); static Point transformPoint(final String lon, final String lat, final String sourceSRS, final String targetSRS); static Point transformPoint(final double lon, final double lat, final CoordinateReferenceSystem sourceCrs, final String targetSRS); static Point transformPoint(final double lon, final double lat, final CoordinateReferenceSystem sourceCrs, final CoordinateReferenceSystem targetCrs); static Point transformPoint(final Point point, final CoordinateReferenceSystem sourceCrs, final CoordinateReferenceSystem targetCrs); static boolean isFirstAxisNorth(CoordinateReferenceSystem crs); static String shortSyntaxEpsg(String crs); static String longSyntaxEpsg(String crs); static CoordinateReferenceSystem longSyntaxCrs(String crs); static JSONObject transformGeometry(JSONObject geometry, final String sourceSRS, final String targetSRS, boolean sourceLon1st, boolean targetLon1st); static void flipFeatureYX(Geometry fnG); static void swapGeometryXY(FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection);  }
@Test public void testTransformPoint() throws Exception { double y = 60.113924; double x = 25.017104; Point p2 = ProjectionHelper.transformPoint(new Point(x, y), EPSG_4258, EPSG_3067); assertEquals("lon", 389790.212234411, p2.getLon(), 1e-9); assertEquals("lat", 6665752.471279182, p2.getLat(), 0.0); Point p3 = ProjectionHelper.transformPoint(x, y, EPSG_4258, EPSG_3067); assertEquals("lon", 389790.212234411, p3.getLon(), 1e-9); assertEquals("lat", 6665752.471279182, p3.getLat(), 0.0); }
@Test public void testTransformPointEPSG_4326NoTransform() throws Exception { double lat = 61.4980214; double lon = 23.7603118; Point p3 = ProjectionHelper.transformPoint(lon, lat, EPSG_4326, EPSG_4326); assertEquals("lon", lon, p3.getLon(), 0.0); assertEquals("lat", lat, p3.getLat(), 0.0); }
@Test public void testTransformPointEPSG_3067ToEPSG_4326() throws Exception { double lat = 7596848.323; double lon = 500001.1369; Point p3 = ProjectionHelper.transformPoint( lon, lat, EPSG_3067,EPSG_4326); Point p4 = ProjectionHelper.transformPoint( p3.getLon(), p3.getLat(), EPSG_4326, EPSG_3067); assertEquals("lon 3067-45326-3067", lon, p4.getLon(), 0.01); assertEquals("lat 3067-4326-3067", lat, p4.getLat(), 0.01); }
@Test public void testTransformPointCRSsForceXY() throws Exception { double lat = 61.49802149449156; double lon = 23.7603118; CoordinateReferenceSystem CRS4326 = CRS.decode(EPSG_4326, true); CoordinateReferenceSystem CRS3035 = CRS.decode(EPSG_3035, true); CoordinateReferenceSystem CRS3067 = CRS.decode(EPSG_3067, true); CoordinateReferenceSystem CRS3857 = CRS.decode(EPSG_3857, true); Point p3 = ProjectionHelper.transformPoint(lon, lat, CRS4326, CRS3035); Point p4 = ProjectionHelper.transformPoint(p3.getLon(), p3.getLat(), CRS3035, CRS4326); assertEquals("lon 3035to4326", lon, p4.getLon(), 0.000001); assertEquals("lat 3035to4326", lat, p4.getLat(), 0.000001); Point p5 = ProjectionHelper.transformPoint(p4.getLon(), p4.getLat(), CRS4326, CRS3067); Point p6 = ProjectionHelper.transformPoint(p5.getLon(), p5.getLat(), CRS3067, CRS4326); assertEquals("lon 3067to4326", lon, p6.getLon(), 0.000001); assertEquals("lat 3067to4326", lat, p6.getLat(), 0.000001); Point p7 = ProjectionHelper.transformPoint(p5.getLon(), p5.getLat(), CRS3067, CRS3857); Point p8 = ProjectionHelper.transformPoint(p7.getLon(), p7.getLat(), CRS3857, CRS3067); assertEquals("lon 3857to3067", p5.getLon(), p8.getLon(), 0.01); assertEquals("lat 3857to3067", p5.getLat(), p8.getLat(), 0.01); }
@Test public void testTransformPointCRSs() throws Exception { double lat = 61.49802149449156; double lon = 23.7603118; CoordinateReferenceSystem CRS4326 = CRS.decode(EPSG_4326); CoordinateReferenceSystem CRS3035 = CRS.decode(EPSG_3035); CoordinateReferenceSystem CRS3067 = CRS.decode(EPSG_3067); CoordinateReferenceSystem CRS3857 = CRS.decode(EPSG_3857); Point p3 = ProjectionHelper.transformPoint(lon, lat, CRS4326, CRS3035); Point p4 = ProjectionHelper.transformPoint(p3.getLon(), p3.getLat(), CRS3035, CRS4326); assertEquals("lon 3035to4326", lon, p4.getLon(), 0.000001); assertEquals("lat 3035to4326", lat, p4.getLat(), 0.000001); Point p5 = ProjectionHelper.transformPoint(p4.getLon(), p4.getLat(), CRS4326, CRS3067); Point p6 = ProjectionHelper.transformPoint(p5.getLon(), p5.getLat(), CRS3067, CRS4326); assertEquals("lon 3067to4326", lon, p6.getLon(), 0.000001); assertEquals("lat 3067to4326", lat, p6.getLat(), 0.000001); Point p7 = ProjectionHelper.transformPoint(p5.getLon(), p5.getLat(), CRS3067, CRS3857); Point p8 = ProjectionHelper.transformPoint(p7.getLon(), p7.getLat(), CRS3857, CRS3067); assertEquals("lon 3857to3067", p5.getLon(), p8.getLon(), 0.01); assertEquals("lat 3857to3067", p5.getLat(), p8.getLat(), 0.01); }