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 */
009package org.jscience.geography.coordinates.crs;
010
011import java.util.Collection;
012import java.util.Set;
013
014import org.jscience.geography.coordinates.CompoundCoordinates;
015import org.jscience.geography.coordinates.Coordinates;
016import org.opengis.metadata.Identifier;
017import org.opengis.referencing.cs.CoordinateSystem;
018import org.opengis.referencing.cs.CoordinateSystemAxis;
019import 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 */
028public 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) throws IndexOutOfBoundsException {
043            int firstDimension = _first.getCoordinateSystem().getDimension();
044            return (dimension < firstDimension) ? _first.getCoordinateSystem().getAxis(dimension) :
045                _next.getCoordinateSystem().getAxis(dimension - firstDimension);
046        }
047
048        public Identifier getName() {
049            throw new UnsupportedOperationException();
050        }
051
052        public Collection<String> getAlias() {
053            return EMPTY_SET;
054        }
055
056        public Set<String> getIdentifiers() {
057            return EMPTY_SET;
058        }
059
060        public InternationalString getRemarks() {
061            throw new UnsupportedOperationException();
062        }
063
064        public String toWKT() throws UnsupportedOperationException {
065            throw new UnsupportedOperationException();
066        }};
067
068
069    public CompoundCRS(CoordinateReferenceSystem<C1> first, CoordinateReferenceSystem<C2> next) {
070        _first = first;
071        _next = next;        
072    }
073
074    @Override
075    protected CompoundCoordinates<C1, C2> coordinatesOf(AbsolutePosition position) {
076        C1 c1 = _first.coordinatesOf(position);
077        C2 c2 = _next.coordinatesOf(position);
078        return CompoundCoordinates.valueOf(c1, c2);
079    }
080
081    @Override
082    protected AbsolutePosition positionOf(CompoundCoordinates<C1, C2> coordinates, AbsolutePosition position) {
083        AbsolutePosition firstPosition = _first.positionOf(coordinates.getFirst(), position);
084        return _next.positionOf(coordinates.getNext(), firstPosition);
085    }
086
087    @Override
088    public CoordinateSystem getCoordinateSystem() {
089        return _coordinateSystem;
090    }
091   
092}