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