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 / surface / circle / AbstractCircle.java @ 43785
History | View | Annotate | Download (14.7 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.surface.circle; |
24 |
|
25 |
import java.awt.Shape; |
26 |
import java.awt.geom.AffineTransform; |
27 |
import java.awt.geom.PathIterator; |
28 |
|
29 |
import org.cresques.cts.CoordTransRuntimeException; |
30 |
import org.cresques.cts.ICoordTrans; |
31 |
|
32 |
import org.gvsig.fmap.geom.GeometryLocator; |
33 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
34 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
35 |
import org.gvsig.fmap.geom.jts.primitive.point.Point2D; |
36 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
37 |
import org.gvsig.fmap.geom.jts.primitive.surface.AbstractSurface; |
38 |
import org.gvsig.fmap.geom.jts.util.UtilFunctions; |
39 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
40 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
41 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
42 |
import org.gvsig.fmap.geom.primitive.Line; |
43 |
import org.gvsig.fmap.geom.primitive.Point; |
44 |
import org.gvsig.fmap.geom.primitive.Polygon; |
45 |
import org.gvsig.fmap.geom.primitive.Ring; |
46 |
import org.gvsig.tools.exception.BaseException; |
47 |
import org.gvsig.tools.locator.LocatorException; |
48 |
|
49 |
|
50 |
/**
|
51 |
* @author fdiaz
|
52 |
*
|
53 |
*/
|
54 |
public abstract class AbstractCircle extends AbstractSurface { |
55 |
|
56 |
/**
|
57 |
*
|
58 |
*/
|
59 |
private static final long serialVersionUID = -5509291843865895995L; |
60 |
|
61 |
protected Point center; |
62 |
protected double radius; |
63 |
|
64 |
/**
|
65 |
* @param type
|
66 |
* @param subtype
|
67 |
*/
|
68 |
public AbstractCircle(int type, int subtype) { |
69 |
super(type, subtype);
|
70 |
} |
71 |
|
72 |
/**
|
73 |
* @param type
|
74 |
* @param subtype
|
75 |
*/
|
76 |
protected AbstractCircle(int type, int subtype, Point center, double radius) { |
77 |
this(type, subtype);
|
78 |
this.setCenter(center);
|
79 |
this.setRadius(radius);
|
80 |
} |
81 |
|
82 |
|
83 |
/**
|
84 |
* @param initialPoint
|
85 |
* @return
|
86 |
*/
|
87 |
protected abstract Point fixPoint(Point point); |
88 |
|
89 |
/**
|
90 |
* @param center the center to set
|
91 |
*/
|
92 |
public void setCenter(Point center) { |
93 |
this.center = fixPoint(center);
|
94 |
} |
95 |
|
96 |
/* (non-Javadoc)
|
97 |
* @see org.gvsig.fmap.geom.primitive.Circle#getCenter()
|
98 |
*/
|
99 |
public Point getCenter() { |
100 |
return this.center; |
101 |
} |
102 |
|
103 |
/**
|
104 |
* @param radius the radius to set
|
105 |
*/
|
106 |
public void setRadius(double radius) { |
107 |
this.radius = radius;
|
108 |
} |
109 |
|
110 |
/* (non-Javadoc)
|
111 |
* @see org.gvsig.fmap.geom.primitive.Circle#getRadious()
|
112 |
*/
|
113 |
public double getRadious() { |
114 |
return this.radius; |
115 |
} |
116 |
|
117 |
/* (non-Javadoc)
|
118 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
119 |
*/
|
120 |
public int getDimension() { |
121 |
return this.center.getDimension(); |
122 |
} |
123 |
|
124 |
/* (non-Javadoc)
|
125 |
* @see org.gvsig.fmap.geom.Geometry#isSimple()
|
126 |
*/
|
127 |
public boolean isSimple() { |
128 |
return true; |
129 |
} |
130 |
|
131 |
/* (non-Javadoc)
|
132 |
* @see org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point)
|
133 |
*/
|
134 |
public void setPoints(Point center, Point radius) { |
135 |
setCenter(center); |
136 |
this.radius = ((PointJTS)radius).getJTSCoordinate().distance(((PointJTS)this.center).getJTSCoordinate()); |
137 |
} |
138 |
|
139 |
/* (non-Javadoc)
|
140 |
* @see org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive.Point, double)
|
141 |
*/
|
142 |
public void setPoints(Point center, double radius) { |
143 |
setCenter(center); |
144 |
this.radius = radius;
|
145 |
} |
146 |
|
147 |
/* (non-Javadoc)
|
148 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
149 |
*/
|
150 |
public boolean is3D() { |
151 |
return ((PointJTS)center).is3D();
|
152 |
} |
153 |
|
154 |
/* (non-Javadoc)
|
155 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getCoordinateAt(int, int)
|
156 |
*/
|
157 |
public double getCoordinateAt(int index, int dimension) { |
158 |
String message = "Calling deprecated method setPoints of a circle"; |
159 |
notifyDeprecated(message); |
160 |
throw new UnsupportedOperationException(message); |
161 |
} |
162 |
|
163 |
/* (non-Javadoc)
|
164 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setCoordinateAt(int, int, double)
|
165 |
*/
|
166 |
public void setCoordinateAt(int index, int dimension, double value) { |
167 |
String message = "Calling deprecated method setPoints of a circle"; |
168 |
notifyDeprecated(message); |
169 |
throw new UnsupportedOperationException(message); |
170 |
} |
171 |
|
172 |
/* (non-Javadoc)
|
173 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(org.gvsig.fmap.geom.primitive.Point)
|
174 |
*/
|
175 |
public void addVertex(Point point) { |
176 |
String message = "Calling deprecated method setPoints of a circle"; |
177 |
notifyDeprecated(message); |
178 |
throw new UnsupportedOperationException(message); |
179 |
} |
180 |
|
181 |
/* (non-Javadoc)
|
182 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double)
|
183 |
*/
|
184 |
public void addVertex(double x, double y) { |
185 |
String message = "Calling deprecated method setPoints of a circle"; |
186 |
notifyDeprecated(message); |
187 |
throw new UnsupportedOperationException(message); |
188 |
} |
189 |
|
190 |
/* (non-Javadoc)
|
191 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double, double)
|
192 |
*/
|
193 |
public void addVertex(double x, double y, double z) { |
194 |
String message = "Calling deprecated method setPoints of a circle"; |
195 |
notifyDeprecated(message); |
196 |
throw new UnsupportedOperationException(message); |
197 |
} |
198 |
|
199 |
/* (non-Javadoc)
|
200 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#removeVertex(int)
|
201 |
*/
|
202 |
public void removeVertex(int index) { |
203 |
String message = "Calling deprecated method setPoints of a circle"; |
204 |
notifyDeprecated(message); |
205 |
throw new UnsupportedOperationException(message); |
206 |
} |
207 |
|
208 |
/* (non-Javadoc)
|
209 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
|
210 |
*/
|
211 |
public Point getVertex(int index) { |
212 |
String message = "Calling deprecated method setPoints of a circle"; |
213 |
notifyDeprecated(message); |
214 |
throw new UnsupportedOperationException(message); |
215 |
} |
216 |
|
217 |
/* (non-Javadoc)
|
218 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getNumVertices()
|
219 |
*/
|
220 |
public int getNumVertices() { |
221 |
String message = "Calling deprecated method getNumVertices of a circle"; |
222 |
notifyDeprecated(message); |
223 |
throw new UnsupportedOperationException(message); |
224 |
} |
225 |
|
226 |
/* (non-Javadoc)
|
227 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#insertVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
228 |
*/
|
229 |
public void insertVertex(int index, Point p) { |
230 |
String message = "Calling deprecated method setPoints of a circle"; |
231 |
notifyDeprecated(message); |
232 |
throw new UnsupportedOperationException(message); |
233 |
} |
234 |
|
235 |
/* (non-Javadoc)
|
236 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
237 |
*/
|
238 |
public void setVertex(int index, Point p) { |
239 |
String message = "Calling deprecated method setPoints of a circle"; |
240 |
notifyDeprecated(message); |
241 |
throw new UnsupportedOperationException(message); |
242 |
} |
243 |
|
244 |
/* (non-Javadoc)
|
245 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
|
246 |
*/
|
247 |
public void setGeneralPath(GeneralPathX generalPathX) { |
248 |
String message = "Calling deprecated method setPoints of a circle"; |
249 |
notifyDeprecated(message); |
250 |
throw new UnsupportedOperationException(message); |
251 |
} |
252 |
|
253 |
/* (non-Javadoc)
|
254 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addMoveToVertex(org.gvsig.fmap.geom.primitive.Point)
|
255 |
*/
|
256 |
public void addMoveToVertex(Point point) { |
257 |
String message = "Calling deprecated method setPoints of a circle"; |
258 |
notifyDeprecated(message); |
259 |
throw new UnsupportedOperationException(message); |
260 |
} |
261 |
|
262 |
/* (non-Javadoc)
|
263 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#closePrimitive()
|
264 |
*/
|
265 |
public void closePrimitive() { |
266 |
String message = "Calling deprecated method setPoints of a circle"; |
267 |
notifyDeprecated(message); |
268 |
throw new UnsupportedOperationException(message); |
269 |
} |
270 |
|
271 |
/* (non-Javadoc)
|
272 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#ensureCapacity(int)
|
273 |
*/
|
274 |
public void ensureCapacity(int capacity) { |
275 |
String message = "Calling deprecated method ensureCapacity of a circle"; |
276 |
notifyDeprecated(message); |
277 |
throw new UnsupportedOperationException(message); |
278 |
} |
279 |
|
280 |
/* (non-Javadoc)
|
281 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
|
282 |
*/
|
283 |
public Shape getShape(AffineTransform affineTransform) { |
284 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
285 |
} |
286 |
|
287 |
/* (non-Javadoc)
|
288 |
* @see org.gvsig.fmap.geom.Geometry#getShape()
|
289 |
*/
|
290 |
public Shape getShape() { |
291 |
return getShape(null); |
292 |
} |
293 |
|
294 |
/* (non-Javadoc)
|
295 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform)
|
296 |
*/
|
297 |
public PathIterator getPathIterator(AffineTransform at) { |
298 |
return this.getPathIterator(at, getManager().getFlatness()); |
299 |
} |
300 |
|
301 |
/* (non-Javadoc)
|
302 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double)
|
303 |
*/
|
304 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
305 |
|
306 |
java.awt.geom.Point2D.Double center = new java.awt.geom.Point2D.Double(this.center.getX(), this.center.getY()); |
307 |
java.awt.geom.Arc2D arco = UtilFunctions.createCircle(center, radius); |
308 |
|
309 |
return arco.getPathIterator(at, flatness);
|
310 |
} |
311 |
|
312 |
/* (non-Javadoc)
|
313 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
314 |
*/
|
315 |
public GeneralPathX getGeneralPath() {
|
316 |
GeneralPathX gp = new DefaultGeneralPathX(getPathIterator(null, getManager().getFlatness()), is3D(), 0.0); |
317 |
return gp;
|
318 |
} |
319 |
|
320 |
/* (non-Javadoc)
|
321 |
* @see org.gvsig.fmap.geom.primitive.Surface#getNumInteriorRings()
|
322 |
*/
|
323 |
public int getNumInteriorRings() { |
324 |
String message = "Calling deprecated method getNumInteriorRings of a circle"; |
325 |
notifyDeprecated(message); |
326 |
throw new UnsupportedOperationException(message); |
327 |
} |
328 |
|
329 |
/* (non-Javadoc)
|
330 |
* @see org.gvsig.fmap.geom.primitive.Surface#getInteriorRing(int)
|
331 |
*/
|
332 |
public Ring getInteriorRing(int index) { |
333 |
String message = "Calling deprecated method getInteriorRing of a circle"; |
334 |
notifyDeprecated(message); |
335 |
throw new UnsupportedOperationException(message); |
336 |
} |
337 |
|
338 |
/* (non-Javadoc)
|
339 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Ring)
|
340 |
*/
|
341 |
public void addInteriorRing(Ring ring) { |
342 |
String message = "Calling deprecated method addInteriorRing of a circle"; |
343 |
notifyDeprecated(message); |
344 |
throw new UnsupportedOperationException(message); |
345 |
} |
346 |
|
347 |
/* (non-Javadoc)
|
348 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Line)
|
349 |
*/
|
350 |
public void addInteriorRing(Line ring) { |
351 |
String message = "Calling deprecated method addInteriorRing of a circle"; |
352 |
notifyDeprecated(message); |
353 |
throw new UnsupportedOperationException(message); |
354 |
} |
355 |
|
356 |
/* (non-Javadoc)
|
357 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Polygon)
|
358 |
*/
|
359 |
public void addInteriorRing(Polygon polygon) { |
360 |
String message = "Calling unsupported method addInteriorRing of a circle"; |
361 |
notifyDeprecated(message); |
362 |
throw new UnsupportedOperationException(message); |
363 |
} |
364 |
/* (non-Javadoc)
|
365 |
* @see org.gvsig.fmap.geom.primitive.Surface#removeInteriorRing(int)
|
366 |
*/
|
367 |
public void removeInteriorRing(int index) { |
368 |
String message = "Calling deprecated method removeInteriorRing of a circle"; |
369 |
notifyDeprecated(message); |
370 |
throw new UnsupportedOperationException(message); |
371 |
} |
372 |
|
373 |
/* (non-Javadoc)
|
374 |
* @see org.gvsig.fmap.geom.Geometry#reProject(org.cresques.cts.ICoordTrans)
|
375 |
*/
|
376 |
public void reProject(ICoordTrans ct) { |
377 |
//FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n, rotaci?n y escala
|
378 |
// Ser?a incorrecto para las de deformaci?n en cizallamiento
|
379 |
|
380 |
Point2D aux = new Point2D(center.getX(), center.getY()-radius); |
381 |
try {
|
382 |
center.reProject(ct); |
383 |
aux.reProject(ct); |
384 |
this.setProjection(ct.getPDest());
|
385 |
} catch (CoordTransRuntimeException e){
|
386 |
center.setX(0);
|
387 |
center.setY(0);
|
388 |
radius = 0;
|
389 |
return;
|
390 |
} |
391 |
try {
|
392 |
radius = center.distance(aux); |
393 |
} catch (BaseException e) {
|
394 |
throw new UnsupportedOperationException("Error calculating the radius of the transformed circle.", e); |
395 |
} |
396 |
} |
397 |
|
398 |
/* (non-Javadoc)
|
399 |
* @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
|
400 |
*/
|
401 |
public void transform(AffineTransform at) { |
402 |
//FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n, rotaci?n y escala
|
403 |
// Ser?a incorrecto para las de deformaci?n en cizallamiento
|
404 |
|
405 |
Point2D aux = new Point2D(center.getX(), center.getY()-radius); |
406 |
center.transform(at); |
407 |
aux.transform(at); |
408 |
try {
|
409 |
radius = center.distance(aux); |
410 |
} catch (BaseException e) {
|
411 |
throw new UnsupportedOperationException("Error calculating the radius of the transformed circle.", e); |
412 |
} |
413 |
|
414 |
} |
415 |
|
416 |
/* (non-Javadoc)
|
417 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#flip()
|
418 |
*/
|
419 |
public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
420 |
//FIXME: throw UnssupportedOperationException or do nothing?
|
421 |
// String message = "Can't flip a circle";
|
422 |
// notifyDeprecated(message);
|
423 |
// throw new UnsupportedOperationException(message);
|
424 |
} |
425 |
|
426 |
|
427 |
@Override
|
428 |
public boolean canBeTransformed(AffineTransform at) { |
429 |
return false; |
430 |
} |
431 |
|
432 |
@Override
|
433 |
public boolean canBeReprojected(ICoordTrans ct) { |
434 |
return false; |
435 |
} |
436 |
|
437 |
} |