Statistics
| Revision:

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

History | View | Annotate | Download (18.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
 * <p>
68
 * This class extends of the {@link Shape} class by historical reasons but this
69
 * inheritance will disappear in future versions.
70
 * </p>
71
 * @see <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012"
72
 *      >ISO 19107< /a>
73
 */
74
public interface Geometry extends Shape, Serializable, Comparable {
75

    
76
        /**
77
         * Predefined geometry types in the model.
78
         */
79
        public interface TYPES {
80

    
81
                /**
82
                 * Any geometry.
83
                 */
84

    
85
                public final static int GEOMETRY = 0;
86

    
87
                /**
88
                 * A geometric element that has zero dimensions and a location
89
                 * determinable by an ordered set of coordinates.
90
                 */
91
                public final static int POINT = 1;
92

    
93
                /**
94
                 * A straight or curved geometric element that is generated by a moving
95
                 * point and that has extension only along the path of the point.
96
                 */
97
                public final static int CURVE = 2;
98

    
99
                /**
100
                 * A closed plane figure bounded by straight lines.
101
                 */
102
                public final static int SURFACE = 3;
103

    
104
                /**
105
                 * Solids in 3D.
106
                 */
107
                public final static int SOLID = 4;
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 three dimensions.
184
                 */
185
                public final static int GEOM3D = 1;
186

    
187
                /**
188
                 * Geometries with two dimensions and with the M coordinate.
189
                 */
190
                public final static int GEOM2DM = 2;
191

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

    
197
                /**
198
                 * The subtype us unknown.
199
                 */
200
                public final static int UNKNOWN = 4;
201
        }
202

    
203
        /**
204
         * Initial value for new geometry types (it must not overlap with the basic
205
         * ones defined in TYPES).
206
         */
207
        public static final int EXTENDED_GEOMTYPE_OFFSET = 17;
208

    
209
        /**
210
         * Initial value for new geometry subtypes (it must not overlap with the
211
         * basic ones defined in SUBTYPES).
212
         */
213
        public static final int EXTENDED_GEOMSUBTYPE_OFFSET = 6;
214

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

    
235
        public static int BEST = 0;
236
        /**
237
         * North.
238
         */
239
        public static int N = 1;
240

    
241
        /**
242
         * North - East.
243
         */
244
        public static int NE = 2;
245

    
246
        /**
247
         * East.
248
         */
249
        public static int E = 3;
250

    
251
        /**
252
         * South - East.
253
         */
254
        public static int SE = 4;
255

    
256
        /**
257
         * South.
258
         */
259
        public static int S = 5;
260

    
261
        /**
262
         * South - West.
263
         */
264
        public static int SW = 6;
265

    
266
        /**
267
         * West.
268
         */
269
        public static int W = 7;
270

    
271
        /**
272
         * North - West.
273
         */
274
        public static int NW = 8;
275

    
276
        public static int SELECTHANDLER = 0;
277
        public static int STRETCHINGHANDLER = 1;
278

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

    
293
        /**
294
         * Creates a clone of this geometry.
295
         * 
296
         * @return A clone of this geometry.
297
         */
298
        public Geometry cloneGeometry();
299

    
300
        /**
301
         * Returns true if this geometry intersects the rectangle passed as
302
         * parameter.
303
         * 
304
         * @param r
305
         *            Rectangle.
306
         * 
307
         * @return True, if <code>this</code> intersects <code>r</code>.
308
         */
309
        public boolean intersects(Rectangle2D r);
310

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

    
328
        /**
329
         * Returns this geometry's boundary rectangle.
330
         * 
331
         * @deprecated use getEnvelope.
332
         * @return Boundary rectangle.
333
         */
334
        public Rectangle2D getBounds2D();
335

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

    
350
        /**
351
         * Reprojects this geometry by the coordinate transformer passed as
352
         * parameter.
353
         * 
354
         * @param ct
355
         *            Coordinate Transformer.
356
         */
357
        public void reProject(ICoordTrans ct);
358

    
359
        /**
360
         * If applies an affine transformation and returns the GeneralPathXIterator
361
         * with this geometry's information.
362
         * 
363
         * @param at
364
         *            The transformation to apply.
365
         * @return The GeneralPathXIterator with this geometry's information.
366
         */
367
        public PathIterator getPathIterator(AffineTransform at);
368

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

    
380
        /**
381
         * It applies an affine transformation to the geometry.
382
         * 
383
         * @param at
384
         *            The transformation to apply.
385
         */
386
        public void transform(AffineTransform at);
387

    
388
        /**
389
         * If applies an affine transformation and returns the GeneralPathXIterator
390
         * with this geometry's information.
391
         * 
392
         * @param at
393
         *            The affine transformation.
394
         * @param flatness
395
         * 
396
         * @return The GeneralPathXIterator with this geometry's information.
397
         */
398
        PathIterator getPathIterator(AffineTransform at, double flatness);
399

    
400
        /**
401
         * Useful to have the real shape behind the scenes. May be uses to edit it
402
         * knowing it it is a Circle, Ellipse, etc.
403
         * 
404
         * @return The awt shape
405
         */
406
        public Shape getInternalShape();
407

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

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

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

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

    
465
        /**
466
         * Instance of the GeometryType associated to this geometry.
467
         * 
468
         * @return The geometry type.
469
         */
470
        public GeometryType getGeometryType();
471

    
472
        /**
473
         * Get GeneralPathIterator, to do registered operations to it.
474
         * 
475
         * @return The GeneralPathX.
476
         */
477
        public GeneralPathX getGeneralPath();
478

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

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

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

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

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

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

    
577
        public Geometry convexHull() throws GeometryOperationNotSupportedException,
578
                        GeometryOperationException;
579

    
580
        public boolean coveredBy(Geometry geometry)
581
                        throws GeometryOperationNotSupportedException,
582
                        GeometryOperationException;
583

    
584
        public boolean crosses(Geometry geometry)
585
                        throws GeometryOperationNotSupportedException,
586
                        GeometryOperationException;
587

    
588
        public Geometry difference(Geometry other)
589
                        throws GeometryOperationNotSupportedException,
590
                        GeometryOperationException;
591

    
592
        public boolean disjoint(Geometry geometry)
593
                        throws GeometryOperationNotSupportedException,
594
                        GeometryOperationException;
595

    
596
        public Geometry intersection(Geometry other)
597
                        throws GeometryOperationNotSupportedException,
598
                        GeometryOperationException;
599

    
600
        public boolean intersects(Geometry geometry)
601
                        throws GeometryOperationNotSupportedException,
602
                        GeometryOperationException;
603

    
604
        public boolean touches(Geometry geometry)
605
                        throws GeometryOperationNotSupportedException,
606
                        GeometryOperationException;
607

    
608
        public Geometry union(Geometry other)
609
                        throws GeometryOperationNotSupportedException,
610
                        GeometryOperationException;
611

    
612
        public boolean within(Geometry geometry)
613
                        throws GeometryOperationNotSupportedException,
614
                        GeometryOperationException;
615

    
616
        public Point centroid() throws GeometryOperationNotSupportedException, GeometryOperationException;
617
        
618
        /**
619
         * This method returns a point which is inside the geometry.
620
         * This is useful for mathematical purposes but it is very unlikely
621
         * to be a suitable place for a label, for example.
622
         * 
623
         * 
624
         * @return an interior point
625
         * @throws GeometryOperationNotSupportedException
626
         * @throws GeometryOperationException
627
         */
628
        public Point getInteriorPoint() throws GeometryOperationNotSupportedException, GeometryOperationException;
629

    
630
        public double area() throws GeometryOperationNotSupportedException, GeometryOperationException;
631
        
632
        public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException;
633
        
634
        /**
635
     * @return  the awt shape used to display the geometry. It 
636
     * applies a tranformation before to return the coordinates
637
     * of the shape
638
     * @deprecated this class inherits of {@link Shape} by historical
639
     * reasons. This method has been added just to control the usage of
640
     * the {@link Shape} class but it will removed in a future.
641
     */
642
        public Shape getShape(AffineTransform affineTransform);
643
        
644
        /**
645
     * @return  the awt shape used to display the geometry. 
646
     * @deprecated this class inherits of {@link Shape} by historical
647
     * reasons. This method has been added just to control the usage of
648
     * the {@link Shape} class but it will removed in a future.
649
     */
650
        public Shape getShape();
651
}