tr.transform(sourcePos, sourcePos);
double utmZoneCenterLongitude = ... // Center lon of zone, example: zone 10 = -123 int zoneNumber = ... // zone number, example: 10 double latitude, longitude = ... // lat, lon in degrees MathTransformFactory mtFactory = ReferencingFactoryFinder.getMathTransformFactory(null); ReferencingFactoryContainer factories = new ReferencingFactoryContainer(null); GeographicCRS geoCRS = org.geotools.referencing.crs.DefaultGeographicCRS.WGS84; CartesianCS cartCS = org.geotools.referencing.cs.DefaultCartesianCS.GENERIC_2D; ParameterValueGroup parameters = mtFactory.getDefaultParameters("Transverse_Mercator"); parameters.parameter("central_meridian").setValue(utmZoneCenterLongitude); parameters.parameter("latitude_of_origin").setValue(0.0); parameters.parameter("scale_factor").setValue(0.9996); parameters.parameter("false_easting").setValue(500000.0); parameters.parameter("false_northing").setValue(0.0); Map properties = Collections.singletonMap("name", "WGS 84 / UTM Zone " + zoneNumber); ProjectedCRS projCRS = factories.createProjectedCRS(properties, geoCRS, null, parameters, cartCS); MathTransform transform = CRS.findMathTransform(geoCRS, projCRS); double[] dest = new double[2]; transform.transform(new double[] {longitude, latitude}, 0, dest, 0, 1); int easting = (int)Math.round(dest[0]); int northing = (int)Math.round(dest[1]);
DirectPosition targetPos = tr.transform(sourcePos, null); double lon = targetPos.getOrdinate(0); double lat = targetPos.getOrdinate(1);
/** * Test method for {@link CoordinateOperationFactoryUsingWKT#createCoordinateOperation}. * * @throws TransformException */ @Test public void testCreateOperationFromCustomCodes() throws Exception { // Test CRSs CoordinateReferenceSystem source = CRS.decode(SOURCE_CRS); CoordinateReferenceSystem target = CRS.decode(TARGET_CRS); MathTransform mt = CRS.findMathTransform(source, target, true); // Test MathTransform double[] p = new double[2]; mt.transform(SRC_TEST_POINT, 0, p, 0, 1); assertEquals(p[0], DST_TEST_POINT[0], 1e-8); assertEquals(p[1], DST_TEST_POINT[1], 1e-8); }
tr.transform(sourcePos, sourcePos);
/** * Test method for {@link CoordinateOperationFactoryUsingWKT#createCoordinateOperation}. * * @throws TransformException */ @Test public void testOverrideEPSGOperation() throws Exception { // Test CRSs CoordinateReferenceSystem source = CRS.decode("EPSG:4269"); CoordinateReferenceSystem target = CRS.decode("EPSG:4326"); MathTransform mt = CRS.findMathTransform(source, target, true); // Test MathTransform double[] p = new double[2]; mt.transform(SRC_TEST_POINT, 0, p, 0, 1); assertEquals(p[0], DST_TEST_POINT[0], 1e-8); assertEquals(p[1], DST_TEST_POINT[1], 1e-8); }
/** See if we can use the stgeorge grid shift files as the ESPG db would like us to */ @Test public void testNadCon() throws Exception { CoordinateReferenceSystem crs4138 = CRS.decode("EPSG:4138"); CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326"); MathTransform mt = CRS.findMathTransform(crs4138, crs4326); assertTrue(mt.toWKT().contains("NADCON")); double[] src = new double[] {-169.625, 56.575}; double[] expected = new double[] {-169.62744, 56.576034}; double[] p = new double[2]; mt.transform(src, 0, p, 0, 1); assertEquals(expected[0], p[0], 1e-6); assertEquals(expected[1], p[1], 1e-6); } }
DirectPosition2D orig = new DirectPosition2D(x, y); DirectPosition2D transformed = new DirectPosition2D(); mathTransform.transform(orig, transformed);
/** * Computes the difference between the ellipsoid and geoid at a specified lat/lon using Geotools EarthGravitationalModel * * @param lat * @param lon * @return difference in meters * @throws FactoryException * @throws TransformException */ public static double computeEllipsoidToGeoidDifference(double lat, double lon) throws FactoryException, TransformException { // Set up a MathTransform based on the EarthGravitationalModel EarthGravitationalModel.Provider provider = new EarthGravitationalModel.Provider(); DefaultMathTransformFactory factory = new DefaultMathTransformFactory(); MathTransform mt = factory.createParameterizedTransform(provider.getParameters().createValue()); // Compute the offset DirectPosition3D dest = new DirectPosition3D(); mt.transform(new DirectPosition3D(lon, lat, 0), dest); return dest.z; } }
/** Transforms a list of coordinate point ordinal values. */ public void transform( final float[] srcPts, final int srcOff, final float[] dstPts, final int dstOff, final int numPts) throws TransformException { transform.transform(srcPts, srcOff, dstPts, dstOff, numPts); }
/** Transforms a list of coordinate point ordinal values. */ public void transform( final double[] srcPts, final int srcOff, final double[] dstPts, final int dstOff, final int numPts) throws TransformException { transform.transform(srcPts, srcOff, dstPts, dstOff, numPts); }
private void mapSrcPoint(double[] coords) throws TransformException { final int npoints = coords.length / 2; // StringBuilder sb = new StringBuilder(); // sb.append("SRC[").append(coords[0]).append(',').append(coords[1]).append(']').append("--g2wd->"); g2wd.transform(coords, 0, coords, 0, npoints); // sb.append("[").append(coords[0]).append(',').append(coords[1]).append(']').append("--d2sCRS->"); dst2srcCRSTransform.transform(coords, 0, coords, 0, npoints); // sb.append('[').append(coords[0]).append(',').append(coords[1]).append(']').append("--w2gs->"); w2gs.transform(coords, 0, coords, 0, npoints); // sb.append('[').append(coords[0]).append(',').append(coords[1]).append(']'); // System.out.println(sb); }
/** Transforms the specified {@code ptSrc} and stores the result in {@code ptDst}. */ @Override public DirectPosition transform(final DirectPosition ptSrc, final DirectPosition ptDst) throws TransformException { assert isValid(); // Note: If we know that the transfert dimension is the same than source // and target dimension, then we don't need to use an intermediate // point. This optimization is done in ConcatenatedTransformDirect. return transform2.transform(transform1.transform(ptSrc, null), ptDst); }
/** Transforms the specified {@code ptSrc} and stores the result in {@code ptDst}. */ @Override public DirectPosition transform(final DirectPosition ptSrc, DirectPosition ptDst) throws TransformException { assert isValid(); ptDst = transform1.transform(ptSrc, ptDst); return transform2.transform(ptDst, ptDst); }
/** Transforms the specified value. */ public double transform(final double value) throws TransformException { final double[] values = new double[] {value}; final double[] buffer = new double[] {transform1.getTargetDimensions()}; transform1.transform(values, 0, buffer, 0, 1); transform2.transform(buffer, 0, values, 0, 1); return values[0]; }
public boolean get(Envelope envelope) throws TransformException { if (!canSimplify(envelope)) { return false; } point[0] = (envelope.getMinX() + envelope.getMaxX()) / 2; point[1] = (envelope.getMinY() + envelope.getMaxY()) / 2; mt.transform(point, 0, point, 0, 1); int r = (int) point[0]; int c = (int) point[1]; return get(r, c); }
public void test() throws Exception { p.setLocation(circumscribed.getCenterX(), circumscribed.getMaxY() + tickle); sphericalGeosToGeog.transform(p, p); } });
public void test() throws Exception { p.setLocation(circumscribed.getCenterX(), circumscribed.getMinY() - tickle); sphericalGeosToGeog.transform(p, p); } });
public void test() throws Exception { p.setLocation(circumscribed.getMinX(), circumscribed.getMaxY()); ellipsoidalGeosToGeog.transform(p, p); } });
public void test() throws Exception { p.setLocation(circumscribed.getCenterX(), circumscribed.getMaxY() + tickle); ellipsoidalGeosToGeog.transform(p, p); } });