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 / AbstractPoint.java @ 42267
History | View | Annotate | Download (8.52 KB)
1 |
/* 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 |
import java.awt.Shape; |
26 |
import java.awt.geom.AffineTransform; |
27 |
import java.awt.geom.PathIterator; |
28 |
|
29 |
import org.cresques.cts.ICoordTrans; |
30 |
|
31 |
import org.gvsig.fmap.geom.DirectPosition; |
32 |
import org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.fmap.geom.GeometryException; |
34 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
35 |
import org.gvsig.fmap.geom.exception.ReprojectionRuntimeException; |
36 |
import org.gvsig.fmap.geom.handler.AbstractHandler; |
37 |
import org.gvsig.fmap.geom.handler.FinalHandler; |
38 |
import org.gvsig.fmap.geom.handler.Handler; |
39 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
40 |
import org.gvsig.fmap.geom.jts.primitive.AbstractPrimitive; |
41 |
import org.gvsig.fmap.geom.jts.primitive.Envelope2D; |
42 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
43 |
import org.gvsig.fmap.geom.primitive.Envelope; |
44 |
|
45 |
/**
|
46 |
* @author fdiaz
|
47 |
*
|
48 |
*/
|
49 |
public abstract class AbstractPoint extends AbstractPrimitive implements PointJTS { |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
private static final long serialVersionUID = -8378193151810866724L; |
55 |
protected com.vividsolutions.jts.geom.Coordinate coordinate;
|
56 |
|
57 |
/**
|
58 |
*
|
59 |
*/
|
60 |
protected AbstractPoint(int subtype) { |
61 |
super(Geometry.TYPES.POINT, subtype);
|
62 |
} |
63 |
|
64 |
/**
|
65 |
*
|
66 |
*/
|
67 |
public AbstractPoint(int subtype, com.vividsolutions.jts.geom.Coordinate coordinate) { |
68 |
this(subtype);
|
69 |
this.coordinate = coordinate;
|
70 |
} |
71 |
|
72 |
/*
|
73 |
* (non-Javadoc)
|
74 |
*
|
75 |
* @see org.gvsig.fmap.geom.primitive.Point#getDirectPosition()
|
76 |
*/
|
77 |
public DirectPosition getDirectPosition() {
|
78 |
return new PointDirectPosition(); |
79 |
} |
80 |
|
81 |
class PointDirectPosition implements DirectPosition { |
82 |
|
83 |
/*
|
84 |
* (non-Javadoc)
|
85 |
*
|
86 |
* @see org.gvsig.fmap.geom.DirectPosition#getDimension()
|
87 |
*/
|
88 |
public int getDimension() { |
89 |
return AbstractPoint.this.getDimension();
|
90 |
} |
91 |
|
92 |
/*
|
93 |
* (non-Javadoc)
|
94 |
*
|
95 |
* @see org.gvsig.fmap.geom.DirectPosition#getOrdinate(int)
|
96 |
*/
|
97 |
public double getOrdinate(int dimension) { |
98 |
return AbstractPoint.this.getCoordinateAt(dimension);
|
99 |
} |
100 |
|
101 |
} |
102 |
|
103 |
/*
|
104 |
* (non-Javadoc)
|
105 |
*
|
106 |
* @see org.gvsig.fmap.geom.primitive.Point#setCoordinateAt(int, double)
|
107 |
*/
|
108 |
public void setCoordinateAt(int dimension, double value) { |
109 |
this.coordinate.setOrdinate(dimension, value);
|
110 |
} |
111 |
|
112 |
/*
|
113 |
* (non-Javadoc)
|
114 |
*
|
115 |
* @see org.gvsig.fmap.geom.primitive.Point#setCoordinates(double[])
|
116 |
*/
|
117 |
public void setCoordinates(double[] values) { |
118 |
for (int i = 0; i < values.length; i++) { |
119 |
this.coordinate.setOrdinate(i, values[i]);
|
120 |
} |
121 |
} |
122 |
|
123 |
/*
|
124 |
* (non-Javadoc)
|
125 |
*
|
126 |
* @see org.gvsig.fmap.geom.primitive.Point#setX(double)
|
127 |
*/
|
128 |
public void setX(double x) { |
129 |
this.coordinate.x = x;
|
130 |
} |
131 |
|
132 |
/*
|
133 |
* (non-Javadoc)
|
134 |
*
|
135 |
* @see org.gvsig.fmap.geom.primitive.Point#setY(double)
|
136 |
*/
|
137 |
public void setY(double y) { |
138 |
this.coordinate.y = y;
|
139 |
} |
140 |
|
141 |
/*
|
142 |
* (non-Javadoc)
|
143 |
*
|
144 |
* @see org.gvsig.fmap.geom.primitive.Point#getCoordinateAt(int)
|
145 |
*/
|
146 |
public double getCoordinateAt(int dimension) { |
147 |
return this.coordinate.getOrdinate(dimension); |
148 |
} |
149 |
|
150 |
/*
|
151 |
* (non-Javadoc)
|
152 |
*
|
153 |
* @see org.gvsig.fmap.geom.primitive.Point#getCoordinates()
|
154 |
*/
|
155 |
public double[] getCoordinates() { |
156 |
double[] coords = new double[this.getDimension()]; |
157 |
for (int i = 0; i < this.getDimension(); i++) { |
158 |
coords[i] = this.coordinate.getOrdinate(i);
|
159 |
} |
160 |
return coords;
|
161 |
} |
162 |
|
163 |
/*
|
164 |
* (non-Javadoc)
|
165 |
*
|
166 |
* @see org.gvsig.fmap.geom.primitive.Point#getX()
|
167 |
*/
|
168 |
public double getX() { |
169 |
return this.coordinate.x; |
170 |
} |
171 |
|
172 |
/*
|
173 |
* (non-Javadoc)
|
174 |
*
|
175 |
* @see org.gvsig.fmap.geom.primitive.Point#getY()
|
176 |
*/
|
177 |
public double getY() { |
178 |
return this.coordinate.y; |
179 |
} |
180 |
|
181 |
/*
|
182 |
* (non-Javadoc)
|
183 |
*
|
184 |
* @see org.gvsig.fmap.geom.primitive.Point#toPoints()
|
185 |
*/
|
186 |
public MultiPoint toPoints() throws GeometryException { |
187 |
// FIXME: Cuando este disponible el Multipoint
|
188 |
// TODO Auto-generated method stub
|
189 |
return null; |
190 |
} |
191 |
|
192 |
/*
|
193 |
* (non-Javadoc)
|
194 |
*
|
195 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
196 |
*/
|
197 |
public com.vividsolutions.jts.geom.Geometry getJTS() {
|
198 |
return JTSUtils.factory.createPoint(this.coordinate); |
199 |
} |
200 |
|
201 |
/*
|
202 |
* (non-Javadoc)
|
203 |
*
|
204 |
* @see org.gvsig.fmap.geom.Geometry#reProject(org.cresques.cts.ICoordTrans)
|
205 |
*/
|
206 |
public void reProject(ICoordTrans ct) { |
207 |
if (ct == null) { |
208 |
return;
|
209 |
} |
210 |
java.awt.geom.Point2D p = new java.awt.geom.Point2D.Double(this.getX(), this.getY()); |
211 |
try {
|
212 |
p = ct.convert(p, p); |
213 |
this.setX(p.getX());
|
214 |
this.setY(p.getY());
|
215 |
} catch (Exception exc) { |
216 |
/*
|
217 |
* This can happen when the reprojection lib is unable
|
218 |
* to reproject (for example the source point
|
219 |
* is out of the valid range and some computing
|
220 |
* problem happens)
|
221 |
*/
|
222 |
throw new ReprojectionRuntimeException(ct.getPOrig(), ct.getPDest(), p, exc); |
223 |
} |
224 |
} |
225 |
|
226 |
/*
|
227 |
* (non-Javadoc)
|
228 |
*
|
229 |
* @see
|
230 |
* org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
|
231 |
*/
|
232 |
public void transform(AffineTransform at) { |
233 |
if (at == null) { |
234 |
return;
|
235 |
} |
236 |
|
237 |
double[] coordinates = getCoordinates(); |
238 |
at.transform(coordinates, 0, coordinates, 0, 1); |
239 |
setCoordinates(coordinates); |
240 |
} |
241 |
|
242 |
/*
|
243 |
* (non-Javadoc)
|
244 |
*
|
245 |
* @see org.gvsig.fmap.geom.jts.primitive.point.PointJTS#getJTSCoordinates()
|
246 |
*/
|
247 |
public com.vividsolutions.jts.geom.Coordinate getJTSCoordinate() {
|
248 |
return this.coordinate; |
249 |
} |
250 |
|
251 |
/*
|
252 |
* (non-Javadoc)
|
253 |
*
|
254 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
|
255 |
*/
|
256 |
public Shape getShape(AffineTransform affineTransform) { |
257 |
return new DefaultGeneralPathX(getPathIterator(affineTransform), false, 0); |
258 |
} |
259 |
|
260 |
/*
|
261 |
* (non-Javadoc)
|
262 |
*
|
263 |
* @see org.gvsig.fmap.geom.Geometry#getShape()
|
264 |
*/
|
265 |
public Shape getShape() { |
266 |
return new DefaultGeneralPathX(getPathIterator(null), false, 0); |
267 |
} |
268 |
|
269 |
/*
|
270 |
* (non-Javadoc)
|
271 |
*
|
272 |
* @see
|
273 |
* org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
|
274 |
* , double)
|
275 |
*/
|
276 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
277 |
return getPathIterator(at);
|
278 |
} |
279 |
|
280 |
/*
|
281 |
* (non-Javadoc)
|
282 |
*
|
283 |
* @see org.gvsig.fmap.geom.Geometry#getHandlers(int)
|
284 |
*/
|
285 |
public Handler[] getHandlers(int type) { |
286 |
return new Handler[] { new PointHandler() }; |
287 |
} |
288 |
|
289 |
class PointHandler extends AbstractHandler implements FinalHandler { |
290 |
|
291 |
public PointHandler() {
|
292 |
point = new java.awt.geom.Point2D.Double(AbstractPoint.this.getX(), AbstractPoint.this.getY());
|
293 |
index = 0;
|
294 |
} |
295 |
|
296 |
public void move(double movex, double movey) { |
297 |
AbstractPoint.this.setX(AbstractPoint.this.getX() + movex); |
298 |
AbstractPoint.this.setY(AbstractPoint.this.getY() + movey); |
299 |
} |
300 |
|
301 |
public void set(double setx, double sety) { |
302 |
AbstractPoint.this.setX(setx); |
303 |
AbstractPoint.this.setY(sety); |
304 |
} |
305 |
} |
306 |
|
307 |
public Envelope getEnvelope() {
|
308 |
// TOCRY: En alg?n momento habr? que probar qu? ocurre en gvSIG si esto
|
309 |
// devuelve lo que deber?a
|
310 |
return new Envelope2D(this.getX() - 0.01, this.getY() - 0.01, this.getX() + 0.02, this.getY() + 0.02); |
311 |
} |
312 |
} |