Statistics
| Revision:

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

History | View | Annotate | Download (11.4 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

    
28
package org.gvsig.fmap.geom;
29

    
30
import java.awt.Shape;
31
import java.awt.geom.AffineTransform;
32
import java.awt.geom.PathIterator;
33
import java.awt.geom.Rectangle2D;
34
import java.io.Serializable;
35

    
36
import org.cresques.cts.ICoordTrans;
37
import org.gvsig.fmap.geom.handler.Handler;
38
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
39
import org.gvsig.fmap.geom.operation.GeometryOperationException;
40
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
41
import org.gvsig.fmap.geom.primitive.Envelope;
42
import org.gvsig.fmap.geom.primitive.FShape;
43
import org.gvsig.fmap.geom.primitive.GeneralPathX;
44
import org.gvsig.fmap.geom.type.GeometryType;
45

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

    
72
        /**
73
         * Predefined geometry types in the model
74
         */
75
        public interface TYPES {
76
                /**
77
                 * NO DATA geometry.
78
                 */
79
                public final static int NULL = -1;
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 determinable by an ordered set
89
                 *  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 point and that has extension
95
                 *  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 = 4;
103
                
104
                /**
105
                 * Solids in 3D
106
                 */
107
                public final static int SOLID = 8;
108
                
109
                /**
110
                 * Words, symbols and form of a written or printed work.
111
                 */
112
                public final static int TEXT = 16;
113
                
114
                /**
115
                 * A set that can contain points, lines and polygons. This is usual in <i>CAD</i> layers <i>(dxf, dgn, dwg)</i>.
116
                 */
117
                public final static int AGGREGATE = 32;
118
                /**
119
                 * A set of points.
120
                 */
121
                public final static int MULTIPOINT = 64;
122
                
123
                /**
124
                 * A set of lines.
125
                 */
126
                public final static int MULTICURVE = 128;
127
                
128
                /**
129
                 * A set of polygons.
130
                 */
131
                public final static int MULTISURFACE = 256;
132
                
133
                /**
134
                 * A set of solids.
135
                 */
136
                public final static int MULTISOLID = 512;
137
                
138
                /**
139
                 * A closed plane curve every point of which is equidistant from a fixed point within the curve.
140
                 */
141
                public final static int CIRCLE = 1024;
142
                
143
                /**
144
                 * A continuous portion (as of a circle or ellipse) of a curved line.
145
                 */
146
                public final static int ARC = 2048;
147
                
148
                /**
149
                 *  A closed plane curve generated by a point moving in such a way that the sums of its distances
150
                 *  from two fixed points is a constant : a plane section of a right circular cone that is a closed
151
                 *  curve.
152
                 */
153
                public final static int ELLIPSE=4096;
154
                                
155
                public final static int SPLINE = 8192;
156
                
157
                public final static int ELLIPTICARC = 16384;
158
                        
159
        }
160
        
161
        /**
162
         * The subtype of a geometry is related with the dimension
163
         * of the geometry, that is a combination between the
164
         * spatial dimension (2D, 2ZD, 3D) and the M coordinate
165
         * or "measure". 
166
         * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
167
         */
168
        public interface SUBTYPES{
169
                /**
170
                 * The subtype us unknown
171
                 */
172
                public final static int UNKNOWN = 0;
173
                
174
                /**
175
                 * Geometries with two dimensions
176
                 */
177
                public final static int GEOM2D = 1;
178
                
179
                /**
180
                 * Geometries with two dimensions and with a value
181
                 * for the elevation
182
                 */
183
                public final static int GEOM2DZ = 2;
184
                
185
                /**
186
                 * Geometries with three dimensions
187
                 */
188
                public final static int GEOM3D = 3;
189
                
190
                /**
191
                 * Geometries with two dimensions and with the 
192
                 * M coordinate
193
                 */
194
                public final static int GEOM2DM = 4;
195
                
196
                /**
197
                 * Geometries with three dimensions and with the
198
                 * M coordinate
199
                 */
200
                public final static int GEOM3DM = 5;
201
        }
202

    
203
        /** Initial value for new geometry types (it must not overlap with the basic ones defined in TYPES) */
204
        public static final int EXTENDED_GEOMTYPE_OFFSET = 65536; //2^16;
205

    
206
        public static int BEST = 0;
207
        /**
208
         * North
209
         */
210
        public static int N = 1;
211
        
212
        /**
213
         * North - East
214
         */
215
        public static int NE = 2;
216
        
217
        /**
218
         * East
219
         */
220
        public static int E = 3;
221
        
222
        /**
223
         * South - East
224
         */
225
        public static int SE = 4;
226
        
227
        /**
228
         * South
229
         */
230
        public static int S = 5;
231
        
232
        /**
233
         * South - West
234
         */
235
        public static int SW = 6;
236
        
237
        /**
238
         * West
239
         */
240
        public static int W = 7;
241
        
242
        /**
243
         * North - West
244
         */
245
        public static int NW = 8;
246

    
247
        public static int SELECTHANDLER=0;
248
        public static int STRETCHINGHANDLER=1;
249

    
250
        /**
251
         * If this geometry is a predefined interface then this method returns one of {@link Geometry.TYPES} contants.<br>
252
         * If this geometry is an extended type then this method returns a runtime constant that identifies its type.
253
         * By convention this value is stored in a constant called .CODE within the geometry class, for instance: Point2D.CODE.
254
         *
255
         * @return If this geometry is a predefined interface then one of {@link Geometry.TYPES} or a runtime constant if
256
         * it is an extended type.
257
         */
258
        public int getType();
259

    
260
        /**
261
         * Creates a clone of this geometry
262
         *
263
         * @return A clone of this geometry.
264
         */
265
        public Geometry cloneGeometry();
266

    
267
        /**
268
         * Returns true if this geometry intersects the rectangle passed as parameter
269
         *
270
         * @param r Rectangle.
271
         *
272
         * @return True, if <code>this</code> intersects <code>r</code>.
273
         */
274
        public boolean intersects(Rectangle2D r);
275

    
276
        /**
277
         * Used by the drawing strategies to quickly test whether this geometry
278
         * intersects with the visible rectangle.
279
         *
280
         * @param x
281
         * The minimum X coordinate
282
         * @param y
283
         * The minimum Y coordinate
284
         * @param w 
285
         * The width of the envelope
286
         * @param h 
287
         * The height of the envelope
288
         * @return true if <code>this</code> intersects the rectangle defined by the parameters
289
         */
290
        public boolean fastIntersects(double x, double y, double w, double h);
291

    
292
        /**
293
         * Returns this geometry's boundary rectangle.
294
         * @deprecated use getEnvelope.
295
         * @return Boundary rectangle.
296
         */
297
        public Rectangle2D getBounds2D();
298
        
299
        /**
300
         * <p>
301
         * Returns the minimum bounding box for this Geometry. This shall
302
         * be the coordinate region spanning the minimum and maximum value 
303
         * for each ordinate taken on by DirectPositions in this Geometry.
304
         * The simplest representation for an envelope consists of two 
305
         * DirectPositions, the first one containing all the minimums for 
306
         * each ordinate, and second one containing all the maximums.
307
         * </p>
308
         * @return 
309
         * The minimum bounding box for this Geometry
310
         */
311
        public Envelope getEnvelope();
312

    
313
        /**
314
         * Reprojects this geometry by the coordinate transformer 
315
         * passed as parameter.
316
         *
317
         * @param ct 
318
         * Coordinate Transformer.
319
         */
320
        public void reProject(ICoordTrans ct);
321

    
322
        /**
323
         * If applies an affine transformation and
324
         * returns the GeneralPathXIterator with this geometry's information
325
         * @param at
326
         * The transformation to apply
327
         * @return 
328
         * The GeneralPathXIterator with this geometry's information.
329
         */
330
        public PathIterator getPathIterator(AffineTransform at);
331

    
332
    /**
333
         * It returns the handlers of the geometry,
334
         * these they can be of two types is straightening and of selection.
335
         *
336
         * @param type
337
         * Type of handlers
338
         *
339
         * @return 
340
         * The handlers.
341
         */
342
        public Handler[] getHandlers(int type);
343

    
344
        /**
345
         * It applies an affine transformation to the geometry.
346
         * 
347
         * @param at
348
         * The transformation to apply
349
         */
350
        public void transform(AffineTransform at);
351

    
352
        /**
353
         * If applies an affine transformation and
354
         * returns the GeneralPathXIterator with this geometry's information
355
         * @param at
356
         * The affine transformation
357
         * @param flatness 
358
         * @return
359
         * The GeneralPathXIterator with this geometry's information.
360
         */
361
        PathIterator getPathIterator(AffineTransform at, double flatness);
362

    
363
        /**
364
         * Useful to have the real shape behind the scenes.
365
         * May be uses to edit it knowing it it is a Circle, Ellipse, etc
366
         * @return
367
         * The awt shape
368
         */
369
        public Shape getInternalShape();
370

    
371
        /**
372
         * Returns the largest number n such that each direct position
373
         * in a geometric set can be associated with a subset 
374
         * that has the direct position in its interior and 
375
         * is similar (isomorphic) to Rn, Euclidean n-space
376
         * @return 
377
         * The dimension
378
         */
379
        public int getDimension();
380

    
381
        /**
382
         * Returns <code>true</code> if this Geometry has no interior point 
383
         * of self-intersection or self-tangency. In mathematical 
384
         * formalisms, this means that every point in the 
385
         * interior of the object must have a metric neighborhood 
386
         * whose intersection with the object is isomorphic to an 
387
         * n-sphere, where n is the dimension of this Geometry.
388
         * @return
389
         * If the geometry is simple
390
         */
391
        public boolean isSimple();
392

    
393
        /**
394
         * Invokes a geometry operation given its index and context
395
         * @param index
396
         * Unique index of the operation. Operation code.
397
         * @return 
398
         * Object returned by the operation.
399
         */
400
        public Object invokeOperation(int index, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException;
401
        
402
        /**
403
         * Invokes a geometry operation given its name and context
404
         * @param opName 
405
         * Operation name
406
         * @return 
407
         * Object returned by the operation.
408
         */
409
        public Object invokeOperation(String opName, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException;
410

    
411
        /**
412
         * Instance of the GeometryType associated to this geometry
413
         * @return
414
         * The geometry type
415
         */
416
        public GeometryType getGeometryType();
417

    
418
        /**
419
         * Get GeneralPathIterator, to do registered operations to it.
420
         * @return 
421
         * The GeneralPathX
422
         */
423
        public GeneralPathX getGeneralPath();
424
}