001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/model/spatialschema/CurveSegmentImpl.java $
002 /*----------------------------------------------------------------------------
003 This file is part of deegree, http://deegree.org/
004 Copyright (C) 2001-2009 by:
005 Department of Geography, University of Bonn
006 and
007 lat/lon GmbH
008
009 This library is free software; you can redistribute it and/or modify it under
010 the terms of the GNU Lesser General Public License as published by the Free
011 Software Foundation; either version 2.1 of the License, or (at your option)
012 any later version.
013 This library is distributed in the hope that it will be useful, but WITHOUT
014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016 details.
017 You should have received a copy of the GNU Lesser General Public License
018 along with this library; if not, write to the Free Software Foundation, Inc.,
019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020
021 Contact information:
022
023 lat/lon GmbH
024 Aennchenstr. 19, 53177 Bonn
025 Germany
026 http://lat-lon.de/
027
028 Department of Geography, University of Bonn
029 Prof. Dr. Klaus Greve
030 Postfach 1147, 53001 Bonn
031 Germany
032 http://www.geographie.uni-bonn.de/deegree/
033
034 e-mail: info@deegree.org
035 ----------------------------------------------------------------------------*/
036 package org.deegree.model.spatialschema;
037
038 import java.io.Serializable;
039
040 import org.deegree.model.crs.CoordinateSystem;
041
042 /**
043 * default implementation of the CurveSegment interface from package deegree.model.spatialschema.
044 * the class is abstract because it should be specialized by derived classes <code>LineString</code>
045 * for example
046 *
047 *
048 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
049 * @author last edited by: $Author: mschneider $
050 *
051 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
052 */
053 public abstract class CurveSegmentImpl implements CurveSegment, Serializable {
054 /** Use serialVersionUID for interoperability. */
055 private final static long serialVersionUID = -8102075931849374162L;
056
057 protected CoordinateSystem crs = null;
058
059 protected Position[] points;
060
061 /**
062 * Creates a new CurveSegmentImpl object.
063 *
064 * @param gmps
065 * @param crs
066 *
067 * @throws GeometryException
068 */
069 protected CurveSegmentImpl( Position[] gmps, CoordinateSystem crs ) throws GeometryException {
070 if ( gmps == null ) {
071 throw new GeometryException( "can't create an empty curve segment" );
072 }
073
074 points = gmps;
075
076 // get spatial reference system of the curve segment from the first point
077 this.crs = crs;
078 }
079
080 /**
081 * returns the first point of the curve. if the curve segment doesn't contain a point
082 * <code>null</code> will be returned
083 */
084 public Point getStartPoint() {
085 return new PointImpl( points[0], crs );
086 }
087
088 /**
089 * returns the last point of the curve. if the curve segment doesn't contain a point
090 * <code>null</code> will be returned
091 */
092 public Point getEndPoint() {
093 return new PointImpl( points[getNumberOfPoints() - 1], crs );
094 }
095
096 /**
097 * returns the number of points building the curve or curve segment
098 */
099 public int getNumberOfPoints() {
100 return points.length;
101 }
102
103 /**
104 * returns all positions of the segement as array of Position. If the segment is empty null will
105 * be returned
106 */
107 public Position[] getPositions() {
108 return points;
109 }
110
111 /**
112 * returns the curve segment position at the submitted index
113 */
114 public Position getPositionAt( int index ) {
115 return points[index];
116 }
117
118 /**
119 * reverses the direction of the curvesegment
120 */
121 public void reverse() {
122 Position[] reverse_ = new Position[points.length];
123
124 for ( int i = 0; i < points.length; i++ ) {
125 reverse_[points.length - 1 - i] = points[i];
126 }
127
128 points = reverse_;
129 }
130
131 /**
132 * returns the coordinate system of the curve segment
133 */
134 public CoordinateSystem getCoordinateSystem() {
135 return crs;
136 }
137
138 /**
139 * checks if this curve segment is completely equal to the submitted geometry
140 *
141 * @param other
142 * object to compare to
143 */
144 @Override
145 public boolean equals( Object other ) {
146 if ( ( other == null ) || !( other instanceof CurveSegmentImpl ) ) {
147 return false;
148 }
149
150 if ( ( crs == null ) && ( ( (CurveSegmentImpl) other ).getCoordinateSystem() != null ) ) {
151 return false;
152 }
153
154 if ( crs != null ) {
155 if ( !crs.equals( ( (CurveSegmentImpl) other ).getCoordinateSystem() ) ) {
156 return false;
157 }
158 } else {
159 if ( ( (CurveSegmentImpl) other ).getCoordinateSystem() != null ) {
160 return false;
161 }
162 }
163
164 Position[] p1 = getPositions();
165 Position[] p2 = ( (CurveSegment) other ).getPositions();
166
167 if ( p1.length != p2.length ) {
168 return false;
169 }
170
171 // if ( !Arrays.equals( p1, p2 ) ) {
172 // TODO
173 // correct comparing of each point considering current tolerance level
174 // }
175
176 return true;
177 }
178
179 /**
180 * The Boolean valued operation "contains" shall return TRUE if this Geometry contains another
181 * Geometry.
182 * <p>
183 * </p>
184 */
185 public boolean contains( Geometry gmo ) {
186 throw new NoSuchMethodError( "the contains operation for curve segments isn't supported at the moment." );
187 }
188
189 @Override
190 protected Object clone()
191 throws CloneNotSupportedException {
192
193 throw new CloneNotSupportedException();
194
195 }
196
197 @Override
198 public String toString() {
199 String ret = null;
200 ret = "points = ";
201 ret += ( "crs = " + crs + "\n" );
202 return ret;
203 }
204 }