svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / primitive / point / Point3DM.java @ 44298
History | View | Annotate | Download (8.07 KB)
1 | 42260 | fdiaz | /* gvSIG. Desktop Geographic Information System.
|
---|---|---|---|
2 | *
|
||
3 | * Copyright ? 2007-2015 gvSIG Association
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
18 | * MA 02110-1301, USA.
|
||
19 | *
|
||
20 | * For any additional information, do not hesitate to contact us
|
||
21 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
22 | */
|
||
23 | package org.gvsig.fmap.geom.jts.primitive.point; |
||
24 | |||
25 | 42267 | fdiaz | import java.awt.geom.AffineTransform; |
26 | import java.awt.geom.PathIterator; |
||
27 | |||
28 | 42260 | fdiaz | import com.vividsolutions.jts.geom.Coordinate; |
29 | 44099 | jjdelcerro | import org.cresques.cts.IProjection; |
30 | 42260 | fdiaz | |
31 | import org.gvsig.fmap.geom.Geometry; |
||
32 | 42269 | fdiaz | import org.gvsig.fmap.geom.GeometryException; |
33 | 42260 | fdiaz | import org.gvsig.fmap.geom.GeometryLocator; |
34 | 42269 | fdiaz | import org.gvsig.fmap.geom.aggregate.MultiPoint; |
35 | 42260 | fdiaz | import org.gvsig.fmap.geom.jts.MCoordinate; |
36 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3DM; |
37 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
38 | import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator; |
||
39 | import org.gvsig.fmap.geom.jts.util.JTSUtils; |
||
40 | 42441 | fdiaz | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
41 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
42 | 42267 | fdiaz | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
43 | 43078 | jjdelcerro | import org.gvsig.fmap.geom.primitive.Point; |
44 | 42260 | fdiaz | import org.gvsig.fmap.geom.type.GeometryType; |
45 | |||
46 | /**
|
||
47 | * @author fdiaz
|
||
48 | *
|
||
49 | */
|
||
50 | public class Point3DM extends AbstractPoint { |
||
51 | |||
52 | /**
|
||
53 | *
|
||
54 | */
|
||
55 | private static final long serialVersionUID = 5749444180040735731L; |
||
56 | |||
57 | /**
|
||
58 | *
|
||
59 | */
|
||
60 | 44099 | jjdelcerro | public Point3DM(IProjection proj, Coordinate coordinates) {
|
61 | 42361 | fdiaz | super(Geometry.SUBTYPES.GEOM3DM, MCoordinate.convertCoordinate(coordinates));
|
62 | 42260 | fdiaz | } |
63 | |||
64 | /**
|
||
65 | *
|
||
66 | */
|
||
67 | public Point3DM() {
|
||
68 | 44099 | jjdelcerro | this(null, JTSUtils.createMCoordinate(0, 0, 0, 0)); |
69 | 42260 | fdiaz | } |
70 | |||
71 | /**
|
||
72 | *
|
||
73 | */
|
||
74 | public Point3DM(double x, double y, double z, double m) { |
||
75 | 44099 | jjdelcerro | this(null, JTSUtils.createMCoordinate(x, y, z, m)); |
76 | 42260 | fdiaz | } |
77 | |||
78 | 42267 | fdiaz | public double getZ() { |
79 | return this.coordinate.z; |
||
80 | } |
||
81 | |||
82 | 42260 | fdiaz | public double getM() { |
83 | 42361 | fdiaz | return ((org.hibernate.spatial.jts.mgeom.MCoordinate) this.coordinate).m; |
84 | 42260 | fdiaz | } |
85 | |||
86 | 42267 | fdiaz | /*
|
87 | * (non-Javadoc)
|
||
88 | *
|
||
89 | 42260 | fdiaz | * @see org.gvsig.fmap.geom.Geometry#getDimension()
|
90 | */
|
||
91 | public int getDimension() { |
||
92 | return 4; |
||
93 | } |
||
94 | |||
95 | 42267 | fdiaz | /*
|
96 | * (non-Javadoc)
|
||
97 | *
|
||
98 | 42260 | fdiaz | * @see org.gvsig.fmap.geom.Geometry#getGeometryType()
|
99 | */
|
||
100 | public GeometryType getGeometryType() {
|
||
101 | try {
|
||
102 | 42267 | fdiaz | return GeometryLocator.getGeometryManager()
|
103 | .getGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3DM); |
||
104 | 42260 | fdiaz | } catch (Exception e) { |
105 | return null; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | 42267 | fdiaz | /*
|
110 | * (non-Javadoc)
|
||
111 | *
|
||
112 | 42260 | fdiaz | * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
113 | */
|
||
114 | 44040 | jjdelcerro | public Point cloneGeometry() { |
115 | 44099 | jjdelcerro | return new Point3DM(this.getProjection(), MCoordinate.convertCoordinate((Coordinate) coordinate.clone())); |
116 | 42260 | fdiaz | } |
117 | |||
118 | 42267 | fdiaz | /*
|
119 | * (non-Javadoc)
|
||
120 | *
|
||
121 | 42260 | fdiaz | * @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
122 | */
|
||
123 | public boolean is3D() { |
||
124 | return true; |
||
125 | } |
||
126 | |||
127 | 42267 | fdiaz | /*
|
128 | * (non-Javadoc)
|
||
129 | *
|
||
130 | * @see
|
||
131 | * org.gvsig.fmap.geom.jts.primitive.point.PointJTS#setJTSCoordinate(com
|
||
132 | * .vividsolutions.jts.geom.Coordinate)
|
||
133 | 42260 | fdiaz | */
|
134 | public void setJTSCoordinate(Coordinate coordinate) { |
||
135 | this.coordinate = coordinate;
|
||
136 | } |
||
137 | |||
138 | 42267 | fdiaz | /*
|
139 | * (non-Javadoc)
|
||
140 | *
|
||
141 | * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
||
142 | */
|
||
143 | public GeneralPathX getGeneralPath() {
|
||
144 | return new DefaultGeneralPathX(new PointIterator(null), true, getZ()); |
||
145 | } |
||
146 | |||
147 | /*
|
||
148 | * (non-Javadoc)
|
||
149 | *
|
||
150 | * @see
|
||
151 | * org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
|
||
152 | * )
|
||
153 | */
|
||
154 | public PathIterator getPathIterator(AffineTransform at) { |
||
155 | PointIterator pi = new PointIterator(at);
|
||
156 | return pi;
|
||
157 | } |
||
158 | |||
159 | public class PointIterator extends GeneralPathXIterator { |
||
160 | |||
161 | /** Transform applied on the coordinates during iteration */
|
||
162 | private AffineTransform at; |
||
163 | |||
164 | /** True when the point has been read once */
|
||
165 | private boolean done; |
||
166 | |||
167 | /**
|
||
168 | * Creates a new PointIterator object.
|
||
169 | *
|
||
170 | * @param p
|
||
171 | * The polygon
|
||
172 | * @param at
|
||
173 | * The affine transform applied to coordinates during
|
||
174 | * iteration
|
||
175 | */
|
||
176 | public PointIterator(AffineTransform at) { |
||
177 | super(new GeneralPathX()); |
||
178 | if (at == null) { |
||
179 | at = new AffineTransform(); |
||
180 | } |
||
181 | |||
182 | this.at = at;
|
||
183 | done = false;
|
||
184 | } |
||
185 | |||
186 | /**
|
||
187 | * Return the winding rule for determining the interior of the path.
|
||
188 | *
|
||
189 | * @return <code>WIND_EVEN_ODD</code> by default.
|
||
190 | */
|
||
191 | public int getWindingRule() { |
||
192 | return PathIterator.WIND_EVEN_ODD; |
||
193 | } |
||
194 | |||
195 | /**
|
||
196 | * @see java.awt.geom.PathIterator#next()
|
||
197 | */
|
||
198 | public void next() { |
||
199 | done = true;
|
||
200 | } |
||
201 | |||
202 | /**
|
||
203 | * @see java.awt.geom.PathIterator#isDone()
|
||
204 | */
|
||
205 | public boolean isDone() { |
||
206 | return done;
|
||
207 | } |
||
208 | |||
209 | /**
|
||
210 | * @see java.awt.geom.PathIterator#currentSegment(double[])
|
||
211 | */
|
||
212 | public int currentSegment(double[] coords) { |
||
213 | coords[0] = getX();
|
||
214 | coords[1] = getY();
|
||
215 | coords[2] = getZ();
|
||
216 | at.transform(coords, 0, coords, 0, 1); |
||
217 | |||
218 | return PathIterator.SEG_MOVETO; |
||
219 | } |
||
220 | |||
221 | /*
|
||
222 | * (non-Javadoc)
|
||
223 | *
|
||
224 | * @see java.awt.geom.PathIterator#currentSegment(float[])
|
||
225 | */
|
||
226 | public int currentSegment(float[] coords) { |
||
227 | coords[0] = (float) getX(); |
||
228 | coords[1] = (float) getY(); |
||
229 | coords[2] = (float) getZ(); |
||
230 | |||
231 | at.transform(coords, 0, coords, 0, 1); |
||
232 | |||
233 | return PathIterator.SEG_MOVETO; |
||
234 | } |
||
235 | } |
||
236 | 42269 | fdiaz | |
237 | |||
238 | /* (non-Javadoc)
|
||
239 | * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
||
240 | */
|
||
241 | public MultiPoint toPoints() throws GeometryException { |
||
242 | MultiPoint multiPoint = new MultiPoint3DM();
|
||
243 | multiPoint.addPoint(this);
|
||
244 | return multiPoint;
|
||
245 | } |
||
246 | 42441 | fdiaz | |
247 | /* (non-Javadoc)
|
||
248 | * @see org.gvsig.fmap.geom.Geometry#offset(double)
|
||
249 | */
|
||
250 | public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
251 | 44099 | jjdelcerro | return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance)); |
252 | 42441 | fdiaz | } |
253 | 42813 | fdiaz | |
254 | public String toString() { |
||
255 | StringBuilder builder = new StringBuilder(); |
||
256 | builder.append("POINT ZM (");
|
||
257 | for( int i=0; i<this.getDimension()-1; i++) { |
||
258 | builder.append(this.getCoordinateAt(i));
|
||
259 | builder.append(" ");
|
||
260 | } |
||
261 | builder.append(this.getCoordinateAt(this.getDimension()-1)); |
||
262 | builder.append(")");
|
||
263 | return builder.toString();
|
||
264 | } |
||
265 | 43078 | jjdelcerro | |
266 | 42875 | fdiaz | @Override
|
267 | public boolean equals(Object obj) { |
||
268 | 44298 | omartinez | if( obj == null ) { |
269 | return false; |
||
270 | } |
||
271 | 43078 | jjdelcerro | Point other;
|
272 | try {
|
||
273 | other = (Point) obj;
|
||
274 | } catch(ClassCastException e) { |
||
275 | 42875 | fdiaz | return false; |
276 | } |
||
277 | 43078 | jjdelcerro | if( this.getGeometryType().getSubType() != other.getGeometryType().getSubType() ) { |
278 | return false; |
||
279 | } |
||
280 | if( this.coordinate.x != other.getX() ) { |
||
281 | return false; |
||
282 | } |
||
283 | if( this.coordinate.y != other.getY() ) { |
||
284 | return false; |
||
285 | } |
||
286 | if( this.coordinate.z != other.getCoordinateAt(2)) { |
||
287 | return false; |
||
288 | } |
||
289 | if( ((MCoordinate)this.coordinate).m != other.getCoordinateAt(3)) { |
||
290 | return false; |
||
291 | } |
||
292 | return true; |
||
293 | } |
||
294 | 42260 | fdiaz | } |