private List<Point3d> transformDstToSrc( ICRS srcCRS, List<Point3d> points ) throws TransformationException { // transform all grid points return new CoordinateTransformer( srcCRS ).transform( getTargetCRS(), points ); }
/** * Transforms a given coordinate into the CoordinateTransformer's coordinate system. * * @param sourceCRS * crs of the input coordinate, must not be <code>null</code> * @param input * input coordinate, must not be <code>null</code> and array length must match the number of dimensions * of <code>sourceCRS</code> * @param out * output coordinate, used to store the transformed ordinates, must not be <code>null</code> and array * length must match the number of dimensions of the target crs * @return transformed coordinate, this is the same instance as <code>out</code> * @throws TransformationException * @throws IllegalArgumentException */ public double[] transform( ICRS sourceCRS, double[] input, double[] out ) throws IllegalArgumentException, TransformationException { Transformation trans = createCRSTransformation( sourceCRS ); trans.doTransform( input, 0, out, 0, input.length ); return out; } }
private double[] getTransformedCoordinate( ICRS inputCRS, double[] inputCoordinate ) throws TransformationException, UnknownCRSException { if ( inputCRS != null && outputCRS != null && !inputCRS.equals( outputCRS ) ) { if ( transformer == null ) { throw new UnknownCRSException( outputCRS.getAlias() ); } double[] out = transformer.transform( inputCRS, inputCoordinate, transformedOrdinates ); return out; } return inputCoordinate; }
/** * Creates a new {@link GML2GeometryWriter} instance. * * @param gmlStream * gml stream writer, must not be <code>null</code> */ public GML2GeometryWriter( GMLStreamWriter gmlStream ) { super( gmlStream ); this.outputCRS = gmlStream.getOutputCrs(); this.simplifier = gmlStream.getGeometrySimplifier(); IUnit crsUnits = null; if ( outputCRS != null ) { try { ICRS crs = outputCRS; crsUnits = crs.getAxis()[0].getUnits(); transformer = new CoordinateTransformer( crs ); transformedOrdinates = new double[crs.getDimension()]; // geoTransformer = new GeometryTransformer( crs ); } catch ( Exception e ) { LOG.debug( "Could not create transformer for CRS '" + outputCRS + "': " + e.getMessage() + ". Encoding will fail if a transformation is actually necessary." ); } } formatter = gmlStream.getCoordinateFormatter(); if ( formatter == null ) { formatter = new DecimalCoordinateFormatter( crsUnits ); } }
return new ArrayList<Point3d>(); Transformation trans = createCRSTransformation( sourceCRS ); if ( TransformationFactory.isIdentity( trans ) ) { return copy; } else if ( sourceCRS.getDimension() == 2 && getTargetCRS().getDimension() == 2 ) {
private double[] getTransformedCoordinate( ICRS inputCRS, double[] inputCoordinate ) throws TransformationException, UnknownCRSException { if ( inputCRS != null && outputCRS != null && !inputCRS.equals( outputCRS ) ) { if ( transformer == null ) { throw new UnknownCRSException( outputCRS.getAlias() ); } double[] out = transformer.transform( inputCRS, inputCoordinate, transformedOrdinates ); return out; } return inputCoordinate; }
/** * Creates a new {@link GML3GeometryWriter} instance. * * @param gmlStreamWriter * gml stream writer, must not be <code>null</code> */ public GML3GeometryWriter( GMLStreamWriter gmlStreamWriter ) { super( gmlStreamWriter ); this.outputCRS = gmlStreamWriter.getOutputCrs(); this.simplifier = gmlStreamWriter.getGeometrySimplifier(); IUnit crsUnits = null; if ( outputCRS != null ) { try { ICRS crs = outputCRS; crsUnits = crs.getAxis()[0].getUnits(); transformer = new CoordinateTransformer( crs ); transformedOrdinates = new double[crs.getDimension()]; geoTransformer = new GeometryTransformer( crs ); } catch ( Exception e ) { LOG.debug( "Could not create transformer for CRS '" + outputCRS + "': " + e.getMessage() + ". Encoding will fail if a transformation is actually necessary." ); } } formatter = gmlStreamWriter.getCoordinateFormatter(); if ( formatter == null ) { formatter = new DecimalCoordinateFormatter( crsUnits ); } }
/** * This method transforms the given coordinate (in the sourceCRS) into a coordinate of the targetCRS and back. * * @param coordinate * to be transformed. * @param withInverse * true if the inverse has to be calculated. * @throws TransformationException * @throws IllegalArgumentException * @throws UnknownCRSException */ public void doTransform( double[] coordinate, boolean withInverse ) throws IllegalArgumentException, TransformationException, UnknownCRSException { CoordinateTransformer ct = new CoordinateTransformer( targetCRS ); double[] in = Arrays.copyOf( coordinate, 3 ); // point to transform double[] out = new double[3]; outputPoint( "The original point in crs: " + sourceCRS.getAlias() + ": ", in, sourceCRS ); ct.transform( sourceCRS, in, out ); outputPoint( "The transformed point in crs: " + targetCRS.getAlias() + ": ", out, targetCRS ); if ( withInverse ) { // transform back to source CRS ct = new CoordinateTransformer( sourceCRS ); double[] nIn = new double[3]; ct.transform( targetCRS, out, nIn ); outputPoint( "The inversed transformed point in crs: " + sourceCRS.getAlias() + ": ", nIn, sourceCRS ); } }
double[] bbox = getAreaOfUseBBox(); CoordinateTransformer t = new CoordinateTransformer( this ); try { ICRS defWGS = GeographicCRS.WGS84; points = t.transform( defWGS, points ); axis0Min = Double.MAX_VALUE; axis1Min = Double.MAX_VALUE;