001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/spatialschema/LineStringImpl.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2006 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.framework.log.ILogger;
049 import org.deegree.framework.log.LoggerFactory;
050 import org.deegree.model.crs.CoordinateSystem;
051
052
053 /**
054 * default implementation of the LineString interface of
055 * package jago.model.
056 *
057 * ------------------------------------------------------------
058 * @version 10.6.2001
059 * @author Andreas Poth
060 */
061 class LineStringImpl extends CurveSegmentImpl implements LineString, Serializable {
062 /** Use serialVersionUID for interoperability. */
063 private final static long serialVersionUID = 8093549521711824076L;
064
065 private static final ILogger LOG = LoggerFactory.getLogger( LineStringImpl.class );
066
067 /**
068 * Creates a new LineStringImpl object.
069 *
070 * @param gmps
071 * @param cs
072 *
073 * @throws GeometryException
074 */
075 public LineStringImpl( Position[] gmps, CoordinateSystem cs )
076 throws GeometryException {
077 super( gmps, cs );
078 }
079
080 /**
081 * returns a shallow copy of the geometry
082 */
083 public Object clone() {
084 CurveSegment cs = null;
085
086 try {
087 cs = new LineStringImpl( getPositions(), getCoordinateSystem() );
088 } catch ( Exception ex ) {
089 LOG.logError( "LineString_Impl.clone: ", ex );
090 }
091
092 return cs;
093 }
094
095 /**
096 * returns the length of the curve in units of the
097 * related spatial reference system
098 */
099 public double getLength() {
100 return -1;
101 }
102
103 /**
104 * returns a reference to itself
105 */
106 public LineString getAsLineString() throws GeometryException {
107 return this;
108 }
109
110 /**
111 * The Boolean valued operation "intersects" shall return TRUE if this Geometry
112 * intersects another Geometry. Within a Complex, the Primitives do not
113 * intersect one another. In general, topologically structured data uses shared
114 * geometric objects to capture intersection information.
115 */
116 public boolean intersects( Geometry gmo ) {
117 boolean inter = false;
118
119 try {
120 if ( gmo instanceof Point ) {
121 double tolerance = ( (Point)gmo ).getTolerance();
122 inter = LinearIntersects.intersects( ( (Point)gmo ).getPosition(), this, tolerance );
123 } else if ( gmo instanceof Curve ) {
124 CurveSegment[] cs = new CurveSegment[] { this };
125 inter = LinearIntersects.intersects( (Curve)gmo, new CurveImpl( cs ) );
126 } else if ( gmo instanceof Surface ) {
127 CurveSegment[] cs = new CurveSegment[] { this };
128 inter = LinearIntersects.intersects( new CurveImpl( cs ), (Surface)gmo );
129 } else if ( gmo instanceof MultiPrimitive ) {
130 inter = intersectsMultiPrimitive( (MultiPrimitive)gmo );
131 }
132 } catch ( Exception e ) {
133 LOG.logError( "", e );
134 }
135
136 return inter;
137 }
138
139 /**
140 * the operations returns true if the submitted multi primitive intersects
141 * with the curve segment
142 */
143 private boolean intersectsMultiPrimitive( MultiPrimitive mprim ) throws Exception {
144 boolean inter = false;
145
146 int cnt = mprim.getSize();
147
148 for ( int i = 0; i < cnt; i++ ) {
149 if ( intersects( mprim.getPrimitiveAt( i ) ) ) {
150 inter = true;
151 break;
152 }
153 }
154
155 return inter;
156 }
157
158 /**
159 * The Boolean valued operation "contains" shall return TRUE if this Geometry
160 * contains another Geometry.
161 */
162 public boolean contains( Geometry gmo ) {
163 return false;
164 }
165 } /* ********************************************************************
166 Changes to this class. What the people have been up to:
167 $Log$
168 Revision 1.9 2007/02/22 11:24:19 poth
169 support for tolerance added form some topological operations
170
171 Revision 1.8 2006/07/12 14:46:15 poth
172 comment footer added
173
174 ********************************************************************** */