Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.api / src / main / java / org / gvsig / fmap / geom / Geometry.java @ 40767

History | View | Annotate | Download (21.4 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
package org.gvsig.fmap.geom;
26

    
27
import java.awt.Shape;
28
import java.awt.geom.AffineTransform;
29
import java.awt.geom.PathIterator;
30
import java.awt.geom.Rectangle2D;
31
import java.io.Serializable;
32

    
33
import org.cresques.cts.ICoordTrans;
34

    
35
import org.gvsig.fmap.geom.handler.Handler;
36
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
37
import org.gvsig.fmap.geom.operation.GeometryOperationException;
38
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
39
import org.gvsig.fmap.geom.primitive.Envelope;
40
import org.gvsig.fmap.geom.primitive.GeneralPathX;
41
import org.gvsig.fmap.geom.primitive.Point;
42
import org.gvsig.fmap.geom.type.GeometryType;
43

    
44
/**
45
 * <p>
46
 * 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"
47
 * >ISO 19107</a>. It is the root class of the geometric object taxonomy and
48
 * supports interfaces common to all geographically referenced geometric
49
 * objects.
50
 * </p>
51
 * <p>
52
 * Geometry instances are sets of direct positions in a particular coordinate
53
 * reference system. A Geometry can be regarded as an infinite set of points
54
 * that satisfies the set operation interfaces for a set of direct positions.
55
 * </p>
56
 * <p>
57
 * A geometric object shall be a combination of a coordinate geometry and a
58
 * coordinate reference system. In all of the operations, all geometric
59
 * calculations shall be done in the coordinate reference system of the first
60
 * geometric object accessed, which is normally the object whose operation is
61
 * being invoked. Returned objects shall be in the coordinate reference system
62
 * in which the calculations are done unless explicitly stated otherwise.
63
 * </p>
64
 * <p>
65
 * This class extends of the {@link Shape} class by historical reasons but this
66
 * inheritance will disappear in future versions.
67
 * </p>
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
                 * A set that can contain points, lines and polygons. This is usual in
108
                 * <i>CAD</i> layers <i>(dxf, dgn, dwg)</i>.
109
                 */
110
                public final static int AGGREGATE = 6;
111
                /**
112
                 * A set of points.
113
                 */
114
                public final static int MULTIPOINT = 7;
115

    
116
                /**
117
                 * A set of lines.
118
                 */
119
                public final static int MULTICURVE = 8;
120

    
121
                /**
122
                 * A set of polygons.
123
                 */
124
                public final static int MULTISURFACE = 9;
125

    
126
                /**
127
                 * A set of solids.
128
                 */
129
                public final static int MULTISOLID = 10;
130

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

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

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

    
149
                public final static int SPLINE = 14;
150

    
151
                public final static int ELLIPTICARC = 15;
152

    
153
                /**
154
                 * NO DATA geometry.
155
                 */
156
                public final static int NULL = 16;
157
        }
158

    
159
        public interface DIMENSIONS {
160
                public final static int X = 0;
161
                public final static int Y = 1;
162
                public final static int Z = 2;
163
        }
164

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

    
174
                /**
175
                 * Geometries with two dimensions.
176
                 */
177
                public final static int GEOM2D = 0;
178

    
179
                /**
180
                 * Geometries with three dimensions.
181
                 */
182
                public final static int GEOM3D = 1;
183

    
184
                /**
185
                 * Geometries with two dimensions and with the M coordinate.
186
                 */
187
                public final static int GEOM2DM = 2;
188

    
189
                /**
190
                 * Geometries with three dimensions and with the M coordinate.
191
                 */
192
                public final static int GEOM3DM = 3;
193

    
194
                /**
195
                 * The subtype us unknown.
196
                 */
197
                public final static int UNKNOWN = 4;
198
        }
199

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

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

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

    
232
        public static int BEST = 0;
233
        /**
234
         * North.
235
         */
236
        public static int N = 1;
237

    
238
        /**
239
         * North - East.
240
         */
241
        public static int NE = 2;
242

    
243
        /**
244
         * East.
245
         */
246
        public static int E = 3;
247

    
248
        /**
249
         * South - East.
250
         */
251
        public static int SE = 4;
252

    
253
        /**
254
         * South.
255
         */
256
        public static int S = 5;
257

    
258
        /**
259
         * South - West.
260
         */
261
        public static int SW = 6;
262

    
263
        /**
264
         * West.
265
         */
266
        public static int W = 7;
267

    
268
        /**
269
         * North - West.
270
         */
271
        public static int NW = 8;
272

    
273
        public static int SELECTHANDLER = 0;
