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