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