Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2059 / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / Geometry.java @ 39313

History | View | Annotate | Download (21.2 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
         * <p>
330
         * Returns the minimum bounding box for this Geometry. This shall be the
331
         * coordinate region spanning the minimum and maximum value for each
332
         * ordinate taken on by DirectPositions in this Geometry. The simplest
333
         * representation for an envelope consists of two DirectPositions, the first
334
         * one containing all the minimums for each ordinate, and second one
335
         * containing all the maximums.
336
         * </p>
337
         * 
338
         * @return The minimum bounding box for this Geometry.
339
         */
340
        public Envelope getEnvelope();
341

    
342
        /**
343
         * Reprojects this geometry by the coordinate transformer passed as
344
         * parameter.
345
         * 
346
         * @param ct
347
         *            Coordinate Transformer.
348
         */
349
        public void reProject(ICoordTrans ct);
350

    
351
        /**
352
         * It applies an affine transformation to the geometry.
353
         * If parameter value is null, it will be considered an
354
         * empty transformation, therefore equivalent to the identity
355
         * transformation.
356
         * 
357
         * @param at
358
         *            The transformation to apply.
359
         */
360
        public void transform(AffineTransform at);
361
        /**
362
         * Returns the largest number n such that each direct position in a
363
         * geometric set can be associated with a subset that has the direct
364
         * position in its interior and is similar (isomorphic) to Rn, Euclidean
365
         * n-space.
366
         * 
367
         * @return The dimension.
368
         */
369
        public int getDimension();
370

    
371
        /**
372
         * Returns <code>true</code> if this Geometry has no interior point of
373
         * self-intersection or self-tangency. In mathematical formalisms, this
374
         * means that every point in the interior of the object must have a metric
375
         * neighborhood whose intersection with the object is isomorphic to an
376
         * n-sphere, where n is the dimension of this Geometry.
377
         * 
378
         * @return If the geometry is simple.
379
         */
380
        public boolean isSimple();
381

    
382
        /**
383
         * Invokes a geometry operation given its index and context.
384
         * 
385
         * @param index
386
         *            Unique index of the operation. Operation code.
387
         * @param ctx
388
         *            The context of the geometry operation.
389
         * @return Object returned by the operation.
390
         * @throws GeometryOperationNotSupportedException
391
         *             It is thrown when the operation has been not registered for
392
         *             this geometry.
393
         * @throws GeometryOperationException
394
         *             It is thrown when there is an error executing the operation.
395
         */
396
        public Object invokeOperation(int index, GeometryOperationContext ctx)
397
                        throws GeometryOperationNotSupportedException,
398
                        GeometryOperationException;
399

    
400
        /**
401
         * Invokes a geometry operation given its name and context.
402
         * 
403
         * @param opName
404
         *            Operation name.
405
         * @param ctx
406
         *            The context of the geometry operation.
407
         * @return Object returned by the operation.
408
         * @throws GeometryOperationNotSupportedException
409
         *             It is thrown when the operation has been not registered for
410
         *             this geometry.
411
         * @throws GeometryOperationException
412
         *             It is thrown when there is an error executing the operation.
413
         */
414
        public Object invokeOperation(String opName, GeometryOperationContext ctx)
415
                        throws GeometryOperationNotSupportedException,
416
                        GeometryOperationException;
417

    
418
        /**
419
         * Instance of the GeometryType associated to this geometry.
420
         * 
421
         * @return The geometry type.
422
         */
423
        public GeometryType getGeometryType();
424

    
425
        /**
426
         * Return a byte array with the equivalent in WKB format of the Geometry.
427
         * 
428
         * Utility method to wrap the invocation to the operation
429
         * {@link OPERATIONS#CONVERTTOWKB}.
430
         * 
431
         * @return the WKB version of the geometry
432
         */
433
        public byte[] convertToWKB() throws GeometryOperationNotSupportedException,
434
                        GeometryOperationException;
435

    
436
        /**
437
         * Return a string with the equivalent in WKT format of the Geometry.
438
         * 
439
         * This is a utility method to wrap the invocation to the operation
440
         * {@link OPERATIONS#CONVERTTOWKT}.
441
         * 
442
         * @return the WKT version of the geometry.
443
         * 
444
         * @throws GeometryOperationNotSupportedException
445
         * @throws GeometryOperationException
446
         */
447
        public String convertToWKT() throws GeometryOperationNotSupportedException,
448
                        GeometryOperationException;
449

    
450
        /**
451
         * Computes a buffer area around this geometry having the given width
452
         * 
453
         * This is a utility method to wrap the invocation to the operation
454
         * {@link OPERATIONS#BUFFER}.
455
         * 
456
         * @param distance
457
         *            the width of the buffer
458
         * 
459
         * @return a new Geometry with the computed buffer.
460
         * 
461
         * @throws GeometryOperationNotSupportedException
462
         * @throws GeometryOperationException
463
         */
464
        public Geometry buffer(double distance)
465
                        throws GeometryOperationNotSupportedException,
466
                        GeometryOperationException;
467

    
468
        /**
469
         * Tests whether this geometry contains the specified geometry.
470
         * 
471
         * This is a utility method to wrap the invocation to the operation
472
         * {@link OPERATIONS#CONTAINS}.
473
         * 
474
         * @param geometry
475
         *            the Geometry with which to compare this Geometry
476
         * 
477
         * @return if this Geometry contains the specified geometry
478
         * 
479
         * @throws GeometryOperationNotSupportedException
480
         * @throws GeometryOperationException
481
         */
482
        public boolean contains(Geometry geometry)
483
                        throws GeometryOperationNotSupportedException,
484
                        GeometryOperationException;
485

    
486
        /**
487
         * Returns the minimum distance between this Geometry and the specified
488
         * geometry.
489
         * 
490
         * This is a utility method to wrap the invocation to the operation
491
         * {@link OPERATIONS#DISTANCE}.
492
         * 
493
         * @param geometry
494
         *            the Geometry from which to compute the distance
495
         * 
496
         * @return the distance between the geometries
497
         * 
498
         * @throws GeometryOperationNotSupportedException
499
         * @throws GeometryOperationException
500
         */
501
        public double distance(Geometry other)
502
                        throws GeometryOperationNotSupportedException,
503
                        GeometryOperationException;
504

    
505
        public Geometry[] closestPoints(Geometry other)
506
                        throws GeometryOperationNotSupportedException,
507
                        GeometryOperationException;
508
        
509
        boolean isWithinDistance(Geometry other, double distance) 
510
                        throws GeometryOperationNotSupportedException,
511
                        GeometryOperationException;
512

    
513
        /**
514
         * Tests whether this geometry overlaps the specified geometry.
515
         * 
516
         * This is a utility method to wrap the invocation to the operation
517
         * {@link OPERATIONS#OVERLAPS}.
518
         * 
519
         * @param geometry
520
         *            the Geometry with which to compare this Geometry
521
         * 
522
         * @return true if the two geometries overlap.
523
         * 
524
         * @throws GeometryOperationNotSupportedException
525
         * @throws GeometryOperationException
526
         */
527
        public boolean overlaps(Geometry geometry)
528
                        throws GeometryOperationNotSupportedException,
529
                        GeometryOperationException;
530

    
531
        public Geometry convexHull() throws GeometryOperationNotSupportedException,
532
                        GeometryOperationException;
533

    
534
        public boolean coveredBy(Geometry geometry)
535
                        throws GeometryOperationNotSupportedException,
536
                        GeometryOperationException;
537

    
538
        public boolean crosses(Geometry geometry)
539
                        throws GeometryOperationNotSupportedException,
540
                        GeometryOperationException;
541

    
542
        public Geometry difference(Geometry other)
543
                        throws GeometryOperationNotSupportedException,
544
                        GeometryOperationException;
545

    
546
        public boolean disjoint(Geometry geometry)
547
                        throws GeometryOperationNotSupportedException,
548
                        GeometryOperationException;
549

    
550
        public Geometry intersection(Geometry other)
551
                        throws GeometryOperationNotSupportedException,
552
                        GeometryOperationException;
553

    
554
        public boolean intersects(Geometry geometry)
555
                        throws GeometryOperationNotSupportedException,
556
                        GeometryOperationException;
557

    
558
        public Geometry snapTo(Geometry other, double snapTolerance)
559
                        throws GeometryOperationNotSupportedException,
560
                        GeometryOperationException;
561
        
562
        public boolean touches(Geometry geometry)
563
                        throws GeometryOperationNotSupportedException,
564
                        GeometryOperationException;
565

    
566
        public Geometry union(Geometry other)
567
                        throws GeometryOperationNotSupportedException,
568
                        GeometryOperationException;
569

    
570
        public boolean within(Geometry geometry)
571
                        throws GeometryOperationNotSupportedException,
572
                        GeometryOperationException;
573

    
574
        public Point centroid() throws GeometryOperationNotSupportedException, GeometryOperationException;
575
        
576
        /**
577
         * This method returns a point which is inside the geometry.
578
         * This is useful for mathematical purposes but it is very unlikely
579
         * to be a suitable place for a label, for example.
580
         * 
581
         * 
582
         * @return an interior point
583
         * @throws GeometryOperationNotSupportedException
584
         * @throws GeometryOperationException
585
         */
586
        public Point getInteriorPoint() throws GeometryOperationNotSupportedException, GeometryOperationException;
587

    
588
        public double area() throws GeometryOperationNotSupportedException, GeometryOperationException;
589
        
590
        public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException;
591

    
592
        
593
        
594
        
595
        /**
596
         * Rotates the geometry by radAngle radians using the given
597
         * coordinates as center of rotation. Rotating with a positive
598
         * angle rotates points on the positive x axis toward the
599
         * positive y axis. In most cases, we assume x increases
600
         * rightwards and y increases upwards, so in most cases,
601
         * a positive angle will mean counter-clockwise rotation.
602
         * 
603
         * @param radAngle the amount of rotation, in radians
604
         * @param basex x coordinate of center of rotation
605
         * @param basey y coordinate of center of rotation
606
         */
607
        public void rotate(double radAngle, double basex, double basey);
608
        
609
        /**
610
         * Shifts geometry by given amount in x and y axes
611
         * 
612
         * @param dx 
613
         * @param dy
614
         */
615
        public void move(double dx, double dy);
616
        
617
        
618
        /**
619
         * Scales geometry in x and y axes by given scale factors
620
         * using the given point as center of projection.
621
         *  
622
         * @param basePoint
623
         * @param sx scale factor in x axis
624
         * @param sy scale factor in y axis
625
         */
626
        public void scale(Point basePoint, double sx, double sy);
627
        
628
        
629
        
630
        
631
        //
632
        // ===============================================
633
        //
634
        
635
        
636
        /**
637
     * @return  the awt shape used to display the geometry. It 
638
     * applies a tranformation before to return the coordinates
639
     * of the shape
640
     * @deprecated this class inherits of {@link Shape} by historical
641
     * reasons. This method has been added just to control the usage of
642
     * the {@link Shape} class but it will removed in a future.
643
     */
644
        public Shape getShape(AffineTransform affineTransform);
645
        
646
        /**
647
     * @return  the awt shape used to display the geometry. 
648
     * @deprecated this class inherits of {@link Shape} by historical
649
     * reasons. This method has been added just to control the usage of
650
     * the {@link Shape} class but it will removed in a future.
651
     */
652
        public Shape getShape();
653

    
654
        /**
655
         * Returns this geometry's boundary rectangle.
656
         * 
657
         * @deprecated use getEnvelope.
658
         * @return Boundary rectangle.
659
         */
660
        public Rectangle2D getBounds2D();
661

    
662
        /**
663
         * If applies an affine transformation and returns the GeneralPathXIterator
664
         * with this geometry's information.
665
         * 
666
         * @param at
667
         *            The transformation to apply.
668
         * @return The GeneralPathXIterator with this geometry's information.
669
         * @deprecated don't use PathIterator over geometries, use instead specific API for each operation. If not has API for that operation let the project team.
670
         * 
671
         */
672
        public PathIterator getPathIterator(AffineTransform at);
673

    
674
        /**
675
         * It returns the handlers of the geometry, these they can be of two types
676
         * is straightening and of selection.
677
         * 
678
         * @param type
679
         *            Type of handlers.
680
         * 
681
         * @deprecated don't use Handlers over geometries, use instead specific API for each operation. If not has API for that operation let the project team.
682
         * @return The handlers.
683
         */
684
        public Handler[] getHandlers(int type);
685

    
686

    
687
        /**
688
         * If applies an affine transformation and returns the GeneralPathXIterator
689
         * with this geometry's information.
690
         * 
691
         * @param at
692
         *            The affine transformation.
693
         * @param flatness
694
         * 
695
         * @return The GeneralPathXIterator with this geometry's information.
696
         * @deprecated don't use PathIterator over geometries, use instead specific API for each operation. If not has API for that operation let the project team.
697
         */
698
        PathIterator getPathIterator(AffineTransform at, double flatness);
699

    
700
        /**
701
         * Useful to have the real shape behind the scenes. May be uses to edit it
702
         * knowing it it is a Circle, Ellipse, etc.
703
         * 
704
         * @return The awt shape
705
         * @deprecated
706
         */
707
        public Shape getInternalShape();
708

    
709

    
710
        /**
711
         * Get GeneralPathIterator, to do registered operations to it.
712
         * 
713
         * @return The GeneralPathX.
714
         * @deprecated don't use GeneralPathX over geometries, use instead specific API for each operation. If not has API for that operation let the project team.
715
         */
716
        public GeneralPathX getGeneralPath();
717

    
718
}