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 @ 41246

History | View | Annotate | Download (46.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
import org.gvsig.tools.dynobject.DynObject;
49
import org.gvsig.tools.service.Manager;
50
import org.gvsig.tools.service.ServiceException;
51
import org.gvsig.tools.service.spi.ServiceManager;
52

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

    
71
    public interface OPERATIONS {
72

    
73
        public final static String FROMWKT = "FromWKT";
74
        public final static String FROMWKB = "FromWKB";
75
    }
76

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

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

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

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

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

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

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

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

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

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

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

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

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

    
784
    public Geometry createFrom(String wkt) throws CreateGeometryException,
785
        GeometryException;
786

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

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

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

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

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

    
889

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

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

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

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

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

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

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

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

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

    
1123
    /**
1124
     * Returns a list with the name of the operations that have been
1125
     * registered.
1126
     * 
1127
     * @return
1128
     *         A list of the registered operations.
1129
     */
1130
    public List getGeometryOperationNames();
1131

    
1132
    /**
1133
     * Returns the flatness used to convert a curve is a set
1134
     * of points.
1135
     * 
1136
     * @return
1137
     *         The flatness.
1138
     */
1139
    public double getFlatness();
1140

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

    
1156
    
1157
    /**
1158
     * Create a spatial index with the implementation specified as name.
1159
     * If the creation of index don't requery parameters can be passed a null.
1160
     * 
1161
     * @param name of the type of spatial index to create
1162
     * @param parameters used to create the index or null.
1163
     * @return the new SpatialIndex or null if not exists the type of index.
1164
     * @throws GeometryException 
1165
     */
1166
    public SpatialIndex createSpatialIndex(String name, DynObject parameters) throws ServiceException;
1167
    
1168
    /**
1169
     * Return the name of the factory of the spatial index required.
1170
     * 
1171
     * @param name of the spatial index factory
1172
     * @return the SpatialIndexFactory required or null if not exists
1173
     */
1174
    public SpatialIndexFactory getSpatialIndexFactory(String name);
1175
    
1176
    /**
1177
     * Create a GeneralPathX to populate a geometry.
1178
     * This method is deprecated, instead use OrientablePrimitive#addVertex(Point) to add vertex to 
1179
     * primitive geometries or {@link MultiPrimitive#addPrimitive(org.gvsig.fmap.geom.primitive.Primitive)} to add geometries to an aggregate.
1180
     * 
1181
     * @param rule
1182
     * @param initialCapacity
1183
     * @param pathIterator , can be null
1184
     * @return a GeneralPathX
1185
     * @deprecated use method of Geometry to handle this 
1186
     * @see OrientablePrimitive#addVertex(Point) or {@link MultiPrimitive#addPrimitive(org.gvsig.fmap.geom.primitive.Primitive)}
1187
     * 
1188
     */
1189
    public GeneralPathX createGeneralPath(int rule, PathIterator pathIterator);
1190

    
1191
        /**
1192
         * <p>
1193
         * Create a new curve with a concrete type and sets the value for the
1194
         * coordinates using a GeneralPathX.
1195
         * </p>
1196
         * 
1197
         * @param generalPathX
1198
         *            It is used to set the values for the X and Y coordinates.
1199
         * @param subType
1200
         *            SubType of geometry. Must be a value defined in
1201
         *            {@link Geometry.SUBTYPES}
1202
         * @return
1203
         *         A curve
1204
         * @throws CreateGeometryException
1205
         *             This exception is thrown when the manager can not create
1206
         *             the geometry.
1207
         * @deprecated use {@link #createCurve(int)} and OrientablePrimitive#addVertex(Point) 
1208
         */
1209
        public Curve createCurve(GeneralPathX generalPathX, int subType)
1210
            throws CreateGeometryException;
1211
        
1212
        /**
1213
         * <p>
1214
         * Create a new multicurve with a concrete type and sets the value for the
1215
         * coordinates using a GeneralPathX.
1216
         * </p>
1217
         * 
1218
         * @param generalPathX
1219
         *            It is used to set the values for the X and Y coordinates.
1220
         * @param subType
1221
         *            SubType of geometry. Must be a value defined in
1222
         *            {@link Geometry.SUBTYPES}
1223
         * @return A multicurve
1224
         * @throws CreateGeometryException
1225
         *             This exception is thrown when the manager can not create the
1226
         *             geometry.
1227
         * @deprecated use {@link #createMultiCurve(int)} and {@link MultiPrimitive#addPrimitive(org.gvsig.fmap.geom.primitive.Primitive)}
1228
         */
1229
        public MultiCurve createMultiCurve(GeneralPathX generalPathX, int subType)
1230
                throws CreateGeometryException;
1231
        
1232
        /**
1233
         * <p>
1234
         * Create a new surface with a concrete type and sets the value for the
1235
         * coordinates using a GeneralPathX.
1236
         * </p>
1237
         * 
1238
         * @param generalPathX
1239
         *            It is used to set the values for the X and Y coordinates.
1240
         * @param subType
1241
         *            SubType of geometry. Must be a value defined in
1242
         *            {@link Geometry.SUBTYPES}
1243
         * @return
1244
         *         A surface
1245
         * @throws CreateGeometryException
1246
         *             This exception is thrown when the manager can not create
1247
         *             the geometry.
1248
         * @deprecated use {@link #createSurface(int)} and OrientablePrimitive#addVertex(Point)
1249
         */
1250
        public Surface createSurface(GeneralPathX generalPathX, int subType)
1251
            throws CreateGeometryException;
1252
        
1253
        /**
1254
         * <p>
1255
         * Create a new multisurface with a concrete type and sets the value for the
1256
         * coordinates using a GeneralPathX.
1257
         * </p>
1258
         * 
1259
         * @param generalPathX
1260
         *            It is used to set the values for the X and Y coordinates.
1261
         * @param subType
1262
         *            SubType of geometry. Must be a value defined in
1263
         *            {@link Geometry.SUBTYPES}
1264
         * @return A multisurface
1265
         * @throws CreateGeometryException
1266
         *             This exception is thrown when the manager can not create the
1267
         *             geometry.
1268
         * @deprecated use {@link #createMultiSurface(int)} and {@link MultiPrimitive#addPrimitive(org.gvsig.fmap.geom.primitive.Primitive)}
1269
         */
1270
        public MultiSurface createMultiSurface(GeneralPathX generalPathX,
1271
            int subType) throws CreateGeometryException;
1272
        
1273
}