Statistics
| Revision:

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

History | View | Annotate | Download (17.9 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 two dimensions and with a value for the elevation.
186
                 */
187
                public final static int GEOM2DZ = 1;
188

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

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

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

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

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

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

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

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

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

    
253
        /**
254
         * East.
255
         */
256
        public static int E = 3;
257

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

    
263
        /**
264
         * South.
265
         */
266
        public static int S = 5;
267

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

    
273
        /**
274
         * West.
275
         */
276
        public static int W = 7;
277

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

    
283
        public static int SELECTHANDLER = 0;
284
        public static int STRETCHINGHANDLER = 1;
285

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
584
        public Geometry convexHull() throws GeometryOperationNotSupportedException,
585
                        GeometryOperationException;
586

    
587
        public boolean coveredBy(Geometry geometry)
588
                        throws GeometryOperationNotSupportedException,
589
                        GeometryOperationException;
590

    
591
        public boolean crosses(Geometry geometry)
592
                        throws GeometryOperationNotSupportedException,
593
                        GeometryOperationException;
594

    
595
        public Geometry difference(Geometry other)
596
                        throws GeometryOperationNotSupportedException,
597
                        GeometryOperationException;
598

    
599
        public boolean disjoint(Geometry geometry)
600
                        throws GeometryOperationNotSupportedException,
601
                        GeometryOperationException;
602

    
603
        public Geometry intersection(Geometry other)
604
                        throws GeometryOperationNotSupportedException,
605
                        GeometryOperationException;
606

    
607
        public boolean intersects(Geometry geometry)
608
                        throws GeometryOperationNotSupportedException,
609
                        GeometryOperationException;
610

    
611
        public boolean touches(Geometry geometry)
612
                        throws GeometryOperationNotSupportedException,
613
                        GeometryOperationException;
614

    
615
        public Geometry union(Geometry other)
616
                        throws GeometryOperationNotSupportedException,
617
                        GeometryOperationException;
618

    
619
        public boolean within(Geometry geometry)
620
                        throws GeometryOperationNotSupportedException,
621
                        GeometryOperationException;
622

    
623
        public Point centroid() throws GeometryOperationNotSupportedException, GeometryOperationException;
624
        
625
        public double area() throws GeometryOperationNotSupportedException, GeometryOperationException;
626
        
627
        public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException;
628
}