Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / Geometry.java @ 32924

History | View | Annotate | Download (17.5 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
import org.gvsig.fmap.geom.handler.Handler;
38
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
39
import org.gvsig.fmap.geom.operation.GeometryOperationException;
40
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
41
import org.gvsig.fmap.geom.primitive.Envelope;
42
import org.gvsig.fmap.geom.primitive.GeneralPathX;
43
import org.gvsig.fmap.geom.type.GeometryType;
44

    
45
/**
46
 * <p>
47
 * 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"
48
 * >ISO 19107</a>. It is the root class of the geometric object taxonomy and
49
 * supports interfaces common to all geographically referenced geometric
50
 * objects.
51
 * </p>
52
 * <p>
53
 * Geometry instances are sets of direct positions in a particular coordinate
54
 * reference system. A Geometry can be regarded as an infinite set of points
55
 * that satisfies the set operation interfaces for a set of direct positions.
56
 * </p>
57
 * <p>
58
 * A geometric object shall be a combination of a coordinate geometry and a
59
 * coordinate reference system. In all of the operations, all geometric
60
 * calculations shall be done in the coordinate reference system of the first
61
 * geometric object accessed, which is normally the object whose operation is
62
 * being invoked. Returned objects shall be in the coordinate reference system
63
 * in which the calculations are done unless explicitly stated otherwise.
64
 * </p>
65
 * 
66
 * @see <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012"
67
 *      >ISO 19107< /a>
68
 */
69
public interface Geometry extends Shape, Serializable, Comparable {
70

    
71
        /**
72
         * Predefined geometry types in the model.
73
         */
74
        public interface TYPES {
75

    
76
                /**
77
                 * Any geometry.
78
                 */
79

    
80
                public final static int GEOMETRY = 0;
81

    
82
                /**
83
                 * A geometric element that has zero dimensions and a location
84
                 * determinable by an ordered set of coordinates.
85
                 */
86
                public final static int POINT = 1;
87

    
88
                /**
89
                 * A straight or curved geometric element that is generated by a moving
90
                 * point and that has extension only along the path of the point.
91
                 */
92
                public final static int CURVE = 2;
93

    
94
                /**
95
                 * A closed plane figure bounded by straight lines.
96
                 */
97
                public final static int SURFACE = 3;
98

    
99
                /**
100
                 * Solids in 3D.
101
                 */
102
                public final static int SOLID = 4;
103

    
104
                /**
105
                 * Words, symbols and form of a written or printed work.
106
                 */
107
                public final static int TEXT = 5;
108

    
109
                /**
110
                 * A set that can contain points, lines and polygons. This is usual in
111
                 * <i>CAD</i> layers <i>(dxf, dgn, dwg)</i>.
112
                 */
113
                public final static int AGGREGATE = 6;
114
                /**
115
                 * A set of points.
116
                 */
117
                public final static int MULTIPOINT = 7;
118

    
119
                /**
120
                 * A set of lines.
121
                 */
122
                public final static int MULTICURVE = 8;
123

    
124
                /**
125
                 * A set of polygons.
126
                 */
127
                public final static int MULTISURFACE = 9;
128

    
129
                /**
130
                 * A set of solids.
131
                 */
132
                public final static int MULTISOLID = 10;
133

    
134
                /**
135
                 * A closed plane curve every point of which is equidistant from a fixed
136
                 * point within the curve.
137
                 */
138
                public final static int CIRCLE = 11;
139

    
140
                /**
141
                 * A continuous portion (as of a circle or ellipse) of a curved line.
142
                 */
143
                public final static int ARC = 12;
144

    
145
                /**
146
                 * A closed plane curve generated by a point moving in such a way that
147
                 * the sums of its distances from two fixed points is a constant : a
148
                 * plane section of a right circular cone that is a closed curve.
149
                 */
150
                public final static int ELLIPSE = 13;
151

    
152
                public final static int SPLINE = 14;
153

    
154
                public final static int ELLIPTICARC = 15;
155

    
156
                /**
157
                 * NO DATA geometry.
158
                 */
159
                public final static int NULL = 16;
160
        }
161

    
162
        public interface DIMENSIONS {
163
                public final static int X = 0;
164
                public final static int Y = 1;
165
                public final static int Z = 2;
166
        }
167

    
168
        /**
169
         * The subtype of a geometry is related with the dimension of the geometry,
170
         * that is a combination between the spatial dimension (2D, 2ZD, 3D) and the
171
         * M coordinate or "measure".
172
         * 
173
         * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
174
         */
175
        public interface SUBTYPES {
176

    
177
                /**
178
                 * Geometries with two dimensions.
179
                 */
180
                public final static int GEOM2D = 0;
181

    
182
                /**
183
                 * Geometries with two dimensions and with a value for the elevation.
184
                 */
185
                public final static int GEOM2DZ = 1;
186

    
187
                /**
188
                 * Geometries with three dimensions.
189
                 */
190
                public final static int GEOM3D = 2;
191

    
192
                /**
193
                 * Geometries with two dimensions and with the M coordinate.
194
                 */
195
                public final static int GEOM2DM = 3;
196

    
197
                /**
198
                 * Geometries with three dimensions and with the M coordinate.
199
                 */
200
                public final static int GEOM3DM = 4;
201

    
202
                /**
203
                 * The subtype us unknown.
204
                 */
205
                public final static int UNKNOWN = 5;
206
        }
207

    
208
        /**
209
         * Initial value for new geometry types (it must not overlap with the basic
210
         * ones defined in TYPES).
211
         */
212
        public static final int EXTENDED_GEOMTYPE_OFFSET = 17;
213

    
214
        /**
215
         * Initial value for new geometry subtypes (it must not overlap with the
216
         * basic ones defined in SUBTYPES).
217
         */
218
        public static final int EXTENDED_GEOMSUBTYPE_OFFSET = 6;
219

    
220
        public interface OPERATIONS {
221
                public final static String CONVERTTOWKT = "toWKT";
222
                public final static String CONVERTTOWKB = "toWKB";
223
                public final static String BUFFER = "buffer";
224
                public final static String DISTANCE = "Distance";
225
                public final static String CONTAINS = "Contains";
226
                public final static String OVERLAPS = "OVERLAPS";
227
                public final static String CONVEXHULL = "ConvexHull";
228
                public final static String COVERS = "Covers";
229
                public final static String CROSSES = "Crosses";
230
                public final static String DIFFERENCE = "Difference";
231
                public final static String DISJOIN = "Disjoin";
232
                public final static String INTERSECTION = "Intersaction";
233
                public final static String INTERSECTS = "Intersects";
234
                public final static String TOUCHES = "Touches";
235
                public final static String UNION = "Union";
236
                public final static String WITHIN = "Within";
237
                public final static String COVEREDBY = "CoveredBy";
238
        }
239

    
240
        public static int BEST = 0;
241
        /**
242
         * North.
243
         */
244
        public static int N = 1;
245

    
246
        /**
247
         * North - East.
248
         */
249
        public static int NE = 2;
250

    
251
        /**
252
         * East.
253
         */
254
        public static int E = 3;
255

    
256
        /**
257
         * South - East.
258
         */
259
        public static int SE = 4;
260

    
261
        /**
262
         * South.
263
         */
264
        public static int S = 5;
265

    
266
        /**
267
         * South - West.
268
         */
269
        public static int SW = 6;
270

    
271
        /**
272
         * West.
273
         */
274
        public static int W = 7;
275

    
276
        /**
277
         * North - West.
278
         */
279
        public static int NW = 8;
280

    
281
        public static int SELECTHANDLER = 0;
282
        public static int STRETCHINGHANDLER = 1;
283

    
284
        /**
285
         * If this geometry is a predefined interface then this method returns one
286
         * of {@link Geometry.TYPES} contants.<br>
287
         * If this geometry is an extended type then this method returns a runtime
288
         * constant that identifies its type. By convention this value is stored in
289
         * a constant called .CODE within the geometry class, for instance:
290
         * Point2D.CODE.
291
         * 
292
         * @return If this geometry is a predefined interface then one of
293
         *         {@link Geometry.TYPES} or a runtime constant if it is an extended
294
         *         type.
295
         */
296
        public int getType();
297

    
298
        /**
299
         * Creates a clone of this geometry.
300
         * 
301
         * @return A clone of this geometry.
302
         */
303
        public Geometry cloneGeometry();
304

    
305
        /**
306
         * Returns true if this geometry intersects the rectangle passed as
307
         * parameter.
308
         * 
309
         * @param r
310
         *            Rectangle.
311
         * 
312
         * @return True, if <code>this</code> intersects <code>r</code>.
313
         */
314
        public boolean intersects(Rectangle2D r);
315

    
316
        /**
317
         * Used by the drawing strategies to quickly test whether this geometry
318
         * intersects with the visible rectangle.
319
         * 
320
         * @param x
321
         *            The minimum X coordinate.
322
         * @param y
323
         *            The minimum Y coordinate.
324
         * @param w
325
         *            The width of the envelope.
326
         * @param h
327
         *            The height of the envelope.
328
         * @return true if <code>this</code> intersects the rectangle defined by the
329
         *         parameters.
330
         */
331
        public boolean fastIntersects(double x, double y, double w, double h);
332

    
333
        /**
334
         * Returns this geometry's boundary rectangle.
335
         * 
336
         * @deprecated use getEnvelope.
337
         * @return Boundary rectangle.
338
         */
339
        public Rectangle2D getBounds2D();
340

    
341
        /**
342
         * <p>
343
         * Returns the minimum bounding box for this Geometry. This shall be the
344
         * coordinate region spanning the minimum and maximum value for each
345
         * ordinate taken on by DirectPositions in this Geometry. The simplest
346
         * representation for an envelope consists of two DirectPositions, the first
347
         * one containing all the minimums for each ordinate, and second one
348
         * containing all the maximums.
349
         * </p>
350
         * 
351
         * @return The minimum bounding box for this Geometry.
352
         */
353
        public Envelope getEnvelope();
354

    
355
        /**
356
         * Reprojects this geometry by the coordinate transformer passed as
357
         * parameter.
358
         * 
359
         * @param ct
360
         *            Coordinate Transformer.
361
         */
362
        public void reProject(ICoordTrans ct);
363

    
364
        /**
365
         * If applies an affine transformation and returns the GeneralPathXIterator
366
         * with this geometry's information.
367
         * 
368
         * @param at
369
         *            The transformation to apply.
370
         * @return The GeneralPathXIterator with this geometry's information.
371
         */
372
        public PathIterator getPathIterator(AffineTransform at);
373

    
374
        /**
375
         * It returns the handlers of the geometry, these they can be of two types
376
         * is straightening and of selection.
377
         * 
378
         * @param type
379
         *            Type of handlers.
380
         * 
381
         * @return The handlers.
382
         */
383
        public Handler[] getHandlers(int type);
384

    
385
        /**
386
         * It applies an affine transformation to the geometry.
387
         * 
388
         * @param at
389
         *            The transformation to apply.
390
         */
391
        public void transform(AffineTransform at);
392

    
393
        /**
394
         * If applies an affine transformation and returns the GeneralPathXIterator
395
         * with this geometry's information.
396
         * 
397
         * @param at
398
         *            The affine transformation.
399
         * @param flatness
400
         * 
401
         * @return The GeneralPathXIterator with this geometry's information.
402
         */
403
        PathIterator getPathIterator(AffineTransform at, double flatness);
404

    
405
        /**
406
         * Useful to have the real shape behind the scenes. May be uses to edit it
407
         * knowing it it is a Circle, Ellipse, etc.
408
         * 
409
         * @return The awt shape
410
         */
411
        public Shape getInternalShape();
412

    
413
        /**
414
         * Returns the largest number n such that each direct position in a
415
         * geometric set can be associated with a subset that has the direct
416
         * position in its interior and is similar (isomorphic) to Rn, Euclidean
417
         * n-space.
418
         * 
419
         * @return The dimension.
420
         */
421
        public int getDimension();
422

    
423
        /**
424
         * Returns <code>true</code> if this Geometry has no interior point of
425
         * self-intersection or self-tangency. In mathematical formalisms, this
426
         * means that every point in the interior of the object must have a metric
427
         * neighborhood whose intersection with the object is isomorphic to an
428
         * n-sphere, where n is the dimension of this Geometry.
429
         * 
430
         * @return If the geometry is simple.
431
         */
432
        public boolean isSimple();
433

    
434
        /**
435
         * Invokes a geometry operation given its index and context.
436
         * 
437
         * @param index
438
         *            Unique index of the operation. Operation code.
439
         * @param ctx
440
         *            The context of the geometry operation.
441
         * @return Object returned by the operation.
442
         * @throws GeometryOperationNotSupportedException
443
         *             It is thrown when the operation has been not registered for
444
         *             this geometry.
445
         * @throws GeometryOperationException
446
         *             It is thrown when there is an error executing the operation.
447
         */
448
        public Object invokeOperation(int index, GeometryOperationContext ctx)
449
                        throws GeometryOperationNotSupportedException,
450
                        GeometryOperationException;
451

    
452
        /**
453
         * Invokes a geometry operation given its name and context.
454
         * 
455
         * @param opName
456
         *            Operation name.
457
         * @param ctx
458
         *            The context of the geometry operation.
459
         * @return Object returned by the operation.
460
         * @throws GeometryOperationNotSupportedException
461
         *             It is thrown when the operation has been not registered for
462
         *             this geometry.
463
         * @throws GeometryOperationException
464
         *             It is thrown when there is an error executing the operation.
465
         */
466
        public Object invokeOperation(String opName, GeometryOperationContext ctx)
467
                        throws GeometryOperationNotSupportedException,
468
                        GeometryOperationException;
469

    
470
        /**
471
         * Instance of the GeometryType associated to this geometry.
472
         * 
473
         * @return The geometry type.
474
         */
475
        public GeometryType getGeometryType();
476

    
477
        /**
478
         * Get GeneralPathIterator, to do registered operations to it.
479
         * 
480
         * @return The GeneralPathX.
481
         */
482
        public GeneralPathX getGeneralPath();
483

    
484
        /**
485
         * Return a byte array with the equivalent in WKB format of the Geometry.
486
         * 
487
         * Utility method to wrap the invocation to the operation
488
         * {@link OPERATIONS#CONVERTTOWKB}.
489
         * 
490
         * @return the WKB version of the geometry
491
         */
492
        public byte[] convertToWKB() throws GeometryOperationNotSupportedException,
493
                        GeometryOperationException;
494

    
495
        /**
496
         * Return a string with the equivalent in WKT format of the Geometry.
497
         * 
498
         * This is a utility method to wrap the invocation to the operation
499
         * {@link OPERATIONS#CONVERTTOWKT}.
500
         * 
501
         * @return the WKT version of the geometry.
502
         * 
503
         * @throws GeometryOperationNotSupportedException
504
         * @throws GeometryOperationException
505
         */
506
        public String convertToWKT() throws GeometryOperationNotSupportedException,
507
                        GeometryOperationException;
508

    
509
        /**
510
         * Computes a buffer area around this geometry having the given width
511
         * 
512
         * This is a utility method to wrap the invocation to the operation
513
         * {@link OPERATIONS#BUFFER}.
514
         * 
515
         * @param distance
516
         *            the width of the buffer
517
         * 
518
         * @return a new Geometry with the computed buffer.
519
         * 
520
         * @throws GeometryOperationNotSupportedException
521
         * @throws GeometryOperationException
522
         */
523
        public Geometry buffer(double distance)
524
                        throws GeometryOperationNotSupportedException,
525
                        GeometryOperationException;
526

    
527
        /**
528
         * Tests whether this geometry contains the specified geometry.
529
         * 
530
         * This is a utility method to wrap the invocation to the operation
531
         * {@link OPERATIONS#CONTAINS}.
532
         * 
533
         * @param geometry
534
         *            the Geometry with which to compare this Geometry
535
         * 
536
         * @return if this Geometry contains the specified geometry
537
         * 
538
         * @throws GeometryOperationNotSupportedException
539
         * @throws GeometryOperationException
540
         */
541
        public boolean contains(Geometry geometry)
542
                        throws GeometryOperationNotSupportedException,
543
                        GeometryOperationException;
544

    
545
        /**
546
         * Returns the minimum distance between this Geometry and the specified
547
         * geometry.
548
         * 
549
         * This is a utility method to wrap the invocation to the operation
550
         * {@link OPERATIONS#DISTANCE}.
551
         * 
552
         * @param geometry
553
         *            the Geometry from which to compute the distance
554
         * 
555
         * @return the distance between the geometries
556
         * 
557
         * @throws GeometryOperationNotSupportedException
558
         * @throws GeometryOperationException
559
         */
560
        public double distance(Geometry geometry)
561
                        throws GeometryOperationNotSupportedException,
562
                        GeometryOperationException;
563

    
564
        /**
565
         * Tests whether this geometry overlaps the specified geometry.
566
         * 
567
         * This is a utility method to wrap the invocation to the operation
568
         * {@link OPERATIONS#OVERLAPS}.
569
         * 
570
         * @param geometry
571
         *            the Geometry with which to compare this Geometry
572
         * 
573
         * @return true if the two geometries overlap.
574
         * 
575
         * @throws GeometryOperationNotSupportedException
576
         * @throws GeometryOperationException
577
         */
578
        public boolean overlaps(Geometry geometry)
579
                        throws GeometryOperationNotSupportedException,
580
                        GeometryOperationException;
581

    
582
        public Geometry convexHull() throws GeometryOperationNotSupportedException,
583
                        GeometryOperationException;
584

    
585
        public boolean coveredBy(Geometry geometry)
586
                        throws GeometryOperationNotSupportedException,
587
                        GeometryOperationException;
588

    
589
        public boolean crosses(Geometry geometry)
590
                        throws GeometryOperationNotSupportedException,
591
                        GeometryOperationException;
592

    
593
        public Geometry difference(Geometry other)
594
                        throws GeometryOperationNotSupportedException,
595
                        GeometryOperationException;
596

    
597
        public boolean disjoint(Geometry geometry)
598
                        throws GeometryOperationNotSupportedException,
599
                        GeometryOperationException;
600

    
601
        public Geometry intersection(Geometry other)
602
                        throws GeometryOperationNotSupportedException,
603
                        GeometryOperationException;
604

    
605
        public boolean intersects(Geometry geometry)
606
                        throws GeometryOperationNotSupportedException,
607
                        GeometryOperationException;
608

    
609
        public boolean touches(Geometry geometry)
610
                        throws GeometryOperationNotSupportedException,
611
                        GeometryOperationException;
612

    
613
        public Geometry union(Geometry other)
614
                        throws GeometryOperationNotSupportedException,
615
                        GeometryOperationException;
616

    
617
        public boolean within(Geometry geometry)
618
                        throws GeometryOperationNotSupportedException,
619
                        GeometryOperationException;
620

    
621
}