/** * Creates the inverse CoordinateOperation. * @return * @throws org.cts.op.NonInvertibleOperationException */ @Override public CoordinateOperation inverse() throws NonInvertibleOperationException { CoordinateOperation[] inverse_sequence = new CoordinateOperation[sequence.length]; for (int i = 0; i < sequence.length; i++) { // If one of the CoordinateOperation is not invertible, it // will throw a NonInvertibleOperationException. inverse_sequence[sequence.length - i - 1] = sequence[i].inverse(); //if (inverse_sequence[sequence.length-i-1] == null) return null; } return new CoordinateOperationSequence(getIdentifier(), inverse_sequence, precision); }
/** * Create a CoordinateOperationSequence from an identifier an array of * {@linkplain org.cts.op.CoordinateOperation CoordinateOperations} and a * precision. * * @param identifier this operation sequence identifier * @param sequence a list containing ordered operations to apply to * coordinates * @param precision precision of this CoordinateOperation as a whole. */ public CoordinateOperationSequence(Identifier identifier, CoordinateOperation[] sequence, double precision) { super(identifier); this.sequence = sequence; this.sequence = cleanSequence(sequence); this.precision = precision; }
result.add(op); } else if (op instanceof CoordinateOperationSequence) { result = fusionSequences(result, Arrays.asList(((CoordinateOperationSequence) op).getSequence()));
/** * Returns a String representation of this CoordinateOperationSequence. It * gives a correct representation of CoordinateOperationSequence nested in a * CoordinateOperationSequence, but will not display nicely a third level of * nests operation. */ @Override public String toString() { StringBuilder sb = new StringBuilder(256); sb.append(getIdentifier().getName()).append("{"); for (CoordinateOperation op : sequence) { sb.append("\n ").append(op.toString()); } sb.append("\n} precision = " + getPrecision()); return sb.toString(); }
/** * Adds a CoordinateOperation to the list of CoordinateOperations usable to transform * coordinates from source CRS to target CRS. * parameter. This CoordinateOperation links a source * {@link org.cts.crs.GeodeticCRS} to a target {@link org.cts.crs.GeodeticCRS} using the * same {@link org.cts.datum.GeodeticDatum}. * Remember that {@link org.cts.crs.GeodeticCRS}s include {@link org.cts.crs.GeocentricCRS}s, * {@link org.cts.crs.Geographic2DCRS}s, {@link org.cts.crs.Geographic3DCRS}s and * {@link org.cts.crs.ProjectedCRS}s. * * @param source the source geodetic coordinate reference system * @param target the target geodetic coordinate reference system * @param opList the list in which the CoordinateOperation must be added */ private static void addCoordinateOperations( GeodeticCRS source, GeodeticCRS target, Set<CoordinateOperation> opList) throws CoordinateOperationException { try { opList.add(new CoordinateOperationSequence( new Identifier(CoordinateOperationSequence.class, source.getCode() + " to " + target.getCode()), source.toGeographicCoordinateConverter(), target.fromGeographicCoordinateConverter())); } catch (NonInvertibleOperationException e) { LOG.warn("Operation from " + source.getCode() + " to " + target.getCode() + " could not be created"); LOG.error("CoordinateOperationFactory", e); } }
ops = cleverAdd(ops, UnitConversion.createUnitConverter(Unit.RADIAN, getCoordinateSystem().getUnit(0), Unit.METER, getCoordinateSystem().getUnit(2))); ops = cleverAdd(ops, CoordinateSwitch.SWITCH_LAT_LON); ops = cleverAdd(ops, UnitConversion.createUnitConverter(Unit.METER, getCoordinateSystem().getUnit(0), Unit.METER, getCoordinateSystem().getUnit(2))); ops = cleverAdd(ops, CoordinateSwitch.SWITCH_LAT_LON); || getCoordinateSystem().getAxis(i).getDirection() == Axis.Direction.WEST || getCoordinateSystem().getAxis(i).getDirection() == Axis.Direction.DOWN) { ops = cleverAdd(ops, new OppositeCoordinate(i)); return new CoordinateOperationSequence(new Identifier( CoordinateOperationSequence.class), ops);
/** * Returns true if object is equals to * <code>this</code>. Tests equality between the length of the sequences and * then the equality of each CoordinateOperation. * * @param o The object to compare this CoordinateOperationSequence * against */ @Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof CoordinateOperationSequence) { CoordinateOperationSequence cooordseq = (CoordinateOperationSequence) o; if (getSequence().length == cooordseq.getSequence().length) { for (int i = 0; i < getSequence().length; i++) { if (!getSequence()[i].equals(cooordseq.getSequence()[i])) { return false; } } return true; } } return false; }
/** * cleverAdd add cleverly a CoordinateOperation in a list of * CoordinateOperations by removing the last element of list if it is the * inverse of the element to add. If not, it simply add the * CoordinateOperation at the end of the list. NB1: If * <code>op</code> is the Identity transformation, it is added only if * <code>ops</code> is empty. NB2: If * <code>ops</code> contains only the identity transformation, it is * replaced by * <code>op</code>. * * @param ops the list in which the CoordinateOperation should be added * @param op the CoordinateOperation to add list) */ public static List<CoordinateOperation> cleverAdd(List<CoordinateOperation> ops, CoordinateOperation op) { List<CoordinateOperation> result = new ArrayList<CoordinateOperation>(ops); List<CoordinateOperation> addedOp = new ArrayList<CoordinateOperation>(); addedOp.add(op); result = fusionSequences(result, addedOp); return result; }
/** * @return * @throws org.cts.op.NonInvertibleOperationException * @see GeodeticCRS#fromGeographicCoordinateConverter() */ @Override public CoordinateOperation fromGeographicCoordinateConverter() throws NonInvertibleOperationException { List<CoordinateOperation> ops = new ArrayList<CoordinateOperation>(); if (!getDatum().getPrimeMeridian().equals(PrimeMeridian.GREENWICH)) { ops.add(LongitudeRotation.getLongitudeRotationFrom(getDatum().getPrimeMeridian())); } ops.add(new Geographic2Geocentric(getDatum().getEllipsoid())); return new CoordinateOperationSequence(new Identifier( CoordinateOperationSequence.class), ops); }
ops = cleverAdd(ops, Identity.IDENTITY); ops = cleverAdd(ops, UnitConversion.createUnitConverter(Unit.RADIAN, Unit.DEGREE, Unit.METER, Unit.METER)); ops.add(z_transfo); ops.add(UnitConversion.createUnitConverter(Unit.DEGREE, Unit.RADIAN, Unit.METER, Unit.METER)); throw new CoordinateOperationNotFoundException("Unknown vertical datum type for this CRS : " + this); return new CoordinateOperationSequence(new Identifier( CoordinateOperationSequence.class), ops);
/** * Returns {@link org.cts.op.CoordinateOperation}s including operations of a particular type. */ public static Set<CoordinateOperation> includeFilter(Collection<? extends CoordinateOperation> ops, Class clazz) { Set<CoordinateOperation> list = new HashSet<CoordinateOperation>(); for (CoordinateOperation op : ops) { if (clazz.isAssignableFrom(op.getClass())) list.add(op); else if (op instanceof CoordinateOperationSequence) { boolean includeOp = false; for (CoordinateOperation subOp : ((CoordinateOperationSequence)op).getSequence()) { if (clazz.isAssignableFrom(subOp.getClass())) { includeOp = true; break; } } if (includeOp) list.add(op); } } return list; }
if (op1.equals(Identity.IDENTITY)) { lst1.remove(lst1.size() - 1); return fusionSequences(lst1, lst2); return fusionSequences(lst1, lst2); lst1.remove(lst1.size() - 1); lst2.remove(0); return fusionSequences(lst1, lst2);
/** * @return * @throws org.cts.op.NonInvertibleOperationException * @see GeodeticCRS#toGeographicCoordinateConverter() */ @Override public CoordinateOperation toGeographicCoordinateConverter() throws NonInvertibleOperationException { List<CoordinateOperation> ops = new ArrayList<CoordinateOperation>(); ops.add(new Geocentric2Geographic(getDatum().getEllipsoid())); if (!getDatum().getPrimeMeridian().equals(PrimeMeridian.GREENWICH)) { ops.add(LongitudeRotation.getLongitudeRotationTo(getDatum().getPrimeMeridian())); } return new CoordinateOperationSequence(new Identifier( CoordinateOperationSequence.class), ops); }
/** * Creates a CoordinateOperationSequence from an identifier, a List of * {@linkplain org.cts.op.CoordinateOperation CoordinateOperations} and a * precision. * * @param identifier this operation sequence identifier * @param list a list containing ordered operations to apply to coordinates * @param precision precision of this CoordinateOperation as a whole. */ public CoordinateOperationSequence(Identifier identifier, List<CoordinateOperation> list, double precision) { super(identifier); this.sequence = list.toArray(new CoordinateOperation[list.size()]); this.sequence = cleanSequence(sequence); this.precision = precision; }
/** * Returns {@link org.cts.op.CoordinateOperation}s excluding sequence containing a particular operation type. * @param ops * @param clazz * @return */ public static Set<CoordinateOperation> excludeFilter(Collection<? extends CoordinateOperation> ops, Class clazz) { Set<CoordinateOperation> list = new HashSet<CoordinateOperation>(); for (CoordinateOperation op : ops) { if (clazz.isAssignableFrom(op.getClass())) continue; if (op instanceof CoordinateOperationSequence) { boolean excludedOp = false; for (CoordinateOperation subOp : ((CoordinateOperationSequence)op).getSequence()) { if (clazz.isAssignableFrom(subOp.getClass())) { excludedOp = true; break; } } if (!excludedOp) list.add(op); } } return list; }
/** * @return * @see GeodeticCRS#toGeographicCoordinateConverter() */ @Override public CoordinateOperation toGeographicCoordinateConverter() { List<CoordinateOperation> ops = new ArrayList<CoordinateOperation>(); for (int i = 0; i < 2; i++) { if (getCoordinateSystem().getAxis(i).getDirection() == SOUTH || getCoordinateSystem().getAxis(i).getDirection() == WEST) { ops.add(new OppositeCoordinate(i)); } } // Convert from source unit to radians ops.add(UnitConversion.createUnitConverter(getCoordinateSystem().getUnit(0), RADIAN)); // switch from LON/LAT to LAT/LON coordinate if necessary if (getCoordinateSystem().getAxis(0).getDirection() == EAST || getCoordinateSystem().getAxis(0).getDirection() == WEST) { ops.add(CoordinateSwitch.SWITCH_LAT_LON); } // Add a third value to transform the geographic2D coord into a // geographic3D coord ops.add(ChangeCoordinateDimension.TO3D); return new CoordinateOperationSequence(new Identifier( CoordinateOperationSequence.class), ops); }
/** * Create a CoordinateOperationSequence from an identifier and a List of * {@linkplain org.cts.op.CoordinateOperation CoordinateOperations}. Precision * of this sequence is considered as the sum of all single * {@link org.cts.op.CoordinateOperation}. * * @param identifier this operation sequence identifier * @param list a list containing ordered operations to apply to coordinates */ public CoordinateOperationSequence(Identifier identifier, List<CoordinateOperation> list) { super(identifier); this.sequence = list.toArray(new CoordinateOperation[list.size()]); this.sequence = cleanSequence(sequence); for (CoordinateOperation op : sequence) { precision += op.getPrecision(); } }
/** * @return * @see GeodeticCRS#fromGeographicCoordinateConverter() */ @Override public CoordinateOperation fromGeographicCoordinateConverter() { List<CoordinateOperation> ops = new ArrayList<CoordinateOperation>(); // Remove the third value to transform the geographic3D coord into a // geographic2D coord ops.add(ChangeCoordinateDimension.TO2D); // switch from LON/LAT to LAT/LON coordinate if necessary if (getCoordinateSystem().getAxis(0).getDirection() == EAST || getCoordinateSystem().getAxis(0).getDirection() == WEST) { ops.add(CoordinateSwitch.SWITCH_LAT_LON); } // Convert from radian to this coordinate system's units ops.add(UnitConversion.createUnitConverter(RADIAN, getCoordinateSystem().getUnit(0))); for (int i = 0; i < 2; i++) { if (getCoordinateSystem().getAxis(i).getDirection() == SOUTH || getCoordinateSystem().getAxis(i).getDirection() == WEST) { ops.add(new OppositeCoordinate(i)); } } return new CoordinateOperationSequence(new Identifier( CoordinateOperationSequence.class), ops); }
/** * Create a CoordinateOperationSequence from an identifier and an array of * {@linkplain org.cts.op.CoordinateOperation CoordinateOperations}. Precision * of this sequence is considered as the sum of all single * {@link org.cts.op.CoordinateOperation}. * * @param identifier this operation sequence identifier * @param sequence an array containing ordered operations to apply to * coordinates */ public CoordinateOperationSequence(Identifier identifier, CoordinateOperation... sequence) { super(identifier); this.sequence = sequence; this.sequence = cleanSequence(sequence); for (CoordinateOperation op : sequence) { precision += op.getPrecision(); } }
/** * @return * @see GeodeticCRS#fromGeographicCoordinateConverter() */ @Override public CoordinateOperation fromGeographicCoordinateConverter() { List<CoordinateOperation> ops = new ArrayList<CoordinateOperation>(); // Remove the third value to transform the geographic3D coord into a // geographic2D coord ops.add(ChangeCoordinateDimension.TO2D); // Projection ops.add(projection); // switch easting/northing coordinate if necessary if (getCoordinateSystem().getAxis(0).getDirection() == NORTH || getCoordinateSystem().getAxis(0).getDirection() == SOUTH) { ops.add(CoordinateSwitch.SWITCH_LAT_LON); } // Unit conversion if (getCoordinateSystem().getUnit(0) != METER) { ops.add(UnitConversion.createUnitConverter(METER, getCoordinateSystem().getUnit(0))); } for (int i = 0; i < 2; i++) { if (getCoordinateSystem().getAxis(i).getDirection() == SOUTH || getCoordinateSystem().getAxis(i).getDirection() == WEST) { ops.add(new OppositeCoordinate(i)); } } return new CoordinateOperationSequence(new Identifier( CoordinateOperationSequence.class), ops); }