001: //$HeadURL: $
002: /*---------------- FILE HEADER ------------------------------------------
003: This file is part of deegree.
004: Copyright (C) 2001-2008 by:
005: Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/deegree/
007: lat/lon GmbH
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: Contact:
022:
023: Andreas Poth
024: lat/lon GmbH
025: Aennchenstr. 19
026: 53177 Bonn
027: Germany
028: E-Mail: poth@lat-lon.de
029:
030: Prof. Dr. Klaus Greve
031: Department of Geography
032: University of Bonn
033: Meckenheimer Allee 166
034: 53115 Bonn
035: Germany
036: E-Mail: greve@giub.uni-bonn.de
037: ---------------------------------------------------------------------------*/
038:
039: package org.deegree.crs.transformations;
040:
041: import java.util.ArrayList;
042: import java.util.List;
043:
044: import javax.vecmath.Point2d;
045: import javax.vecmath.Point3d;
046:
047: import org.deegree.crs.coordinatesystems.ProjectedCRS;
048: import org.deegree.crs.exceptions.ProjectionException;
049: import org.deegree.crs.exceptions.TransformationException;
050: import org.deegree.crs.projections.Projection;
051: import org.deegree.framework.log.ILogger;
052: import org.deegree.framework.log.LoggerFactory;
053:
054: /**
055: * The <code>ProjectionTransform</code> class wraps the access to a projection, by calling it's doProjection.
056: *
057: * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
058: *
059: * @author last edited by: $Author:$
060: *
061: * @version $Revision:$, $Date:$
062: *
063: */
064:
065: public class ProjectionTransform extends CRSTransformation {
066:
067: private static ILogger LOG = LoggerFactory
068: .getLogger(ProjectionTransform.class);
069:
070: private Projection projection;
071:
072: /**
073: * @param projectedCRS
074: * The crs containing a projection.
075: */
076: public ProjectionTransform(ProjectedCRS projectedCRS) {
077: super (projectedCRS.getGeographicCRS(), projectedCRS);
078: this .projection = projectedCRS.getProjection();
079: }
080:
081: @Override
082: public List<Point3d> doTransform(List<Point3d> srcPts)
083: throws TransformationException {
084: List<Point3d> result = new ArrayList<Point3d>(srcPts.size());
085: if (ILogger.LOG_DEBUG == LOG.getLevel()) {
086: StringBuilder sb = new StringBuilder(
087: isInverseTransform() ? "An inverse" : "A");
088: sb.append(" projection transform with incoming points: ");
089: sb.append(srcPts);
090: sb.append(" and following projection: ");
091: sb.append(projection.getIdAndName());
092: LOG.logDebug(sb.toString());
093: }
094: TransformationException trans = new TransformationException(
095: srcPts.size());
096: if (isInverseTransform()) {
097:
098: for (int i = 0; i < srcPts.size(); ++i) {
099: Point3d p = srcPts.get(i);
100: try {
101: Point2d tmp = projection.doInverseProjection(p.x,
102: p.y);
103: result.add(new Point3d(tmp.x, tmp.y, p.z));
104: } catch (ProjectionException e) {
105: trans.setTransformError(i, e.getMessage());
106: result.add(srcPts.get(i));
107: }
108: }
109: } else {
110: for (int i = 0; i < srcPts.size(); ++i) {
111: Point3d p = srcPts.get(i);
112: try {
113: Point2d tmp = projection.doProjection(p.x, p.y);
114: result.add(new Point3d(tmp.x, tmp.y, p.z));
115: } catch (ProjectionException e) {
116: trans.setTransformError(i, e.getMessage());
117: result.add(srcPts.get(i));
118: }
119: }
120: }
121: if (!trans.getTransformErrors().isEmpty()) {
122: trans.setTransformedPoints(result);
123: throw trans;
124: }
125: return result;
126: }
127:
128: @Override
129: public boolean isIdentity() {
130: // a projection cannot be an identity it doesn't make a lot of sense.
131: return false;
132: }
133:
134: @Override
135: public String toString() {
136: return super .toString() + " - Projection: "
137: + projection.getName();
138: }
139:
140: @Override
141: public String getName() {
142: return "Projection-Transform";
143: }
144:
145: }
|