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 / GeometryManager.java @ 40559

History | View | Annotate | Download (45.3 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
package org.gvsig.fmap.geom;
25

    
26
import java.awt.geom.PathIterator;
27
import java.util.List;
28

    
29
import org.gvsig.fmap.geom.aggregate.MultiCurve;
30
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
31
import org.gvsig.fmap.geom.aggregate.MultiSurface;
32
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
33
import org.gvsig.fmap.geom.exception.CreateGeometryException;
34
import org.gvsig.fmap.geom.operation.GeometryOperation;
35
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
36
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
38
import org.gvsig.fmap.geom.primitive.Curve;
39
import org.gvsig.fmap.geom.primitive.Envelope;
40
import org.gvsig.fmap.geom.primitive.GeneralPathX;
41
import org.gvsig.fmap.geom.primitive.NullGeometry;
42
import org.gvsig.fmap.geom.primitive.OrientablePrimitive;
43
import org.gvsig.fmap.geom.primitive.Point;
44
import org.gvsig.fmap.geom.primitive.Surface;
45
import org.gvsig.fmap.geom.type.GeometryType;
46
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
47
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
48

    
49
/**
50
 * This singleton provides a centralized access to gvSIG's Geometry Model.
51
 * Its responsibilities are:<br>
52
 * 
53
 * <ul>
54
 * <li>Offering a set of convenient methods for registering and retrieving
55
 * geometry types.
56
 * <li>Offering a set of convenient methods for registering and retrieving
57
 * geometry operations associated to one or more geometry types.
58
 * <li>Offering a set of convenient methods for registering and retrieving new
59
 * geometries.
60
 * </ul>
61
 * 
62
 * @author jiyarza
63
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
64
 */
65
public interface GeometryManager {
66

    
67
    public interface OPERATIONS {
68

    
69
        public final static String FROMWKT = "FromWKT";
70
        public final static String FROMWKB = "FromWKB";
71
    }
72

    
73
    /**
74
     * <p>
75
     * Registers a GeometryOperation associated to a GeometryType. Returns an
76
     * unique index that is used later to identify and invoke the operation.
77
     * </p>
78
     * <p>
79
     * By convention this index should be in a final and static variable in the
80
     * class that implements the operation. The value of this variable must be
81
     * set using the method
82
     * {@link GeometryManager#getGeometryOperationCode(String)}:<BR>
83
     * 
84
     * <pre>
85
     * 
86
     * public class MyOperation extends GeometryOperation {
87
     * 
88
     *     public static final int CODE = GeometryLocator.getGeometryManager()
89
     *         .getGeometryOperationCode(&quot;MyOperation&quot;);
90
     * }
91
     * </pre>
92
     * 
93
     * </p>
94
     * 
95
     * @param geomOpName
96
     *            Operation's unique name
97
     * @param geomOp
98
     *            Specific GeometryOperation's instance implementing this
99
     *            operation
100
     * @param geomType
101
     *            GeometryType instance to which this operation should be
102
     *            associated
103
     * @return Index assigned to this operation. This index is used later to
104
     *         access the operation.
105
     * 
106
     */
107
    public int registerGeometryOperation(String geomOpName,
108
        GeometryOperation geomOp, GeometryType geomType);
109

    
110
    /**
111
     * <p>
112
     * Registers a GeometryOperation that is common for all GeometryType
113
     * (registered yet or not). Returns an unique index that is used later to
114
     * identify and invoke the operation.
115
     * </p>
116
     * <p>
117
     * By convention this index should be in a final and static variable in the
118
     * class that implements the operation. The value of this variable must be
119
     * set using the method
120
     * {@link GeometryManager#getGeometryOperationCode(String)}:<BR>
121
     * 
122
     * <pre>
123
     * 
124
     * public class MyOperation extends GeometryOperation {
125
     * 
126
     *     public static final int CODE = GeometryLocator.getGeometryManager()
127
     *         .getGeometryOperationCode(&quot;MyOperation&quot;);
128
     * }
129
     * </pre>
130
     * 
131
     * </p>
132
     * 
133
     * @param geomOpName
134
     *            Operation's unique name
135
     * @param geomOp
136
     *            Specific GeometryOperation's instance implementing this
137
     *            operation
138
     * @return Index assigned to this operation. This index is used later to
139
     *         access the operation.
140
     */
141
    public int registerGeometryOperation(String geomOpName,
142
        GeometryOperation geomOp);
143

    
144
    /**
145
     * <p>
146
     * Registers a GeometryOperation associated to a GeometryType, that has been
147
     * specified using the type code and the subtype code. Returns an unique
148
     * index that is used later to identify and invoke the operation.
149
     * </p>
150
     * <p>
151
     * By convention this index should be in a final and static variable in the
152
     * class that implements the operation. The value of this variable must be
153
     * set using the method
154
     * {@link GeometryManager#getGeometryOperationCode(String)}:<BR>
155
     * 
156
     * <pre>
157
     * 
158
     * public class MyOperation extends GeometryOperation {
159
     * 
160
     *     public static final int CODE = GeometryLocator.getGeometryManager()
161
     *         .getGeometryOperationCode(&quot;MyOperation&quot;);
162
     * }
163
     * </pre>
164
     * 
165
     * </p>
166
     * <p>
167
     * This method is only used if you have not a reference to the GeometryType
168
     * associated to the geometry class. If you have such reference then it is
169
     * slightly faster to use the method that receives the GeometryType.<br>
170
     * </p>
171
     * 
172
     * @param geomOpName
173
     *            Operation's unique name
174
     * @param geomOp
175
     *            Specific GeometryOperation's instance implementing this
176
     *            operation
177
     * @param type
178
     *            Type of geometry. Must be a value defined in
179
     *            {@link Geometry.TYPES}
180
     * @param subType
181
     *            SubType of geometry. Must be a value defined in
182
     *            {@link Geometry.SUBTYPES}
183
     * @return Index assigned to this operation. This index is used later to
184
     *         access the operation.
185
     * @throws GeometryTypeNotSupportedException
186
     *             Returns this exception if there is not a registered geometry
187
     *             with
188
     *             these type and subtype
189
     * @throws GeometryTypeNotValidException
190
     *             Returns if the type and subtype are not valid
191
     */
192
    public int registerGeometryOperation(String geomOpName,
193
        GeometryOperation geomOp, int type, int subType)
194
        throws GeometryTypeNotSupportedException, GeometryTypeNotValidException;
195

    
196
    /**
197
     * <p>
198
     * Registers a GeometryOperation associated to all the geometries with a
199
     * concrete type. Returns an unique index that is used later to identify and
200
     * invoke the operation.<br>
201
     * </p>
202
     * <p>
203
     * By convention this index should be in a final and static variable in the
204
     * class that implements the operation. The value of this variable must be
205
     * set using the method
206
     * {@link GeometryManager#getGeometryOperationCode(String)}:<BR>
207
     * 
208
     * <pre>
209
     * 
210
     * public class MyOperation extends GeometryOperation {
211
     * 
212
     *     public static final int CODE = GeometryLocator.getGeometryManager()
213
     *         .getGeometryOperationCode(&quot;MyOperation&quot;);
214
     * }
215
     * </pre>
216
     * 
217
     * </p>
218
     * 
219
     * @param geomOpName
220
     *            Operation's unique name
221
     * @param geomOp
222
     *            Specific GeometryOperation's instance implementing this
223
     *            operation
224
     * @param type
225
     *            Type of geometry. Must be a value defined in
226
     *            {@link Geometry.TYPES}
227
     * @return Index assigned to this operation. This index is used later to
228
     *         access the operation.
229
     */
230
    public int registerGeometryOperation(String geomOpName,
231
        GeometryOperation geomOp, int type);
232
    
233
    /**
234
     * <p>
235
     * Registers a GeometryOperation associated to all the geometries which
236
     * super type matches with a concrete type. Returns an unique index that 
237
     * is used later to identify and invoke the operation.<br>
238
     * </p>
239
     * <p>
240
     * By convention this index should be in a final and static variable in the
241
     * class that implements the operation. The value of this variable must be
242
     * set using the method
243
     * {@link GeometryManager#getGeometryOperationCode(String)}:<BR>
244
     * 
245
     * <pre>
246
     * 
247
     * public class MyOperation extends GeometryOperation {
248
     * 
249
     *     public static final int CODE = GeometryLocator.getGeometryManager()
250
     *         .getGeometryOperationCode(&quot;MyOperation&quot;);
251
     * }
252
     * </pre>
253
     * 
254
     * </p>
255
     * 
256
     * @param geomOpName
257
     *            Operation's unique name
258
     * @param geomOp
259
     *            Specific GeometryOperation's instance implementing this
260
     *            operation
261
     * @param superType
262
     *            super type of geometries that is used to register
263
     *            the operation. Must be a value defined in
264
     *            {@link Geometry.TYPES}
265
     * @return Index assigned to this operation. This index is used later to
266
     *         access the operation.
267
     */
268
    public int registerGeometryOperationBySuperType(String geomOpName,
269
        GeometryOperation geomOp, int superType);
270
    
271
    /**
272
     * <p>
273
     * Registers a GeometryOperation associated to all the geometries which
274
     * super subType matches with a concrete subType. Returns an unique index that 
275
     * is used later to identify and invoke the operation.<br>
276
     * </p>
277
     * <p>
278
     * By convention this index should be in a final and static variable in the
279
     * class that implements the operation. The value of this variable must be
280
     * set using the method
281
     * {@link GeometryManager#getGeometryOperationCode(String)}:<BR>
282
     * 
283
     * <pre>
284
     * 
285
     * public class MyOperation extends GeometryOperation {
286
     * 
287
     *     public static final int CODE = GeometryLocator.getGeometryManager()
288
     *         .getGeometryOperationCode(&quot;MyOperation&quot;);
289
     * }
290
     * </pre>
291
     * 
292
     * </p>
293
     * 
294
     * @param geomOpName
295
     *            Operation's unique name
296
     * @param geomOp
297
     *            Specific GeometryOperation's instance implementing this
298
     *            operation
299
     * @param superSubType
300
     *            super subType of geometries that is used to register
301
     *            the operation. Must be a value defined in
302
     *            {@link Geometry.SUBTYPES}
303
     * @return Index assigned to this operation. This index is used later to
304
     *         access the operation.
305
     */
306
    public int registerGeometryOperationBySuperSubType(String geomOpName,
307
        GeometryOperation geomOp, int superSubType);
308

    
309
    /**
310
     * <p>
311
     * Registers a GeometryOperation associated to all the geometries with a
312
     * concrete subtype. Returns an unique index that is used later to identify
313
     * and invoke the operation.<br>
314
     * </p>
315
     * <p>
316
     * By convention this index should be in a final and static variable in the
317
     * class that implements the operation. The value of this variable must be
318
     * set using the method
319
     * {@link GeometryManager#getGeometryOperationCode(String)}:<BR>
320
     * 
321
     * <pre>
322
     * 
323
     * public class MyOperation extends GeometryOperation {
324
     * 
325
     *     public static final int CODE = GeometryLocator.getGeometryManager()
326
     *         .getGeometryOperationCode(&quot;MyOperation&quot;);
327
     * }
328
     * </pre>
329
     * 
330
     * </p>
331
     * 
332
     * @param geomOpName
333
     *            Operation's unique name
334
     * @param geomOp
335
     *            Specific GeometryOperation's instance implementing this
336
     *            operation
337
     * @param subType
338
     *            SubType of geometry. Must be a value defined in
339
     *            {@link Geometry.SUBTYPES}
340
     * @return Index assigned to this operation. This index is used later to
341
     *         access the operation.
342
     */
343
    public int registerGeometryOperationBySubtype(String geomOpName,
344
        GeometryOperation geomOp, int subType);
345

    
346
    /**
347
     * <p>
348
     * Registers a GeometryType instance. 
349
     * </p>
350
     * 
351
     * @param geometryType
352
     *            A {@link GeometryType} instance to create {@link Geometry} objects
353
     */
354
    public void registerGeometryType(GeometryType geometryType);
355
    
356
    /**
357
     * <p>
358
     * Registers a Geometry implementation class with a predefined geometry type
359
     * and returns the associated GeometryType instance. Available predefined
360
     * types are defined in {@link Geometry.TYPES} and the subtypes are defined
361
     * in {@link Geometry.SUBTYPES}.
362
     * </p>
363
     * <p>
364
     * How to register a geometry class with a predefined type:
365
     * 
366
     * <pre>
367
     * 
368
     * GeometryType geomType = GeometryLocator.getGeometryManager()
369
     *     .registerBasicGeometryType(Point2D.class, &quot;Point2D&quot;, Geometry.TYPES.POINT,
370
     *         Geometry.SYBTYPES.GEOM2D);
371
     * </pre>
372
     * 
373
     * </p>
374
     * 
375
     * @param geomClass
376
     *            Geometry subclass. It must not be null and must implement
377
     *            Geometry, otherwise an exception
378
     *            is raised.
379
     * @param name
380
     *            Symbolic name for the geometry type, it can be null. If it is
381
     *            null then the symbolic name
382
     *            will be the simple class name.
383
     * @param type
384
     *            Type of geometry. Must be a value defined in
385
     *            {@link Geometry.TYPES}
386
     * @param subType
387
     *            SubType of geometry. Must be a value defined in
388
     *            {@link Geometry.SUBTYPES}
389
     * @return Instance of GeometryType associated to the Geometry
390
     *         implementation class
391
     *         geomClass
392
     * @throws IllegalArgumentException
393
     *             If geomClass is null or does not implement Geometry
394
     */
395
    public GeometryType registerGeometryType(Class geomClass, String name,
396
        int type, int subType);
397
    
398
    /**
399
     * <p>
400
     * Registers a Geometry implementation class with a predefined geometry type
401
     * and returns the associated GeometryType instance. Available predefined
402
     * types are defined in {@link Geometry.TYPES} and the subtypes are defined
403
     * in {@link Geometry.SUBTYPES}.    
404
     * </p>
405
     * <p>
406
     * It adds also the super type and the super subType of the geometry, that
407
     * can be used to check if the type (or the subtype) inherits of other 
408
     * type (or subType)
409
     * </p>
410
     * <p>
411
     * How to register a geometry class with a predefined type:
412
     * 
413
     * <pre>
414
     * 
415
     * GeometryType geomType = GeometryLocator.getGeometryManager()
416
     *     .registerBasicGeometryType(Arc3D.class, &quot;Arc3D&quot;, Geometry.TYPES.ARC,
417
     *         Geometry.SYBTYPES.GEOM3D, Geometry.TYPES.CURVE, Geometry.SYBTYPES.GEOM2D);
418
     * </pre>
419
     * 
420
     * </p>
421
     * 
422
     * @param geomClass
423
     *            Geometry subclass. It must not be null and must implement
424
     *            Geometry, otherwise an exception
425
     *            is raised.
426
     * @param name
427
     *            Symbolic name for the geometry type, it can be null. If it is
428
     *            null then the symbolic name
429
     *            will be the simple class name.
430
     * @param type
431
     *            Type of geometry. Must be a value defined in
432
     *            {@link Geometry.TYPES}
433
     * @param subType
434
     *            SubType of geometry. Must be a value defined in
435
     *            {@link Geometry.SUBTYPES}
436
     * @param superType
437
     *              Super type of a geometry. Must be a value defined in
438
     *            {@link Geometry.TYPES}
439
     * @param superSubType
440
     *             Super subType of a geometry. Must be a value defined in
441
     *            {@link Geometry.SUBTYPES}
442
     * @return Instance of GeometryType associated to the Geometry
443
     *         implementation class
444
     *         geomClass
445
     * @throws IllegalArgumentException
446
     *             If geomClass is null or does not implement Geometry
447
     */
448
    public GeometryType registerGeometryType(Class geomClass, String name,
449
        int type, int subType, int superType, int superSubType);
450
    
451
    /**
452
     * <p>
453
     * Registers a Geometry implementation class with a predefined geometry type
454
     * and returns the associated GeometryType instance. Available predefined
455
     * types are defined in {@link Geometry.TYPES} and the subtypes are defined
456
     * in {@link Geometry.SUBTYPES}.    
457
     * </p>
458
     * <p>
459
     * It adds also the super type of the geometry, that can be used to 
460
     * check if the type inherits of other type.
461
     * </p>
462
     * <p>
463
     * How to register a geometry class with a predefined type:
464
     * 
465
     * <pre>
466
     * 
467
     * GeometryType geomType = GeometryLocator.getGeometryManager()
468
     *     .registerBasicGeometryType(Arc3D.class, &quot;Arc3D&quot;, Geometry.TYPES.ARC,
469
     *         Geometry.SYBTYPES.GEOM3D, Geometry.TYPES.CURVE);
470
     * </pre>
471
     * 
472
     * </p>
473
     * 
474
     * @param geomClass
475
     *            Geometry subclass. It must not be null and must implement
476
     *            Geometry, otherwise an exception
477
     *            is raised.
478
     * @param name
479
     *            Symbolic name for the geometry type, it can be null. If it is
480
     *            null then the symbolic name
481
     *            will be the simple class name.
482
     * @param type
483
     *            Type of geometry. Must be a value defined in
484
     *            {@link Geometry.TYPES}
485
     * @param subType
486
     *            SubType of geometry. Must be a value defined in
487
     *            {@link Geometry.SUBTYPES}
488
     * @param superType
489
     *              Super type of a geometry. Must be a value defined in
490
     *            {@link Geometry.TYPES}   
491
     * @return Instance of GeometryType associated to the Geometry
492
     *         implementation class
493
     *         geomClass
494
     * @throws IllegalArgumentException
495
     *             If geomClass is null or does not implement Geometry
496
     */
497
    public GeometryType registerGeometryType(Class geomClass, String name,
498
        int type, int subType, int superType);
499
    
500
    /**
501
     * <p>
502
     * Registers a Geometry implementation class with a predefined geometry type
503
     * and returns the associated GeometryType instance. Available predefined
504
     * types are defined in {@link Geometry.TYPES} and the subtypes are defined
505
     * in {@link Geometry.SUBTYPES}.    
506
     * </p>
507
     * <p>
508
     * It adds also the super types and the super subTypes of the geometry, that
509
     * can be used to check if the type (or the subtype) inherits of other 
510
     * types (or subTypes)
511
     * </p>
512
     * <p>
513
     * How to register a geometry class with a predefined type:
514
     * 
515
     * <pre>
516
     * 
517
     * GeometryType geomType = GeometryLocator.getGeometryManager()
518
     *     .registerBasicGeometryType(Circle3DM.class, &quot;Circle3DM&quot;, Geometry.TYPES.CIRCLE,
519
     *         Geometry.SYBTYPES.GEOM3DM,
520
     *         new int[]{Geometry.TYPES.CURVE, Geometry.TYPES.GEOMETRY},
521
     *         new int[]{Geometry.SYBTYPES.GEOM2D, Geometry.SYBTYPES.GEOM3D});
522
     * </pre>
523
     * 
524
     * </p>
525
     * 
526
     * @param geomClass
527
     *            Geometry subclass. It must not be null and must implement
528
     *            Geometry, otherwise an exception
529
     *            is raised.
530
     * @param name
531
     *            Symbolic name for the geometry type, it can be null. If it is
532
     *            null then the symbolic name
533
     *            will be the simple class name.
534
     * @param type
535
     *            Type of geometry. Must be a value defined in
536
     *            {@link Geometry.TYPES}
537
     * @param subType
538
     *            SubType of geometry. Must be a value defined in
539
     *            {@link Geometry.SUBTYPES}
540
     * @param superTypes
541
     *              List of the super types of a geometry. Must be a value defined in
542
     *            {@link Geometry.TYPES}
543
     * @param superSubTypes
544
     *             List of the super subType of a geometry. Must be a value defined in
545
     *            {@link Geometry.SUBTYPES}
546
     * @return Instance of GeometryType associated to the Geometry
547
     *         implementation class
548
     *         geomClass
549
     * @throws IllegalArgumentException
550
     *             If geomClass is null or does not implement Geometry
551
     */
552
    public GeometryType registerGeometryType(Class geomClass, String name,
553
        int type, int subType, int[] superTypes, int superSubTypes[]);
554
    
555
    /**
556
     * <p>
557
     * Registers a Geometry implementation class with a predefined geometry type
558
     * and returns the associated GeometryType instance. Available predefined
559
     * types are defined in {@link Geometry.TYPES} and the subtypes are defined
560
     * in {@link Geometry.SUBTYPES}.    
561
     * </p>
562
     * <p>
563
     * It adds also the super types and the super subTypes of the geometry, that
564
     * can be used to check if the type inherits of other types.
565
     * </p>
566
     * <p>
567
     * How to register a geometry class with a predefined type:
568
     * 
569
     * <pre>
570
     * 
571
     * GeometryType geomType = GeometryLocator.getGeometryManager()
572
     *     .registerBasicGeometryType(Circle2D.class, &quot;Circle2DM&quot;, Geometry.TYPES.CIRCLE,
573
     *         Geometry.SYBTYPES.GEOM2D,
574
     *         new int[]{Geometry.TYPES.CURVE, Geometry.TYPES.SURFACE});        
575
     * </pre>
576
     * 
577
     * </p>
578
     * 
579
     * @param geomClass
580
     *            Geometry subclass. It must not be null and must implement
581
     *            Geometry, otherwise an exception
582
     *            is raised.
583
     * @param name
584
     *            Symbolic name for the geometry type, it can be null. If it is
585
     *            null then the symbolic name
586
     *            will be the simple class name.
587
     * @param type
588
     *            Type of geometry. Must be a value defined in
589
     *            {@link Geometry.TYPES}
590
     * @param subType
591
     *            SubType of geometry. Must be a value defined in
592
     *            {@link Geometry.SUBTYPES}
593
     * @param superTypes
594
     *              List of the super types of a geometry. Must be a value defined in
595
     *            {@link Geometry.TYPES}
596
     * @return Instance of GeometryType associated to the Geometry
597
     *         implementation class
598
     *         geomClass
599
     * @throws IllegalArgumentException
600
     *             If geomClass is null or does not implement Geometry
601
     */
602
    public GeometryType registerGeometryType(Class geomClass, String name,
603
        int type, int subType, int[] superTypes);
604

    
605
    /**
606
     * <p>
607
     * Registers a Geometry implementation class with a predefined geometry type
608
     * and returns the associated GeometryType instance. Available predefined
609
     * types are defined in {@link Geometry.TYPES} and the subtypes are defined
610
     * in {@link Geometry.SUBTYPES}.
611
     * </p>
612
     * <p>
613
     * In this case the symbolic name will be the geometry's simple class name
614
     * </p>
615
     * How to register a new geometry type:
616
     * 
617
     * <pre>
618
     * 
619
     * GeometryType geomType = GeometryLocator.getGeometryManager()
620
     *     .registerBasicGeometryType(Point2D.class, Geometry.TYPES.POINT,
621
     *         Geometry.SYBTYPES.GEOM2D);
622
     * </pre>
623
     * 
624
     * @param geomClass
625
     *            Geometry implementation class. It must not be null and must
626
     *            implement Geometry,
627
     *            otherwise an exception is thrown.
628
     * @param type
629
     *            Type of geometry. Must be a value defined in
630
     *            {@link Geometry.TYPES}
631
     * @param subType
632
     *            SubType of geometry. Must be a value defined in
633
     *            {@link Geometry.SUBTYPES}
634
     * @return Instance of GeometryType associated to the Geometry
635
     *         implementation class
636
     * @throws IllegalArgumentException
637
     *             If geomClass is null or does not implement Geometry
638
     */
639
    public GeometryType registerGeometryType(Class geomClass, int type,
640
        int subType);
641

    
642
    /**
643
     * <p>
644
     * Returns an instance of GeometryType given the Geometry type and the
645
     * subtype.
646
     * </p>
647
     * 
648
     * @param type
649
     *            Type of geometry. Must be a value defined in
650
     *            {@link Geometry.TYPES}
651
     * @param subType
652
     *            SubType of geometry. Must be a value defined in
653
     *            {@link Geometry.SUBTYPES}
654
     * @return Instance of GeometryType associated to the type and the subtype
655
     * @throws GeometryTypeNotSupportedException
656
     *             Returns this exception if there is not a registered geometry
657
     *             with
658
     *             these type and subtype
659
     * @throws GeometryTypeNotValidException
660
     *             Returns if the type and subtype are not valid
661
     */
662
    public GeometryType getGeometryType(int type, int subType)
663
        throws GeometryTypeNotSupportedException, GeometryTypeNotValidException;
664

    
665
    /**
666
     * <p>
667
     * This method creates a {@link Geometry} with the type specified by this
668
     * GeometryType. The geometry is empty, and all the internal attributes must
669
     * be assigned to a value when the geometry has been created.
670
     * </p>
671
     * <p>
672
     * This example creates a point2D and sets the coordinates to 1,1:
673
     * 
674
     * <pre>
675
     * Point point =
676
     *     (Point) GeometryLocator.getGeometryManager().create(GEOMETRY.TYPES.POINT,
677
     *         GEOMETRY.SUBTYPES.GEOM2D);
678
     * point.setX(1);
679
     * point.setY(1);
680
     * </pre>
681
     * 
682
     * </p>
683
     * 
684
     * @param geomType
685
     *            The geometry type
686
     * @return
687
     *         A instance of a geometry.
688
     * @throws CreateGeometryException
689
     *             This exception is thrown when the manager can not create
690
     *             the geometry.
691
     */
692
    public Geometry create(GeometryType geomType)
693
        throws CreateGeometryException;
694

    
695
    /**
696
     * <p>
697
     * Creates a Envelope with a concrete subtype. The envelope is empty and it
698
     * have to be filled with the corners once has been created.
699
     * </p>
700
     * 
701
     * @param subType
702
     *            SubType of envelope. Must be a value defined in
703
     *            {@link Geometry.SUBTYPES}
704
     * @return
705
     *         A Envelope
706
     * @throws CreateEnvelopeException
707
     *             If it is not possible to create the envelope.
708
     */
709
    public Envelope createEnvelope(int subType) throws CreateEnvelopeException;
710

    
711
    /**
712
     * <p>
713
     * Creates a Envelope with a concrete subtype. It sets the values for the
714
     * lower corner and the upper corner (in 2D) using the method parameters.
715
     * </p>
716
     * 
717
     * @param minX
718
     *            The minimum value for the X coordinate.
719
     * @param minY
720
     *            The minimum value for the Y coordinate.
721
     * @param maxX
722
     *            The maximum value for the X coordinate.
723
     * @param maxY
724
     *            The maximum value for the Y coordinate.
725
     * @param subType
726
     *            SubType of envelope. Must be a value defined in
727
     *            {@link Geometry.SUBTYPES}
728
     * @return
729
     * @throws CreateEnvelopeException
730
     */
731
    public Envelope createEnvelope(double minX, double minY, double maxX,
732
        double maxY, int subType) throws CreateEnvelopeException;
733

    
734
    /**
735
     * <p>
736
     * This method creates a {@link Geometry} with the type specified by this
737
     * name. If a geometry with this name doesn't exist, a
738
     * {@link IllegalArgumentException} is thrown. The geometry is empty, and
739
     * all the internal attributes must be assigned to a value when the geometry
740
     * has been created.
741
     * </p>
742
     * <p>
743
     * This example creates a point2D and sets the coordinates to 1,1: It
744
     * supposes that there is a Point2D class with name "Point2D".
745
     * </p>
746
     * 
747
     * <pre>
748
     * Point point = (Point) GeometryLocator.getGeometryManager().create(&quot;Point2D&quot;);
749
     * point.setX(1);
750
     * point.setY(1);
751
     * </pre>
752
     * 
753
     * @param name
754
     *            The name of the geometry type
755
     * @return
756
     *         A instance of a geometry.
757
     * @throws CreateGeometryException
758
     *             This exception is thrown when the manager can not create
759
     *             the geometry.
760
     */
761
    public Geometry create(String name) throws CreateGeometryException;
762

    
763
    /**
764
     * Create a geometry from a WKT definition.
765
     * 
766
     * This is a utility method to wrap the invocation to the operation
767
     * {@link OPERATIONS#FROMWKT}.
768
     * 
769
     * @param wkt
770
     *            geometry in Well-known text format
771
     * 
772
     * @return the geometry as a Geometry
773
     * 
774
     * @throws CreateGeometryException
775
     * @throws GeometryException
776
     */
777
    public Geometry createFrom(String wkt, String srs)
778
        throws CreateGeometryException, GeometryException;
779

    
780
    public Geometry createFrom(String wkt) throws CreateGeometryException,
781
        GeometryException;
782

    
783
    /**
784
     * Create a geometry from a WKB definition.
785
     * 
786
     * This is a utility method to wrap the invocation to the operation
787
     * {@link OPERATIONS#FROMWKB}.
788
     * 
789
     * @param wkb
790
     *            geometry in well-known binary format
791
     * 
792
     * @return the geometry as a Geometry
793
     * 
794
     * @throws CreateGeometryException
795
     * @throws GeometryException
796
     */
797
    public Geometry createFrom(byte[] wkb) throws CreateGeometryException,
798
        GeometryException;
799

    
800
    /**
801
     * <p>
802
     * This method creates a {@link Geometry} with a concrete type and subtype.
803
     * The geometry is empty, and all the internal attributes must be assigned
804
     * to a value when the geometry has been created.
805
     * </p>
806
     * <p>
807
     * This example creates a point2D and sets the coordinates to 1,1. It
808
     * supposes that there is a Point2D class with the id 1.
809
     * </p>
810
     * 
811
     * <pre>
812
     * Point point =
813
     *     (Point) GeometryLocator.getGeometryManager().create(Geometry.TYPES.POINT,
814
     *         Geometry.SYBTYPES.GEOM2D);
815
     * point.setX(1);
816
     * point.setY(1);
817
     * </pre>
818
     * 
819
     * @param type
820
     *            Type of geometry. Must be a value defined in
821
     *            {@link Geometry.TYPES}
822
     * @param subType
823
     *            SubType of geometry. Must be a value defined in
824
     *            {@link Geometry.SUBTYPES}
825
     * @return
826
     *         A instance of a geometry.
827
     * @throws CreateGeometryException
828
     *             This exception is thrown when the manager can not create
829
     *             the geometry.
830
     */
831
    public Geometry create(int type, int subType)
832
        throws CreateGeometryException;
833

    
834
    /**
835
     * <p>
836
     * It creates a null geometry with a concrete subtype.
837
     * <p>
838
     * 
839
     * @param subType
840
     *            SubType of geometry. Must be a value defined in
841
     *            {@link Geometry.SUBTYPES}
842
     * @return
843
     *         A NullGeometry
844
     * @throws CreateGeometryException
845
     *             This exception is thrown when the manager can not create
846
     *             the geometry.
847
     */
848
    public NullGeometry createNullGeometry(int subType)
849
        throws CreateGeometryException;
850

    
851
    /**
852
     * <p>
853
     * Create a new point with a concrete type and sets the value for the X and
854
     * the Y.
855
     * </p>
856
     * 
857
     * @param x
858
     *            The X coordinate
859
     * @param y
860
     *            The y coordinate
861
     * @param subType
862
     *            SubType of geometry. Must be a value defined in
863
     *            {@link Geometry.SUBTYPES}
864
     * @throws CreateGeometryException
865
     *             This exception is thrown when the manager can not create
866
     *             the geometry.
867
     * @return
868
     *         The Point
869
     */
870
    public Point createPoint(double x, double y, int subType)
871
        throws CreateGeometryException;
872

    
873
    /**
874
     * Create a new curve with a concrete type. Use later addVertex to add
875
     * vertex to te curve. 
876
     * 
877
     * @param subType SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
878
     * @return a curve
879
     * @throws CreateGeometryException
880
     *             This exception is thrown when the manager can not create
881
     *             the geometry.
882
     */
883
    public Curve createCurve(int subType) throws CreateGeometryException;
884

    
885

    
886
    /**
887
     * Create a new multicurve with a concrete type
888
     * Use addPrimitive and addVertex to populate the multicurve.
889
     * 
890
     * @param subType
891
     *            SubType of geometry. Must be a value defined in
892
     *            {@link Geometry.SUBTYPES}
893
     * @return A multicurve
894
     * @throws CreateGeometryException
895
     *             This exception is thrown when the manager can not create the
896
     *             geometry.
897
     */
898
    public MultiCurve createMultiCurve(int subType) throws CreateGeometryException;
899

    
900
    /**
901
     * Create a new surface with a concrete type.
902
     * Use later addVertex to add vertex to te surface-
903
     * 
904
     * @param subType
905
     *            SubType of geometry. Must be a value defined in
906
     *            {@link Geometry.SUBTYPES}
907
     * @return
908
     *         A surface
909
     * @throws CreateGeometryException
910
     *             This exception is thrown when the manager can not create
911
     *             the geometry.
912
     */
913
    public Surface createSurface(int subType)
914
        throws CreateGeometryException;
915

    
916
    /**
917
     * Create a new multisurface with a concrete type
918
     * Use later addPrimitive and addvertex to populate.
919
     * 
920
     * @param subType
921
     *            SubType of geometry. Must be a value defined in
922
     *            {@link Geometry.SUBTYPES}
923
     * @return A multisurface
924
     * @throws CreateGeometryException
925
     *             This exception is thrown when the manager can not create the
926
     *             geometry.
927
     */
928
    public MultiSurface createMultiSurface(int subType) throws CreateGeometryException;
929

    
930
    /**
931
     * <p>
932
     * Returns an operation given the Geometry type, the Geometry subtype and
933
     * and the operation code. If opCode corresponds to a common operation (a
934
     * common operation is an operation registered for all geometries), then
935
     * this method returns the common operation.
936
     * </p>
937
     * <p>
938
     * For better performance, if you need to call an operation multiple times,
939
     * use this method only once and keep the returned object in a local
940
     * variable over which you can iterate. For instance:
941
     * 
942
     * <pre>
943
     * // Get the operation you need
944
     * GeometryManager gm = GeometryLocator.getGeometryManager()
945
     * GeometryOperation geomOp = null;
946
     * try {
947
     *    geomOp = gm.getGeometryOperation(Draw2D.CODE, Geometry.TYPES.POINT, 
948
     *    Geometry.SUBTYPES.GEOM2D);
949
     * } catch (GeometryTypeNotSupportedException gtnse) {
950
     *    // treat exception
951
     * } catch (GeometryOperationNotSupportedException gonse) {
952
     *    // treat exception
953
     * }
954
     * 
955
     *  // Fill the operation context with required params
956
     * GeometryOperationContext ctx = new GeometryOperationContext();
957
     * 
958
     *  // Here is the main loop where you call the operation
959
     * for (int i=0; i<myGeometries.length; i++) {
960
     *    Object result = geomOp.invoke(myGeometries[i], ctx);
961
     * }
962
     * </pre>
963
     * 
964
     * </p>
965
     * 
966
     * @param opCode
967
     *            The operation code
968
     * @param type
969
     *            Type of geometry. Must be a value defined in
970
     *            {@link Geometry.TYPES}
971
     * @param subType
972
     *            SubType of geometry. Must be a value defined in
973
     *            {@link Geometry.SUBTYPES}
974
     * @return Geometry operation
975
     * @throws GeometryTypeNotSupportedException
976
     *             Returns this exception if there is not a registered geometry
977
     *             with
978
     *             these type and subtype
979
     * @throws GeometryTypeNotValidException
980
     *             Returns this exception if the type and subtype are not valid
981
     * @throws GeometryOperationNotSupportedException
982
     *             Returns this exception if there is not a registered operation
983
     *             with
984
     *             this operation code
985
     */
986
    public GeometryOperation getGeometryOperation(int opCode, int type,
987
        int subType) throws GeometryTypeNotSupportedException,
988
        GeometryOperationNotSupportedException, GeometryTypeNotValidException;
989

    
990
    /**
991
     * <p>
992
     * Returns an common operation with given operation code. A common operation
993
     * is an operation registered for all geometries.
994
     * </p>
995
     * <p>
996
     * For better performance, if you need to call an operation multiple times,
997
     * use this method only once and keep the returned object in a local
998
     * variable over which you can iterate. For instance:
999
     * 
1000
     * <pre>
1001
     * // Get the operation you need
1002
     * GeometryManager gm = GeometryLocator.getGeometryManager()
1003
     * GeometryOperation geomOp = null;
1004
     * try {
1005
     *    geomOp = gm.getGeometryOperation(FromWKB.CODE);
1006
     * } catch (GeometryOperationNotSupportedException gonse) {
1007
     *    // treat exception
1008
     * }
1009
     * 
1010
     *  // Fill the operation context with required params
1011
     * FromWKBGeometryOperationContext ctx = new FromWKBGeometryOperationContext();
1012
     * 
1013
     *  // Here is the main loop where you call the operation
1014
     * for (int i=0; i<myGeometriesWKB.length; i++) {
1015
     *    ctx.setData(myGeometriesWKB[i]);
1016
     *    Object result = geomOp.invoke(null, ctx);
1017
     * }
1018
     * </pre>
1019
     * 
1020
     * </p>
1021
     * 
1022
     * @param opCode
1023
     *            The operation code
1024
     * @return Geometry operation
1025
     * @throws GeometryOperationNotSupportedException
1026
     *             Returns this exception if there is not a registered operation
1027
     *             with
1028
     *             this operation code
1029
     */
1030
    public GeometryOperation getGeometryOperation(int opCode)
1031
        throws GeometryOperationNotSupportedException;
1032

    
1033
    /**
1034
     * <p>
1035
     * Invokes an operation given its code, the geometry and the operation
1036
     * context holding the parameters required for the operation.
1037
     * </p>
1038
     * 
1039
     * @param opCode
1040
     *            Operation code.
1041
     * @param geom
1042
     *            Geometry to which apply the operation
1043
     * @param ctx
1044
     *            Context holding the operation parameters
1045
     * @return
1046
     *         The object returned by an operation, depends on each operation.
1047
     */
1048
    public Object invokeOperation(int opCode, Geometry geom,
1049
        GeometryOperationContext ctx)
1050
        throws GeometryOperationNotSupportedException,
1051
        GeometryOperationException;
1052

    
1053
    /**
1054
     * <p>
1055
     * Invokes an operation given its code, the geometry and the operation
1056
     * context holding the parameters required for the operation.
1057
     * </p>
1058
     * 
1059
     * @param geomOpName
1060
     *            Operation name.
1061
     * @param geom
1062
     *            Geometry to which apply the operation
1063
     * @param ctx
1064
     *            Context holding the operation parameters
1065
     * @return
1066
     *         The object returned by an operation, depends on each operation.
1067
     */
1068
    public Object invokeOperation(String geomOpName, Geometry geom,
1069
        GeometryOperationContext ctx)
1070
        throws GeometryOperationNotSupportedException,
1071
        GeometryOperationException;
1072

    
1073
    /**
1074
     * <p>
1075
     * Invokes an operation given its code, and the operation context holding
1076
     * the parameters required for the operation.
1077
     * </p>
1078
     * 
1079
     * @param geomOpName
1080
     *            Operation name.
1081
     * @param ctx
1082
     *            Context holding the operation parameters
1083
     * @return
1084
     *         The object returned by an operation, depends on each operation.
1085
     */
1086
    public Object invokeOperation(String geomOpName,
1087
        GeometryOperationContext ctx)
1088
        throws GeometryOperationNotSupportedException,
1089
        GeometryOperationException;
1090

    
1091
    /**
1092
     * <p>
1093
     * Registers the unique name of one operation. If it already exists then
1094
     * this method does nothing but returning the name's corresponding index.
1095
     * </p>
1096
     * <p>
1097
     * By convention this method is used to set the value of the final and
1098
     * static variable that is located in the classes that implements the
1099
     * operation:<BR>
1100
     * 
1101
     * <pre>
1102
     * 
1103
     * public class MyOperation extends GeometryOperation {
1104
     * 
1105
     *     public static final int CODE = GeometryLocator.getGeometryManager()
1106
     *         .getGeometryOperationCode(&quot;MyOperation&quot;);
1107
     * }
1108
     * </pre>
1109
     * 
1110
     * </p>
1111
     * 
1112
     * @param geomOpName
1113
     *            Name used to register the geometry operation
1114
     * @return
1115
     *         Index assigned to the operation name passed as parameter
1116
     */
1117
    public int getGeometryOperationCode(String geomOpName);
1118

    
1119
    /**
1120
     * Returns a list with the name of the operations that have been
1121
     * registered.
1122
     * 
1123
     * @return
1124
     *         A list of the registered operations.
1125
     */
1126
    public List getGeometryOperationNames();
1127

    
1128
    /**
1129
     * Returns the flatness used to convert a curve is a set
1130
     * of points.
1131
     * 
1132
     * @return
1133
     *         The flatness.
1134
     */
1135
    public double getFlatness();
1136

    
1137
    /**
1138
     * Sets the application flatness.
1139
     * 
1140
     * @param flatness
1141
     *            The flatness to set
1142
     */
1143
    public void setFlatness(double flatness);
1144
    
1145
    /**
1146
     * Create a memory spatial index with the default implementation.
1147
     * 
1148
     * @return a new SpatialIndex
1149
     */
1150
    public SpatialIndex createDefaultMemorySpatialIndex() throws GeometryException;
1151
    
1152

    
1153
    /**
1154
     * Create a GeneralPathX to populate a geometry.
1155
     * This method is deprecated, instead use OrientablePrimitive#addVertex(Point) to add vertex to 
1156
     * primitive geometries or {@link MultiPrimitive#addPrimitive(org.gvsig.fmap.geom.primitive.Primitive)} to add geometries to an aggregate.
1157
     * 
1158
     * @param rule
1159
     * @param initialCapacity
1160
     * @param pathIterator , can be null
1161
     * @return a GeneralPathX
1162
     * @deprecated use method of Geometry to handle this 
1163
     * @see OrientablePrimitive#addVertex(Point) or {@link MultiPrimitive#addPrimitive(org.gvsig.fmap.geom.primitive.Primitive)}
1164
     * 
1165
     */
1166
    public GeneralPathX createGeneralPath(int rule, PathIterator pathIterator);
1167

    
1168
        /**
1169
         * <p>
1170
         * Create a new curve with a concrete type and sets the value for the
1171
         * coordinates using a GeneralPathX.
1172
         * </p>
1173
         * 
1174
         * @param generalPathX
1175
         *            It is used to set the values for the X and Y coordinates.
1176
         * @param subType
1177
         *            SubType of geometry. Must be a value defined in
1178
         *            {@link Geometry.SUBTYPES}
1179
         * @return
1180
         *         A curve
1181
         * @throws CreateGeometryException
1182
         *             This exception is thrown when the manager can not create
1183
         *             the geometry.
1184
         * @deprecated use {@link #createCurve(int)} and OrientablePrimitive#addVertex(Point) 
1185
         */
1186
        public Curve createCurve(GeneralPathX generalPathX, int subType)
1187
            throws CreateGeometryException;
1188
        
1189
        /**
1190
         * <p>
1191
         * Create a new multicurve with a concrete type and sets the value for the
1192
         * coordinates using a GeneralPathX.
1193
         * </p>
1194
         * 
1195
         * @param generalPathX
1196
         *            It is used to set the values for the X and Y coordinates.
1197
         * @param subType
1198
         *            SubType of geometry. Must be a value defined in
1199
         *            {@link Geometry.SUBTYPES}
1200
         * @return A multicurve
1201
         * @throws CreateGeometryException
1202
         *             This exception is thrown when the manager can not create the
1203
         *             geometry.
1204
         * @deprecated use {@link #createMultiCurve(int)} and {@link MultiPrimitive#addPrimitive(org.gvsig.fmap.geom.primitive.Primitive)}
1205
         */
1206
        public MultiCurve createMultiCurve(GeneralPathX generalPathX, int subType)
1207
                throws CreateGeometryException;
1208
        
1209
        /**
1210
         * <p>
1211
         * Create a new surface with a concrete type and sets the value for the
1212
         * coordinates using a GeneralPathX.
1213
         * </p>
1214
         * 
1215
         * @param generalPathX
1216
         *            It is used to set the values for the X and Y coordinates.
1217
         * @param subType
1218
         *            SubType of geometry. Must be a value defined in
1219
         *            {@link Geometry.SUBTYPES}
1220
         * @return
1221
         *         A surface
1222
         * @throws CreateGeometryException
1223
         *             This exception is thrown when the manager can not create
1224
         *             the geometry.
1225
         * @deprecated use {@link #createSurface(int)} and OrientablePrimitive#addVertex(Point)
1226
         */
1227
        public Surface createSurface(GeneralPathX generalPathX, int subType)
1228
            throws CreateGeometryException;
1229
        
1230
        /**
1231
         * <p>
1232
         * Create a new multisurface with a concrete type and sets the value for the
1233
         * coordinates using a GeneralPathX.
1234
         * </p>
1235
         * 
1236
         * @param generalPathX
1237
         *            It is used to set the values for the X and Y coordinates.
1238
         * @param subType
1239
         *            SubType of geometry. Must be a value defined in
1240
         *            {@link Geometry.SUBTYPES}
1241
         * @return A multisurface
1242
         * @throws CreateGeometryException
1243
         *             This exception is thrown when the manager can not create the
1244
         *             geometry.
1245
         * @deprecated use {@link #createMultiSurface(int)} and {@link MultiPrimitive#addPrimitive(org.gvsig.fmap.geom.primitive.Primitive)}
1246
         */
1247
        public MultiSurface createMultiSurface(GeneralPathX generalPathX,
1248
            int subType) throws CreateGeometryException;
1249
        
1250
}