root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / Geometry.java @ 34899
History | View | Annotate | Download (17.8 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.geom; |
29 |
|
30 |
import java.awt.Shape; |
31 |
import java.awt.geom.AffineTransform; |
32 |
import java.awt.geom.PathIterator; |
33 |
import java.awt.geom.Rectangle2D; |
34 |
import java.io.Serializable; |
35 |
|
36 |
import org.cresques.cts.ICoordTrans; |
37 |
|
38 |
import org.gvsig.fmap.geom.handler.Handler; |
39 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
40 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
41 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
42 |
import org.gvsig.fmap.geom.primitive.Envelope; |
43 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
44 |
import org.gvsig.fmap.geom.primitive.Point; |
45 |
import org.gvsig.fmap.geom.type.GeometryType; |
46 |
|
47 |
/**
|
48 |
* <p>
|
49 |
* This interface is equivalent to the GM_Object specified in <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012"
|
50 |
* >ISO 19107</a>. It is the root class of the geometric object taxonomy and
|
51 |
* supports interfaces common to all geographically referenced geometric
|
52 |
* objects.
|
53 |
* </p>
|
54 |
* <p>
|
55 |
* Geometry instances are sets of direct positions in a particular coordinate
|
56 |
* reference system. A Geometry can be regarded as an infinite set of points
|
57 |
* that satisfies the set operation interfaces for a set of direct positions.
|
58 |
* </p>
|
59 |
* <p>
|
60 |
* A geometric object shall be a combination of a coordinate geometry and a
|
61 |
* coordinate reference system. In all of the operations, all geometric
|
62 |
* calculations shall be done in the coordinate reference system of the first
|
63 |
* geometric object accessed, which is normally the object whose operation is
|
64 |
* being invoked. Returned objects shall be in the coordinate reference system
|
65 |
* in which the calculations are done unless explicitly stated otherwise.
|
66 |
* </p>
|
67 |
*
|
68 |
* @see <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012"
|
69 |
* >ISO 19107< /a>
|
70 |
*/
|
71 |
public interface Geometry extends Shape, Serializable, Comparable { |
72 |
|
73 |
/**
|
74 |
* Predefined geometry types in the model.
|
75 |
*/
|
76 |
public interface TYPES { |
77 |
|
78 |
/**
|
79 |
* Any geometry.
|
80 |
*/
|
81 |
|
82 |
public final static int GEOMETRY = 0; |
83 |
|
84 |
/**
|
85 |
* A geometric element that has zero dimensions and a location
|
86 |
* determinable by an ordered set of coordinates.
|
87 |
*/
|
88 |
public final static int POINT = 1; |
89 |
|
90 |
/**
|
91 |
* A straight or curved geometric element that is generated by a moving
|
92 |
* point and that has extension only along the path of the point.
|
93 |
*/
|
94 |
public final static int CURVE = 2; |
95 |
|
96 |
/**
|
97 |
* A closed plane figure bounded by straight lines.
|
98 |
*/
|
99 |
public final static int SURFACE = 3; |
100 |
|
101 |
/**
|
102 |
* Solids in 3D.
|
103 |
*/
|
104 |
public final static int SOLID = 4; |
105 |
|
106 |
/**
|
107 |
* Words, symbols and form of a written or printed work.
|
108 |
*/
|
109 |
public final static int TEXT = 5; |
110 |
|
111 |
/**
|
112 |
* A set that can contain points, lines and polygons. This is usual in
|
113 |
* <i>CAD</i> layers <i>(dxf, dgn, dwg)</i>.
|
114 |
*/
|
115 |
public final static int AGGREGATE = 6; |
116 |
/**
|
117 |
* A set of points.
|
118 |
*/
|
119 |
public final static int MULTIPOINT = 7; |
120 |
|
121 |
/**
|
122 |
* A set of lines.
|
123 |
*/
|
124 |
public final static int MULTICURVE = 8; |
125 |
|
126 |
/**
|
127 |
* A set of polygons.
|
128 |
*/
|
129 |
public final static int MULTISURFACE = 9; |
130 |
|
131 |
/**
|
132 |
* A set of solids.
|
133 |
*/
|
134 |
public final static int MULTISOLID = 10; |
135 |
|
136 |
/**
|
137 |
* A closed plane curve every point of which is equidistant from a fixed
|
138 |
* point within the curve.
|
139 |
*/
|
140 |
public final static int CIRCLE = 11; |
141 |
|
142 |
/**
|
143 |
* A continuous portion (as of a circle or ellipse) of a curved line.
|
144 |
*/
|
145 |
public final static int ARC = 12; |
146 |
|
147 |
/**
|
148 |
* A closed plane curve generated by a point moving in such a way that
|
149 |
* the sums of its distances from two fixed points is a constant : a
|
150 |
* plane section of a right circular cone that is a closed curve.
|
151 |
*/
|
152 |
public final static int ELLIPSE = 13; |
153 |
|
154 |
public final static int SPLINE = 14; |
155 |
|
156 |
public final static int ELLIPTICARC = 15; |
157 |
|
158 |
/**
|
159 |
* NO DATA geometry.
|
160 |
*/
|
161 |
public final static int NULL = 16; |
162 |
} |
163 |
|
164 |
public interface DIMENSIONS { |
165 |
public final static int X = 0; |
166 |
public final static int Y = 1; |
167 |
public final static int Z = 2; |
168 |
} |
169 |
|
170 |
/**
|
171 |
* The subtype of a geometry is related with the dimension of the geometry,
|
172 |
* that is a combination between the spatial dimension (2D, 2ZD, 3D) and the
|
173 |
* M coordinate or "measure".
|
174 |
*
|
175 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
176 |
*/
|
177 |
public interface SUBTYPES { |
178 |
|
179 |
/**
|
180 |
* Geometries with two dimensions.
|
181 |
*/
|
182 |
public final static int GEOM2D = 0; |
183 |
|
184 |
/**
|
185 |
* Geometries with three dimensions.
|
186 |
*/
|
187 |
public final static int GEOM3D = 1; |
188 |
|
189 |
/**
|
190 |
* Geometries with two dimensions and with the M coordinate.
|
191 |
*/
|
192 |
public final static int GEOM2DM = 2; |
193 |
|
194 |
/**
|
195 |
* Geometries with three dimensions and with the M coordinate.
|
196 |
*/
|
197 |
public final static int GEOM3DM = 3; |
198 |
|
199 |
/**
|
200 |
* The subtype us unknown.
|
201 |
*/
|
202 |
public final static int UNKNOWN = 4; |
203 |
} |
204 |
|
205 |
/**
|
206 |
* Initial value for new geometry types (it must not overlap with the basic
|
207 |
* ones defined in TYPES).
|
208 |
*/
|
209 |
public static final int EXTENDED_GEOMTYPE_OFFSET = 17; |
210 |
|
211 |
/**
|
212 |
* Initial value for new geometry subtypes (it must not overlap with the
|
213 |
* basic ones defined in SUBTYPES).
|
214 |
*/
|
215 |
public static final int EXTENDED_GEOMSUBTYPE_OFFSET = 6; |
216 |
|
217 |
public interface OPERATIONS { |
218 |
public final static String CONVERTTOWKT = "toWKT"; |
219 |
public final static String CONVERTTOWKB = "toWKB"; |
220 |
public final static String BUFFER = "buffer"; |
221 |
public final static String DISTANCE = "Distance"; |
222 |
public final static String CONTAINS = "Contains"; |
223 |
public final static String OVERLAPS = "OVERLAPS"; |
224 |
public final static String CONVEXHULL = "ConvexHull"; |
225 |
public final static String COVERS = "Covers"; |
226 |
public final static String CROSSES = "Crosses"; |
227 |
public final static String DIFFERENCE = "Difference"; |
228 |
public final static String DISJOIN = "Disjoin"; |
229 |
public final static String INTERSECTION = "Intersaction"; |
230 |
public final static String INTERSECTS = "Intersects"; |
231 |
public final static String TOUCHES = "Touches"; |
232 |
public final static String UNION = "Union"; |
233 |
public final static String WITHIN = "Within"; |
234 |
public final static String COVEREDBY = "CoveredBy"; |
235 |
} |
236 |
|
237 |
public static int BEST = 0; |
238 |
/**
|
239 |
* North.
|
240 |
*/
|
241 |
public static int N = 1; |
242 |
|
243 |
/**
|
244 |
* North - East.
|
245 |
*/
|
246 |
public static int NE = 2; |
247 |
|
248 |
/**
|
249 |
* East.
|
250 |
*/
|
251 |
public static int E = 3; |
252 |
|
253 |
/**
|
254 |
* South - East.
|
255 |
*/
|
256 |
public static int SE = 4; |
257 |
|
258 |
/**
|
259 |
* South.
|
260 |
*/
|
261 |
public static int S = 5; |
262 |
|
263 |
/**
|
264 |
* South - West.
|
265 |
*/
|
266 |
public static int SW = 6; |
267 |
|
268 |
/**
|
269 |
* West.
|
270 |
*/
|
271 |
public static int W = 7; |
272 |
|
273 |
/**
|
274 |
* North - West.
|
275 |
*/
|
276 |
public static int NW = 8; |
277 |
|
278 |
public static int SELECTHANDLER = 0; |
279 |
public static int STRETCHINGHANDLER = 1; |
280 |
|
281 |
/**
|
282 |
* If this geometry is a predefined interface then this method returns one
|
283 |
* of {@link Geometry.TYPES} contants.<br>
|
284 |
* If this geometry is an extended type then this method returns a runtime
|
285 |
* constant that identifies its type. By convention this value is stored in
|
286 |
* a constant called .CODE within the geometry class, for instance:
|
287 |
* Point2D.CODE.
|
288 |
*
|
289 |
* @return If this geometry is a predefined interface then one of
|
290 |
* {@link Geometry.TYPES} or a runtime constant if it is an extended
|
291 |
* type.
|
292 |
*/
|
293 |
public int getType(); |
294 |
|
295 |
/**
|
296 |
* Creates a clone of this geometry.
|
297 |
*
|
298 |
* @return A clone of this geometry.
|
299 |
*/
|
300 |
public Geometry cloneGeometry();
|
301 |
|
302 |
/**
|
303 |
* Returns true if this geometry intersects the rectangle passed as
|
304 |
* parameter.
|
305 |
*
|
306 |
* @param r
|
307 |
* Rectangle.
|
308 |
*
|
309 |
* @return True, if <code>this</code> intersects <code>r</code>.
|
310 |
*/
|
311 |
public boolean intersects(Rectangle2D r); |
312 |
|
313 |
/**
|
314 |
* Used by the drawing strategies to quickly test whether this geometry
|
315 |
* intersects with the visible rectangle.
|
316 |
*
|
317 |
* @param x
|
318 |
* The minimum X coordinate.
|
319 |
* @param y
|
320 |
* The minimum Y coordinate.
|
321 |
* @param w
|
322 |
* The width of the envelope.
|
323 |
* @param h
|
324 |
* The height of the envelope.
|
325 |
* @return true if <code>this</code> intersects the rectangle defined by the
|
326 |
* parameters.
|
327 |
*/
|
328 |
public boolean fastIntersects(double x, double y, double w, double h); |
329 |
|
330 |
/**
|
331 |
* Returns this geometry's boundary rectangle.
|
332 |
*
|
333 |
* @deprecated use getEnvelope.
|
334 |
* @return Boundary rectangle.
|
335 |
*/
|
336 |
public Rectangle2D getBounds2D(); |
337 |
|
338 |
/**
|
339 |
* <p>
|
340 |
* Returns the minimum bounding box for this Geometry. This shall be the
|
341 |
* coordinate region spanning the minimum and maximum value for each
|
342 |
* ordinate taken on by DirectPositions in this Geometry. The simplest
|
343 |
* representation for an envelope consists of two DirectPositions, the first
|
344 |
* one containing all the minimums for each ordinate, and second one
|
345 |
* containing all the maximums.
|
346 |
* </p>
|
347 |
*
|
348 |
* @return The minimum bounding box for this Geometry.
|
349 |
*/
|
350 |
public Envelope getEnvelope();
|
351 |
|
352 |
/**
|
353 |
* Reprojects this geometry by the coordinate transformer passed as
|
354 |
* parameter.
|
355 |
*
|
356 |
* @param ct
|
357 |
* Coordinate Transformer.
|
358 |
*/
|
359 |
public void reProject(ICoordTrans ct); |
360 |
|
361 |
/**
|
362 |
* If applies an affine transformation and returns the GeneralPathXIterator
|
363 |
* with this geometry's information.
|
364 |
*
|
365 |
* @param at
|
366 |
* The transformation to apply.
|
367 |
* @return The GeneralPathXIterator with this geometry's information.
|
368 |
*/
|
369 |
public PathIterator getPathIterator(AffineTransform at); |
370 |
|
371 |
/**
|
372 |
* It returns the handlers of the geometry, these they can be of two types
|
373 |
* is straightening and of selection.
|
374 |
*
|
375 |
* @param type
|
376 |
* Type of handlers.
|
377 |
*
|
378 |
* @return The handlers.
|
379 |
*/
|
380 |
public Handler[] getHandlers(int type); |
381 |
|
382 |
/**
|
383 |
* It applies an affine transformation to the geometry.
|
384 |
*
|
385 |
* @param at
|
386 |
* The transformation to apply.
|
387 |
*/
|
388 |
public void transform(AffineTransform at); |
389 |
|
390 |
/**
|
391 |
* If applies an affine transformation and returns the GeneralPathXIterator
|
392 |
* with this geometry's information.
|
393 |
*
|
394 |
* @param at
|
395 |
* The affine transformation.
|
396 |
* @param flatness
|
397 |
*
|
398 |
* @return The GeneralPathXIterator with this geometry's information.
|
399 |
*/
|
400 |
PathIterator getPathIterator(AffineTransform at, double flatness); |
401 |
|
402 |
/**
|
403 |
* Useful to have the real shape behind the scenes. May be uses to edit it
|
404 |
* knowing it it is a Circle, Ellipse, etc.
|
405 |
*
|
406 |
* @return The awt shape
|
407 |
*/
|
408 |
public Shape getInternalShape(); |
409 |
|
410 |
/**
|
411 |
* Returns the largest number n such that each direct position in a
|
412 |
* geometric set can be associated with a subset that has the direct
|
413 |
* position in its interior and is similar (isomorphic) to Rn, Euclidean
|
414 |
* n-space.
|
415 |
*
|
416 |
* @return The dimension.
|
417 |
*/
|
418 |
public int getDimension(); |
419 |
|
420 |
/**
|
421 |
* Returns <code>true</code> if this Geometry has no interior point of
|
422 |
* self-intersection or self-tangency. In mathematical formalisms, this
|
423 |
* means that every point in the interior of the object must have a metric
|
424 |
* neighborhood whose intersection with the object is isomorphic to an
|
425 |
* n-sphere, where n is the dimension of this Geometry.
|
426 |
*
|
427 |
* @return If the geometry is simple.
|
428 |
*/
|
429 |
public boolean isSimple(); |
430 |
|
431 |
/**
|
432 |
* Invokes a geometry operation given its index and context.
|
433 |
*
|
434 |
* @param index
|
435 |
* Unique index of the operation. Operation code.
|
436 |
* @param ctx
|
437 |
* The context of the geometry operation.
|
438 |
* @return Object returned by the operation.
|
439 |
* @throws GeometryOperationNotSupportedException
|
440 |
* It is thrown when the operation has been not registered for
|
441 |
* this geometry.
|
442 |
* @throws GeometryOperationException
|
443 |
* It is thrown when there is an error executing the operation.
|
444 |
*/
|
445 |
public Object invokeOperation(int index, GeometryOperationContext ctx) |
446 |
throws GeometryOperationNotSupportedException,
|
447 |
GeometryOperationException; |
448 |
|
449 |
/**
|
450 |
* Invokes a geometry operation given its name and context.
|
451 |
*
|
452 |
* @param opName
|
453 |
* Operation name.
|
454 |
* @param ctx
|
455 |
* The context of the geometry operation.
|
456 |
* @return Object returned by the operation.
|
457 |
* @throws GeometryOperationNotSupportedException
|
458 |
* It is thrown when the operation has been not registered for
|
459 |
* this geometry.
|
460 |
* @throws GeometryOperationException
|
461 |
* It is thrown when there is an error executing the operation.
|
462 |
*/
|
463 |
public Object invokeOperation(String opName, GeometryOperationContext ctx) |
464 |
throws GeometryOperationNotSupportedException,
|
465 |
GeometryOperationException; |
466 |
|
467 |
/**
|
468 |
* Instance of the GeometryType associated to this geometry.
|
469 |
*
|
470 |
* @return The geometry type.
|
471 |
*/
|
472 |
public GeometryType getGeometryType();
|
473 |
|
474 |
/**
|
475 |
* Get GeneralPathIterator, to do registered operations to it.
|
476 |
*
|
477 |
* @return The GeneralPathX.
|
478 |
*/
|
479 |
public GeneralPathX getGeneralPath();
|
480 |
|
481 |
/**
|
482 |
* Return a byte array with the equivalent in WKB format of the Geometry.
|
483 |
*
|
484 |
* Utility method to wrap the invocation to the operation
|
485 |
* {@link OPERATIONS#CONVERTTOWKB}.
|
486 |
*
|
487 |
* @return the WKB version of the geometry
|
488 |
*/
|
489 |
public byte[] convertToWKB() throws GeometryOperationNotSupportedException, |
490 |
GeometryOperationException; |
491 |
|
492 |
/**
|
493 |
* Return a string with the equivalent in WKT format of the Geometry.
|
494 |
*
|
495 |
* This is a utility method to wrap the invocation to the operation
|
496 |
* {@link OPERATIONS#CONVERTTOWKT}.
|
497 |
*
|
498 |
* @return the WKT version of the geometry.
|
499 |
*
|
500 |
* @throws GeometryOperationNotSupportedException
|
501 |
* @throws GeometryOperationException
|
502 |
*/
|
503 |
public String convertToWKT() throws GeometryOperationNotSupportedException, |
504 |
GeometryOperationException; |
505 |
|
506 |
/**
|
507 |
* Computes a buffer area around this geometry having the given width
|
508 |
*
|
509 |
* This is a utility method to wrap the invocation to the operation
|
510 |
* {@link OPERATIONS#BUFFER}.
|
511 |
*
|
512 |
* @param distance
|
513 |
* the width of the buffer
|
514 |
*
|
515 |
* @return a new Geometry with the computed buffer.
|
516 |
*
|
517 |
* @throws GeometryOperationNotSupportedException
|
518 |
* @throws GeometryOperationException
|
519 |
*/
|
520 |
public Geometry buffer(double distance) |
521 |
throws GeometryOperationNotSupportedException,
|
522 |
GeometryOperationException; |
523 |
|
524 |
/**
|
525 |
* Tests whether this geometry contains the specified geometry.
|
526 |
*
|
527 |
* This is a utility method to wrap the invocation to the operation
|
528 |
* {@link OPERATIONS#CONTAINS}.
|
529 |
*
|
530 |
* @param geometry
|
531 |
* the Geometry with which to compare this Geometry
|
532 |
*
|
533 |
* @return if this Geometry contains the specified geometry
|
534 |
*
|
535 |
* @throws GeometryOperationNotSupportedException
|
536 |
* @throws GeometryOperationException
|
537 |
*/
|
538 |
public boolean contains(Geometry geometry) |
539 |
throws GeometryOperationNotSupportedException,
|
540 |
GeometryOperationException; |
541 |
|
542 |
/**
|
543 |
* Returns the minimum distance between this Geometry and the specified
|
544 |
* geometry.
|
545 |
*
|
546 |
* This is a utility method to wrap the invocation to the operation
|
547 |
* {@link OPERATIONS#DISTANCE}.
|
548 |
*
|
549 |
* @param geometry
|
550 |
* the Geometry from which to compute the distance
|
551 |
*
|
552 |
* @return the distance between the geometries
|
553 |
*
|
554 |
* @throws GeometryOperationNotSupportedException
|
555 |
* @throws GeometryOperationException
|
556 |
*/
|
557 |
public double distance(Geometry geometry) |
558 |
throws GeometryOperationNotSupportedException,
|
559 |
GeometryOperationException; |
560 |
|
561 |
/**
|
562 |
* Tests whether this geometry overlaps the specified geometry.
|
563 |
*
|
564 |
* This is a utility method to wrap the invocation to the operation
|
565 |
* {@link OPERATIONS#OVERLAPS}.
|
566 |
*
|
567 |
* @param geometry
|
568 |
* the Geometry with which to compare this Geometry
|
569 |
*
|
570 |
* @return true if the two geometries overlap.
|
571 |
*
|
572 |
* @throws GeometryOperationNotSupportedException
|
573 |
* @throws GeometryOperationException
|
574 |
*/
|
575 |
public boolean overlaps(Geometry geometry) |
576 |
throws GeometryOperationNotSupportedException,
|
577 |
GeometryOperationException; |
578 |
|
579 |
public Geometry convexHull() throws GeometryOperationNotSupportedException, |
580 |
GeometryOperationException; |
581 |
|
582 |
public boolean coveredBy(Geometry geometry) |
583 |
throws GeometryOperationNotSupportedException,
|
584 |
GeometryOperationException; |
585 |
|
586 |
public boolean crosses(Geometry geometry) |
587 |
throws GeometryOperationNotSupportedException,
|
588 |
GeometryOperationException; |
589 |
|
590 |
public Geometry difference(Geometry other)
|
591 |
throws GeometryOperationNotSupportedException,
|
592 |
GeometryOperationException; |
593 |
|
594 |
public boolean disjoint(Geometry geometry) |
595 |
throws GeometryOperationNotSupportedException,
|
596 |
GeometryOperationException; |
597 |
|
598 |
public Geometry intersection(Geometry other)
|
599 |
throws GeometryOperationNotSupportedException,
|
600 |
GeometryOperationException; |
601 |
|
602 |
public boolean intersects(Geometry geometry) |
603 |
throws GeometryOperationNotSupportedException,
|
604 |
GeometryOperationException; |
605 |
|
606 |
public boolean touches(Geometry geometry) |
607 |
throws GeometryOperationNotSupportedException,
|
608 |
GeometryOperationException; |
609 |
|
610 |
public Geometry union(Geometry other)
|
611 |
throws GeometryOperationNotSupportedException,
|
612 |
GeometryOperationException; |
613 |
|
614 |
public boolean within(Geometry geometry) |
615 |
throws GeometryOperationNotSupportedException,
|
616 |
GeometryOperationException; |
617 |
|
618 |
public Point centroid() throws GeometryOperationNotSupportedException, GeometryOperationException; |
619 |
|
620 |
public double area() throws GeometryOperationNotSupportedException, GeometryOperationException; |
621 |
|
622 |
public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException; |
623 |
} |