274
        public static int STRETCHINGHANDLER = 1;
275

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

    
290
        /**
291
         * Creates a clone of this geometry.
292
         * 
293
         * @return A clone of this geometry.
294
         */
295
        public Geometry cloneGeometry();
296

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

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

    
325
        /**
326
         * <p>
327
         * Returns the minimum bounding box for this Geometry. This shall be the
328
         * coordinate region spanning the minimum and maximum value for each
329
         * ordinate taken on by DirectPositions in this Geometry. The simplest
330
         * representation for an envelope consists of two DirectPositions, the first
331
         * one containing all the minimums for each ordinate, and second one
332
         * containing all the maximums.
333
         * </p>
334
         * 
335
         * @return The minimum bounding box for this Geometry.
336
         */
337
        public Envelope getEnvelope();
338

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

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

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

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

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

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

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

    
433
        public byte[] convertToWKB(int srs) 
434
                throws GeometryOperationNotSupportedException, GeometryOperationException;
435
        
436
        public byte[] convertToWKBForcingType(int srs, int type) 
437
                throws GeometryOperationNotSupportedException, GeometryOperationException;
438

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

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

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

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

    
508
        public Geometry[] closestPoints(Geometry other)
509
                        throws GeometryOperationNotSupportedException,
510
                        GeometryOperationException;
511
        
512
        boolean isWithinDistance(Geometry other, double distance) 
513
                        throws GeometryOperationNotSupportedException,
514
                        GeometryOperationException;
515

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

    
534
        public Geometry convexHull() throws GeometryOperationNotSupportedException,
535
                        GeometryOperationException;
536

    
537
        public boolean coveredBy(Geometry geometry)
538
                        throws GeometryOperationNotSupportedException,
539
                        GeometryOperationException;
540

    
541
        public boolean crosses(Geometry geometry)
542
                        throws GeometryOperationNotSupportedException,
543
                        GeometryOperationException;
544

    
545
        public Geometry difference(Geometry other)
546
                        throws GeometryOperationNotSupportedException,
547
                        GeometryOperationException;
548

    
549
        public boolean disjoint(Geometry geometry)
550
                        throws GeometryOperationNotSupportedException,
551
                        GeometryOperationException;
552

    
553
        public Geometry intersection(Geometry other)
554
                        throws GeometryOperationNotSupportedException,
555
                        GeometryOperationException;
556

    
557
        public boolean intersects(Geometry geometry)
558
                        throws GeometryOperationNotSupportedException,
559
                        GeometryOperationException;
560

    
561
        public Geometry snapTo(Geometry other, double snapTolerance)
562
                        throws GeometryOperationNotSupportedException,
563
                        GeometryOperationException;
564
        
565
        public boolean touches(Geometry geometry)
566
                        throws GeometryOperationNotSupportedException,
567
                        GeometryOperationException;
568

    
569
        public Geometry union(Geometry other)
570
                        throws GeometryOperationNotSupportedException,
571
                        GeometryOperationException;
572

    
573
        public boolean within(Geometry geometry)
574
                        throws GeometryOperationNotSupportedException,
575
                        GeometryOperationException;
576

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

    
591
        public double area() throws GeometryOperationNotSupportedException, GeometryOperationException;
592
        
593
        public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException;
594

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

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

    
665
        /**
666
         * If applies an affine transformation and returns the GeneralPathXIterator
667
         * with this geometry's information.
668
         * 
669
         * @param at
670
         *            The transformation to apply.
671
         * @return The GeneralPathXIterator with this geometry's information.
672
         * @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.
673
         * 
674
         */
675
        public PathIterator getPathIterator(AffineTransform at);
676

    
677
        /**
678
         * It returns the handlers of the geometry, these they can be of two types
679
         * is straightening and of selection.
680
         * 
681
         * @param type
682
         *            Type of handlers.
683
         * 
684
         * @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.
685
         * @return The handlers.
686
         */
687
        public Handler[] getHandlers(int type);
688

    
689

    
690
        /**
691
         * If applies an affine transformation and returns the GeneralPathXIterator
692
         * with this geometry's information.
693
         * 
694
         * @param at
695
         *            The affine transformation.
696
         * @param flatness
697
         * 
698
         * @return The GeneralPathXIterator with this geometry's information.
699
         * @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.
700
         */
701
        PathIterator getPathIterator(AffineTransform at, double flatness);
702

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

    
712

    
713
        /**
714
         * Get GeneralPathIterator, to do registered operations to it.
715
         * 
716
         * @return The GeneralPathX.
717
         * @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.
718
         */
719
        public GeneralPathX getGeneralPath();
720

    
721
}