001: /*
002: * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
003: * Copyright (C) 2006 - JScience (http://jscience.org/)
004: * All rights reserved.
005: *
006: * Permission to use, copy, modify, and distribute this software is
007: * freely granted, provided that this notice is preserved.
008: */
009: package org.jscience.geography.coordinates.crs;
010:
011: import java.util.Collection;
012: import java.util.Set;
013:
014: import org.jscience.geography.coordinates.CompoundCoordinates;
015: import org.jscience.geography.coordinates.Coordinates;
016: import org.opengis.metadata.Identifier;
017: import org.opengis.referencing.cs.CoordinateSystem;
018: import org.opengis.referencing.cs.CoordinateSystemAxis;
019: import org.opengis.util.InternationalString;
020:
021: /**
022: * This class represents a coordinate reference system combining two or more
023: * distinct reference systems.
024: *
025: * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
026: * @version 3.0, February 13, 2006
027: */
028: public class CompoundCRS<C1 extends Coordinates<?>, C2 extends Coordinates<?>>
029: extends CoordinateReferenceSystem<CompoundCoordinates<C1, C2>> {
030:
031: final CoordinateReferenceSystem<C1> _first;
032:
033: final CoordinateReferenceSystem<C2> _next;
034:
035: final CoordinateSystem _coordinateSystem = new CoordinateSystem() {
036:
037: public int getDimension() {
038: return _first.getCoordinateSystem().getDimension()
039: + _next.getCoordinateSystem().getDimension();
040: }
041:
042: public CoordinateSystemAxis getAxis(int dimension)
043: throws IndexOutOfBoundsException {
044: int firstDimension = _first.getCoordinateSystem()
045: .getDimension();
046: return (dimension < firstDimension) ? _first
047: .getCoordinateSystem().getAxis(dimension) : _next
048: .getCoordinateSystem().getAxis(
049: dimension - firstDimension);
050: }
051:
052: public Identifier getName() {
053: throw new UnsupportedOperationException();
054: }
055:
056: public Collection<String> getAlias() {
057: return EMPTY_SET;
058: }
059:
060: public Set<String> getIdentifiers() {
061: return EMPTY_SET;
062: }
063:
064: public InternationalString getRemarks() {
065: throw new UnsupportedOperationException();
066: }
067:
068: public String toWKT() throws UnsupportedOperationException {
069: throw new UnsupportedOperationException();
070: }
071: };
072:
073: public CompoundCRS(CoordinateReferenceSystem<C1> first,
074: CoordinateReferenceSystem<C2> next) {
075: _first = first;
076: _next = next;
077: }
078:
079: @Override
080: protected CompoundCoordinates<C1, C2> coordinatesOf(
081: AbsolutePosition position) {
082: C1 c1 = _first.coordinatesOf(position);
083: C2 c2 = _next.coordinatesOf(position);
084: return CompoundCoordinates.valueOf(c1, c2);
085: }
086:
087: @Override
088: protected AbsolutePosition positionOf(
089: CompoundCoordinates<C1, C2> coordinates,
090: AbsolutePosition position) {
091: AbsolutePosition firstPosition = _first.positionOf(coordinates
092: .getFirst(), position);
093: return _next.positionOf(coordinates.getNext(), firstPosition);
094: }
095:
096: @Override
097: public CoordinateSystem getCoordinateSystem() {
098: return _coordinateSystem;
099: }
100:
101: }
|