Quick Search:

View

Revision:

Diff

Diff from 48 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/HibernateSpatial/trunk/hibernate-spatial-jtsm/src/main/java/org/hibernatespatial/mgeom/MCoordinate.java

Annotated File View

maesenka
42
1 /**
2  * $Id: MCoordinate.java 48 2007-10-29 19:24:37Z maesenka $
3  *
4  * This file is part of Hibernate Spatial, an extension to the 
5  * hibernate ORM solution for geographic data. 
6  *  
7  * Copyright © 2007 Geovise BVBA
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  *
23  * For more information, visit: http://www.hibernatespatial.com/
24  */
25 package org.hibernatespatial.mgeom;
26
27 import com.vividsolutions.jts.geom.Coordinate;
28 import com.vividsolutions.jts.geom.CoordinateSequence;
29
30 /**
31  * This coordinate class supports 4D coordinates, where the first 3 measures
32  * (x,y,z) are coordinates in a 3 dimensional space (cartesian for example), and
33  * the fourth is a measure value used for linear referencing. Note that the
34  * measure value is independent of whether the (x,y,z) values are used. For
maesenka
48
35  * example, the z value can not be used while the measure value is used. <p/>
maesenka
42
36  * While this class extends the Coordinate class, it can be used seamlessly as a
37  * substitute in the event that the Measure value is not used. In these cases
38  * the Measure value shall simply be Double.NaN
39  * 
40  * @see com.vividsolutions.jts.geom.Coordinate
41  */
42 public class MCoordinate extends Coordinate {
43         /**
44          * 
45          */
46         private static final long serialVersionUID = 1L;
47
48         public double m;
49
50         /**
51          * Default constructor
52          */
53         public MCoordinate() {
54                 super();
55                 this.m = Double.NaN;
56         }
57
58         public MCoordinate(double xdouble ydouble zdouble m) {
59                 super(xyz);
60                 this.m = m;
61         }
62
63         public MCoordinate(double xdouble y) {
64                 super(xy);
65                 m = Double.NaN;
66         }
67
68         public MCoordinate(Coordinate coord) {
69                 super(coord);
70                 if (coord instanceof MCoordinate)
71                         m = ((MCoordinatecoord).m;
72                 else
73                         m = Double.NaN;
74         }
75
76         public MCoordinate(MCoordinate coord) {
77                 super(coord);
78                 m = coord.m;
79         }
80
81         /**
82          * TODO: I'd like to see this method added to the base Coordinate class
83          * Returns the ordinate value specified in this Coordinate instance. The
84          * index of the desired ordinates are specified in the CoordinateSequence
85          * class; hence CoodinateSequence.X returns the x ordinate,
86          * CoodinateSequence.Y the y ordinate, CoodinateSequence.Z the z ordinate,
87          * and CoodinateSequence.M the m ordinate. Note that the dimension may not
88          * imply the desired ordinate in the case where one is using a 2 dimensional
89          * geometry with a measure value. Therefore, these constants are highly
90          * recommended.
91          * 
92          * @param ordinateIndex
93          *            the desired ordinate index.
94          * @return the value of stored in the ordinate index. Incorrect or unused
95          *         indexes shall return Double.NaN
96          */
97         public double getOrdinate(int ordinateIndex) {
98                 switch (ordinateIndex) {
99                 case CoordinateSequence.X:
100                         return this.x;
101                 case CoordinateSequence.Y:
102                         return this.y;
103                 case CoordinateSequence.Z:
104                         return this.z;
105                 case CoordinateSequence.M:
106                         return this.m;
107                 }
108                 return Double.NaN;
109         }
110
111         /**
112          * TODO: I'd like to see this method added to the base Coordinate class Sets
113          * the value for a given ordinate. This should be specified using the
114          * CoordinateSequence ordinate index constants.
115          * 
116          * @param ordinateIndex
117          *            the desired ordinate index.
118          * @param value
119          *            the new ordinate value
120          * @throws IllegalArgumentException
121          *             if the ordinateIndex value is incorrect
122          * @see #getOrdinate(int)
123          */
124         public void setOrdinate(int ordinateIndexdouble value) {
125                 switch (ordinateIndex) {
126                 case CoordinateSequence.X:
127                         this.x = value;
128                         break;
129                 case CoordinateSequence.Y:
130                         this.y = value;
131                         break;
132                 case CoordinateSequence.Z:
133                         this.z = value;
134                         break;
135                 case CoordinateSequence.M:
136                         this.m = value;
137                         break;
138                 default:
139                         throw new IllegalArgumentException("invalid ordinateIndex");
140                 }
141         }
142
143         public boolean equals2DWithMeasure(Coordinate other) {
144                 boolean result = this.equals2D(other);
145                 if (result) {
146                         MCoordinate mc = convertCoordinate(other);
147                         result = (Double.compare(this.mmc.m) == 0);
148                 }
149                 return result;
150         }
151
152         public boolean equals3DWithMeasure(Coordinate other) {
153                 boolean result = this.equals3D(other);
154                 if (result) {
155                         MCoordinate mc = convertCoordinate(other);
156                         result = (Double.compare(this.mmc.m) == 0);
157                 }
158                 return result;
159         }
160
maesenka
48
161         /*
162          * Default equality is now equality in 2D-plane. This is required to remain
163          * consistent with JTS.
164          * 
165          * TODO:check whether this method is still needed.
166          * 
167          * (non-Javadoc)
168          * 
169          * @see com.vividsolutions.jts.geom.Coordinate#equals(java.lang.Object)
170          */
maesenka
42
171         public boolean equals(Object other) {
maesenka
48
172                 if (other instanceof Coordinate) {
173                         return equals2D((Coordinateother);
maesenka
42
174                 } else {
175                         return false;
176                 }
177         }
178
179         public String toString() {
180                 return "(" + x + "," + y + "," + z + "," + " m=" + m + ")";
181         }
182
183         /**
184          * Converts a standard Coordinate instance to an MCoordinate instance. If
185          * coordinate is already an instance of an MCoordinate, then it is simply
186          * returned. In cases where it is converted, the measure value of the
187          * coordinate is initialized to Double.NaN.
188          * 
189          * @param coordinate
190          *            The coordinate to be converted
191          * @return an instance of MCoordinate corresponding to the
192          *         <code>coordinate</code> parameter
193          */
194         public static MCoordinate convertCoordinate(Coordinate coordinate) {
195                 if (coordinate == null)
196                         return null;
197                 if (coordinate instanceof MCoordinate)
198                         return (MCoordinatecoordinate;
199                 return new MCoordinate(coordinate);
200         }
201
202         /**
203          * A convenience method for creating a MCoordinate instance where there are
204          * only 2 coordinates and an lrs measure value. The z value of the
205          * coordinate shall be set to Double.NaN
206          * 
207          * @param x
208          *            the x coordinate value
209          * @param y
210          *            the y coordinate value
211          * @param m
212          *            the lrs measure value
213          * @return The constructed MCoordinate value
214          */
215         public static MCoordinate create2dWithMeasure(double xdouble ydouble m) {
216                 return new MCoordinate(xyDouble.NaNm);
217         }
218
219         /**
220          * A convenience method for creating a MCoordinate instance where there are
221          * only 2 coordinates and an lrs measure value. The z and m value of the
222          * coordinate shall be set to Double.NaN
223          * 
224          * @param x
225          *            the x coordinate value
226          * @param y
227          *            the y coordinate value
228          * @return The constructed MCoordinate value
229          */
230         public static MCoordinate create2d(double xdouble y) {
231                 return new MCoordinate(xyDouble.NaNDouble.NaN);
232         }
233
234         /**
235          * A convenience method for creating a MCoordinate instance where there are
236          * 3 coordinates and an lrs measure value.
237          * 
238          * @param x
239          *            the x coordinate value
240          * @param y
241          *            the y coordinate value
242          * @param z
243          *            the z coordinate value
244          * @param m
245          *            the lrs measure value
246          * @return The constructed MCoordinate value
247          */
248         public static MCoordinate create3dWithMeasure(double xdouble ydouble z,
249                         double m) {
250                 return new MCoordinate(xyzm);
251         }
252
253         /**
254          * A convenience method for creating a MCoordinate instance where there are
255          * 3 coordinates but no lrs measure value. The m value of the coordinate
256          * shall be set to Double.NaN
257          * 
258          * @param x
259          *            the x coordinate value
260          * @param y
261          *            the y coordinate value
262          * @param z
263          *            the z coordinate value
264          * @return The constructed MCoordinate value
265          */
266         public static MCoordinate create3d(double xdouble ydouble z) {
267                 return new MCoordinate(xyzDouble.NaN);
268         }
269 }
FishEye: Open Source License registered to Hibernate Spatial.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, Subversion, CVS & Perforce analysis. (Version:1.5.2 Build:build-298 2008-05-26 ) - Administration - Page generated 2010-09-08 06:54 +0200