Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / GeometryFactory.java @ 26866

History | View | Annotate | Download (20.9 KB)

1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.fmap.geom;
42

    
43
import java.awt.geom.Point2D;
44

    
45
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
46
import org.gvsig.fmap.geom.Geometry.TYPES;
47
import org.gvsig.fmap.geom.aggregate.BaseMultiPrimitive;
48
import org.gvsig.fmap.geom.aggregate.MultiCurve;
49
import org.gvsig.fmap.geom.aggregate.MultiCurve2D;
50
import org.gvsig.fmap.geom.aggregate.MultiPoint;
51
import org.gvsig.fmap.geom.aggregate.MultiPoint2D;
52
import org.gvsig.fmap.geom.aggregate.MultiPoint2DZ;
53
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
54
import org.gvsig.fmap.geom.aggregate.MultiSurface;
55
import org.gvsig.fmap.geom.aggregate.MultiSurface2D;
56
import org.gvsig.fmap.geom.primitive.Arc;
57
import org.gvsig.fmap.geom.primitive.Circle;
58
import org.gvsig.fmap.geom.primitive.Circle2D;
59
import org.gvsig.fmap.geom.primitive.Circle2DZ;
60
import org.gvsig.fmap.geom.primitive.Curve;
61
import org.gvsig.fmap.geom.primitive.Curve2D;
62
import org.gvsig.fmap.geom.primitive.Curve2DZ;
63
import org.gvsig.fmap.geom.primitive.Ellipse;
64
import org.gvsig.fmap.geom.primitive.Ellipse2D;
65
import org.gvsig.fmap.geom.primitive.Ellipse2DZ;
66
import org.gvsig.fmap.geom.primitive.EllipticArc;
67
import org.gvsig.fmap.geom.primitive.EllipticArc2D;
68
import org.gvsig.fmap.geom.primitive.EllipticArc2DZ;
69
import org.gvsig.fmap.geom.primitive.GeneralPathX;
70
import org.gvsig.fmap.geom.primitive.Point;
71
import org.gvsig.fmap.geom.primitive.Point2DZ;
72
import org.gvsig.fmap.geom.primitive.Primitive;
73
import org.gvsig.fmap.geom.primitive.Spline2D;
74
import org.gvsig.fmap.geom.primitive.Spline2DZ;
75
import org.gvsig.fmap.geom.primitive.Surface;
76
import org.gvsig.fmap.geom.primitive.Surface2D;
77
import org.gvsig.fmap.geom.primitive.Surface2DZ;
78
import org.slf4j.Logger;
79
import org.slf4j.LoggerFactory;
80

    
81

    
82
/**
83
 * Clase que crea las geometr�as, contendra un m�todo create por cada tipo de
84
 * geometria que soporte gvSIG
85
 */
86
public class GeometryFactory {
87
        final static private Logger logger = LoggerFactory.getLogger(GeometryFactory.class);
88

    
89
        /**
90
         * Crea una geometr�a que contiene como shape un punto 2D.
91
         *
92
         * @param x
93
         *            Coordenada x.
94
         * @param y
95
         *            Coordenada y.
96
         *
97
         * @return Geometr�a.
98
         */
99
        public Geometry createPoint2D(double x, double y) {
100
                try {
101
                        Point point = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
102
                        point.setX(x);
103
                        point.setY(y);
104
                        return point;
105
                } catch (Exception e) {
106
                        logger.error("Impossible to create a Point2D", e);
107
                        return null;
108
                }
109
        }
110

    
111
        public  Geometry createPoint2D(org.gvsig.fmap.geom.primitive.Point2D p) {
112
                try {
113
                        Point point = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
114
                        point.setX(p.getX());
115
                        point.setY(p.getY());
116
                        return point;
117
                } catch (Exception e) {
118
                        logger.error("Impossible to create a Point2D", e);
119
                        return null;
120
                }
121
        }
122

    
123
        /**
124
         * Crea una geometr�a que contiene como shape un Multipunto 2D.
125
         *
126
         * @param x
127
         *            Coordenada x.
128
         * @param y
129
         *            Coordenada y.
130
         *
131
         * @return Geometr�a.
132
         */
133
        public  Geometry createMultipoint2D(double[] x, double[] y) {
134
                try {
135
                        MultiPoint multipoint = (MultiPoint)GeometryLocator.getGeometryManager().create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
136
                        multipoint.setPoints(x, y);
137
                        return multipoint;
138
                } catch (Exception e) {
139
                        logger.error("Impossible to create a MultiPoint2D", e);
140
                        return null;
141
                }        
142
        }
143

    
144
        /**
145
         * Crea una geometr�a que contiene como shape un punto 3D.
146
         *
147
         * @param x
148
         *            Coordenada x.
149
         * @param y
150
         *            Coordenada y.
151
         * @param z
152
         *            Coordenada z.
153
         *
154
         * @return Geometr�a.
155
         */
156
        public  Geometry createPoint3D(double x, double y, double z) {
157
                try {
158
                        Point point = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2DZ);
159
                        point.setX(x);
160
                        point.setY(y);
161
                        point.setCoordinateAt(2, z);
162
                        return point;
163
                } catch (Exception e) {
164
                        logger.error("Impossible to create a Point3D", e);
165
                        return null;
166
                }
167
        }
168

    
169
        /**
170
         * Crea una geometr�a que contiene como shape un Multipunto 3D.
171
         *
172
         * @param x
173
         *            Coordenada x.
174
         * @param y
175
         *            Coordenada y.
176
         * @param z
177
         *            Coordenada z.
178
         *
179
         * @return Geometr�a.
180
         */
181
        public  Geometry createMultipoint3D(double[] x, double[] y, double[] z) {
182
                try {
183
                        MultiPoint multipoint = (MultiPoint)GeometryLocator.getGeometryManager().create(TYPES.MULTIPOINT, SUBTYPES.GEOM2DZ);
184
                        for (int i=0 ; i<x.length ; i++){
185
                                Point point = (Point)GeometryLocator.getGeometryManager().create(TYPES.MULTIPOINT, SUBTYPES.GEOM2DZ);
186
                                point.setX(x[i]);
187
                                point.setY(y[i]);
188
                                point.setCoordinateAt(2, z[i]);
189
                                multipoint.addPoint(point);
190
                        }                        
191
                        return multipoint;
192
                } catch (Exception e) {
193
                        logger.error("Impossible to create a MultiPoint3D", e);
194
                        return null;
195
                }                        
196
        }
197

    
198
        /**
199
         * Crea una geometr�a que contiene como shape un Polil�nea 2D.
200
         *
201
         * @param shape
202
         *            GeneralPathX.
203
         *
204
         * @return Geometr�a.
205
         */
206
        public  Geometry createPolyline2D(GeneralPathX shape) {
207
                try {
208
                        Curve curve = (Curve)GeometryLocator.getGeometryManager().create(TYPES.CURVE, SUBTYPES.GEOM2D);
209
                        curve.setGeneralPath(shape);
210
                        return curve;
211
                } catch (Exception e) {
212
                        logger.error("Impossible to create a Curve2D", e);
213
                        return null;
214
                }
215
        }
216

    
217
        /**
218
         * Crea una geometr�a que contiene como shape un Polil�nea 3D.
219
         *
220
         * @param shape
221
         *            GeneralPathX.
222
         * @param pZ
223
         *            Vector de Z.
224
         *
225
         * @return Geometr�a.
226
         */
227
        public  Geometry createPolyline3D(GeneralPathX shape, double[] pZ) {
228
                try {
229
                        Curve curve = (Curve)GeometryLocator.getGeometryManager().create(TYPES.CURVE, SUBTYPES.GEOM2DZ);
230
                        curve.setGeneralPath(shape);
231
                        for (int i=0 ; i<pZ.length ; i++){
232
                                curve.setCoordinateAt(i, 2, pZ[i]);
233
                        }
234
                        return curve;
235
                } catch (Exception e) {
236
                        logger.error("Impossible to create a Curve2D", e);
237
                        return null;
238
                }
239
        }
240

    
241
        /**
242
         * Creates a multiline form a set of lines
243
         *
244
         * @param polylines
245
         *            The lines
246
         * @return A multiline
247
         */
248
        public  Geometry createMultiPolyline(Curve2D[] polylines) {
249
                try {
250
                        MultiCurve curve = (MultiCurve)GeometryLocator.getGeometryManager().create(TYPES.CURVE, SUBTYPES.GEOM2D);
251
                        for (int i=0 ; i<polylines.length ; i++){
252
                                curve.addCurve(polylines[i]);
253
                        }
254
                        return curve;
255
                } catch (Exception e) {
256
                        logger.error("Impossible to create a MultiCurve2D", e);
257
                        return null;
258
                }                
259
        }
260

    
261
        /**
262
         * Creates a multiline form a set of lines
263
         *
264
         * @param polylines
265
         *            The lines
266
         * @return A multiline
267
         */
268
        public  Geometry createMultiPolygon(Surface2D[] polygons) {
269
                try {
270
                        MultiSurface surface = (MultiSurface)GeometryLocator.getGeometryManager().create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D);
271
                        for (int i=0 ; i<polygons.length ; i++){
272
                                surface.addSurface(polygons[i]);
273
                        }
274
                        return surface;
275
                } catch (Exception e) {
276
                        logger.error("Impossible to create a MultiSurface2D", e);
277
                        return null;
278
                }                
279
        }
280

    
281
        /**
282
         * Creates a multigeometry form a set of geometries
283
         *
284
         * @param geometries
285
         *            The geometries
286
         * @return A multigeometry
287
         */
288
        public  Geometry createMultiGeometry(Geometry[] geometries) {
289
                try {
290
                        MultiPrimitive multiGeometry = (MultiPrimitive)GeometryLocator.getGeometryManager().create(TYPES.AGGREGATE, SUBTYPES.GEOM2D);
291
                        for (int i=0 ; i<geometries.length ; i++){
292
                                multiGeometry.addPrimitive((Primitive)geometries[i]);
293
                        }
294
                        return multiGeometry;
295
                } catch (Exception e) {
296
                        logger.error("Impossible to create a MultiGeometry", e);
297
                        return null;
298
                }                
299
        }
300

    
301
        /**
302
         * Crea una geometr�a que contiene como shape un Pol�gono 3D.
303
         *
304
         * @param shape
305
         *            GeneralPathX.
306
         * @param pZ
307
         *            Vector de Z.
308
         *
309
         * @return Geometr�a.
310
         */
311
        public  Geometry createPolygon2DZ(GeneralPathX shape, double[] pZ) {
312
                try {
313
                        Surface surface = (Surface)GeometryLocator.getGeometryManager().create(TYPES.SURFACE, SUBTYPES.GEOM2DZ);
314
                        surface.setGeneralPath(shape);
315
                        for (int i=0 ; i<pZ.length ; i++){
316
                                surface.setCoordinateAt(i, 2, pZ[i]);
317
                        }
318
                        return surface;
319
                } catch (Exception e) {
320
                        logger.error("Impossible to create a MultiSurface3D", e);
321
                        return null;
322
                }
323
        }
324

    
325
        /**
326
         * Crea una geometr�a que contiene como shape un Pol�gono 2D.
327
         *
328
         * @param shape
329
         *            GeneralPathX.
330
         *
331
         * @return Geometr�a.
332
         */
333
        public  Geometry createPolygon2D(GeneralPathX shape) {
334
                try {
335
                        Surface surface = (Surface)GeometryLocator.getGeometryManager().create(TYPES.SURFACE, SUBTYPES.GEOM2D);
336
                        surface.setGeneralPath(shape);
337
                        return surface;
338
                } catch (Exception e) {
339
                        logger.error("Impossible to create a Surface2D", e);
340
                        return null;
341
                }
342
        }
343

    
344
        /**
345
         * Crea una geometr�a que contiene como shape un Pol�gono 2D.
346
         *
347
         * @param shape
348
         *            FPolyline2D closed (you must be sure it is really closed).
349
         *
350
         * @return Geometr�a.
351
         */
352
        public  Geometry createPolygon2D(Curve2D shape) {
353
                try {
354
                        Surface surface = (Surface)GeometryLocator.getGeometryManager().create(TYPES.SURFACE, SUBTYPES.GEOM2D);
355
                        surface.setGeneralPath(shape.getGeneralPathX());
356
                        return surface;
357
                } catch (Exception e) {
358
                        logger.error("Impossible to create a Surface2D", e);
359
                        return null;
360
                }                
361
        }
362

    
363
        /**
364
         * Crea a partir de un FShape una geometr�a.
365
         *
366
         * @param shp
367
         *            FShape.
368
         *
369
         * @return Geometr�a.
370
         */
371
//        public  Geometry createGeometry(FShape shp) {
372
//                return (Geometry) shp;
373
//        }
374

    
375
        public  Geometry createCircle(java.awt.geom.Point2D center,
376
                        java.awt.geom.Point2D radious) {
377
                try {
378
                        Point pCenter = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
379
                        pCenter.setX(center.getX());
380
                        pCenter.setY(center.getY());
381
                        
382
                        Point pRadious = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
383
                        pRadious.setX(radious.getX());
384
                        pRadious.setX(radious.getY());
385
                        
386
                        Circle circle = (Circle)GeometryLocator.getGeometryManager().create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
387
                        circle.setPoints(pCenter, pRadious);
388
                        return circle;
389
                } catch (Exception e) {
390
                        logger.error("Impossible to create a Circle2D", e);
391
                        return null;
392
                }        
393
        }
394

    
395
        public  Geometry createCircle(Point2D center, double radio) {
396
                try {
397
                        Point pCenter = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
398
                        pCenter.setX(center.getX());
399
                        pCenter.setY(center.getY());
400
                        
401
                        Circle circle = (Circle)GeometryLocator.getGeometryManager().create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
402
                        circle.setPoints(pCenter, radio);
403
                        return circle;
404
                } catch (Exception e) {
405
                        logger.error("Impossible to create a Circle2D", e);
406
                        return null;
407
                }        
408
        }
409

    
410
        public  Geometry createCircle2DZ(Point2D center, double radio, double z) {
411
                try {
412
                        Point pCenter = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
413
                        pCenter.setX(center.getX());
414
                        pCenter.setY(center.getY());
415
                        
416
                        Circle circle = (Circle)GeometryLocator.getGeometryManager().create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
417
                        circle.setPoints(pCenter, radio);
418
                        circle.setCoordinateAt(0, 2, z);
419
                        return circle;
420
                } catch (Exception e) {
421
                        logger.error("Impossible to create a Circle3D", e);
422
                        return null;
423
                }        
424
        }
425

    
426
        public  Geometry createCircle(Point2D p1, Point2D p2, Point2D p3) {
427
                try {
428
                        Point _p1 = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
429
                        _p1.setX(p1.getX());
430
                        _p1.setY(p1.getY());
431
                        
432
                        Point _p2 = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
433
                        _p2.setX(p2.getX());
434
                        _p2.setY(p2.getY());
435
                        
436
                        Point _p3 = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
437
                        _p3.setX(p3.getX());
438
                        _p1.setY(p3.getY());
439
                        
440
                        Circle circle = (Circle)GeometryLocator.getGeometryManager().create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
441
                        circle.setPoints(_p1, _p2, _p3);                        
442
                        return circle;
443
                } catch (Exception e) {
444
                        logger.error("Impossible to create a Circle3D", e);
445
                        return null;
446
                }
447
        }
448

    
449
        public Geometry createArc(Point2D p1, Point2D p2, Point2D p3) {
450
                try {
451
                        Point _p1 = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
452
                        _p1.setX(p1.getX());
453
                        _p1.setY(p1.getY());
454
                        
455
                        Point _p2 = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
456
                        _p2.setX(p2.getX());
457
                        _p2.setY(p2.getY());
458
                        
459
                        Point _p3 = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
460
                        _p3.setX(p3.getX());
461
                        _p1.setY(p3.getY());
462
                        
463
                        Arc arc = (Arc)GeometryLocator.getGeometryManager().create(TYPES.ARC, SUBTYPES.GEOM2D);
464
                        arc.setPoints(_p1, _p2, _p3);                        
465
                        return arc;
466
                } catch (Exception e) {
467
                        logger.error("Impossible to create a Arc2D", e);
468
                        return null;
469
                }
470
        }
471
        public Geometry createArc2DZ(Point2D p1, Point2D p2, Point2D p3, double z) {
472
                try {
473
                        Point _p1 = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
474
                        _p1.setX(p1.getX());
475
                        _p1.setY(p1.getY());
476
                        
477
                        Point _p2 = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
478
                        _p2.setX(p2.getX());
479
                        _p2.setY(p2.getY());
480
                        
481
                        Point _p3 = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
482
                        _p3.setX(p3.getX());
483
                        _p1.setY(p3.getY());
484
                        
485
                        Arc arc = (Arc)GeometryLocator.getGeometryManager().create(TYPES.ARC, SUBTYPES.GEOM2DZ);
486
                        arc.setPoints(_p1, _p2, _p3);        
487
                        arc.setCoordinateAt(0, 2, z);
488
                        return arc;
489
                } catch (Exception e) {
490
                        logger.error("Impossible to create a Arc3D", e);
491
                        return null;
492
                }
493
        }
494

    
495
        public Geometry createArc(Point2D center, double radius,double initAngle,double angleExt ) {
496
                try {
497
                        Point pCenter = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
498
                        pCenter.setX(center.getX());
499
                        pCenter.setY(center.getY());
500
                        
501
                        Arc arc = (Arc)GeometryLocator.getGeometryManager().create(TYPES.ARC, SUBTYPES.GEOM2D);
502
                        arc.setPoints(pCenter, radius, initAngle, angleExt);                        
503
                        return arc;
504
                } catch (Exception e) {
505
                        logger.error("Impossible to create a Arc2D", e);
506
                        return null;
507
                }
508
        }
509

    
510
        public Geometry createArc2DZ(Point2D center, double radius,double initAngle,double angleExt, double z ) {
511
                try {
512
                        Point pCenter = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
513
                        pCenter.setX(center.getX());
514
                        pCenter.setY(center.getY());
515
                        
516
                        Arc arc = (Arc)GeometryLocator.getGeometryManager().create(TYPES.ARC, SUBTYPES.GEOM2DZ);
517
                        arc.setPoints(pCenter, radius, initAngle, angleExt);                        
518
                        arc.setCoordinateAt(0, 2, z);
519
                        return arc;
520
                } catch (Exception e) {
521
                        logger.error("Impossible to create a Arc3D", e);
522
                        return null;
523
                }
524
        }
525

    
526
        public Geometry createLine2D(Point2D start, Point2D end) {
527
                try {
528
                        Point pStart = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
529
                        pStart.setX(start.getX());
530
                        pStart.setY(end.getY());
531
                        
532
                        Point pEnd = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
533
                        pEnd.setX(end.getX());
534
                        pEnd.setY(end.getY());
535
                        
536
                        Curve curve = (Curve)GeometryLocator.getGeometryManager().create(TYPES.CURVE, SUBTYPES.GEOM2D);
537
                        curve.setPoints(pStart, pEnd);
538
                        return curve;
539
                } catch (Exception e) {
540
                        logger.error("Impossible to create a Curve2D", e);
541
                        return null;
542
                }
543
        }
544

    
545
        public Geometry createLine2DZ(Point2D start, Point2D end, double z ) {
546
                try {
547
                        Point pStart = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
548
                        pStart.setX(start.getX());
549
                        pStart.setY(end.getY());
550
                        
551
                        Point pEnd = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
552
                        pEnd.setX(end.getX());
553
                        pEnd.setY(end.getY());
554
                        
555
                        Curve curve = (Curve)GeometryLocator.getGeometryManager().create(TYPES.CURVE, SUBTYPES.GEOM2DZ);
556
                        curve.setPoints(pStart, pEnd);
557
                        curve.setCoordinateAt(0, 2, z);
558
                        return curve;
559
                } catch (Exception e) {
560
                        logger.error("Impossible to create a Curve3D", e);
561
                        return null;
562
                }
563
        }
564

    
565
        public  Geometry createEllipse(Point2D axis1Start, Point2D axis1End,
566
                        double axis2Length) {
567
                try {
568
                        Point pAxis1Start = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
569
                        pAxis1Start.setX(axis1Start.getX());
570
                        pAxis1Start.setY(axis1Start.getY());
571
                        
572
                        Point pAxis1End = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
573
                        pAxis1End.setX(axis1End.getX());
574
                        pAxis1End.setY(axis1End.getY());
575
                        
576
                        Ellipse ellipse = (Ellipse)GeometryLocator.getGeometryManager().create(TYPES.ELLIPSE, SUBTYPES.GEOM2D);
577
                        ellipse.setPoints(pAxis1Start, pAxis1End, axis2Length);
578
                        return ellipse;
579
                } catch (Exception e) {
580
                        logger.error("Impossible to create a Ellipse2D", e);
581
                        return null;
582
                }
583
        }
584

    
585
        public  Geometry createEllipse2DZ(Point2D axis1Start, Point2D axis1End,
586
                        double axis2Length, double z) {
587
                try {
588
                        Point pAxis1Start = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
589
                        pAxis1Start.setX(axis1Start.getX());
590
                        pAxis1Start.setY(axis1Start.getY());
591
                        
592
                        Point pAxis1End = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
593
                        pAxis1End.setX(axis1End.getX());
594
                        pAxis1End.setY(axis1End.getY());
595
                        
596
                        Ellipse ellipse = (Ellipse)GeometryLocator.getGeometryManager().create(TYPES.ELLIPSE, SUBTYPES.GEOM2DZ);
597
                        ellipse.setPoints(pAxis1Start, pAxis1End, axis2Length);
598
                        ellipse.setCoordinateAt(0, 2, z);
599
                        return ellipse;
600
                } catch (Exception e) {
601
                        logger.error("Impossible to create a Ellipse3D", e);
602
                        return null;
603
                }
604
        }
605

    
606
        public  Geometry createEllipticArc2D(Point2D axis1Start, Point2D axis1End,
607
                        double semiAxis2Length, double angSt, double angExt) {
608
                try {
609
                        Point pAxis1Start = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
610
                        pAxis1Start.setX(axis1Start.getX());
611
                        pAxis1Start.setY(axis1Start.getY());
612
                        
613
                        Point pAxis1End = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
614
                        pAxis1End.setX(axis1End.getX());
615
                        pAxis1End.setY(axis1End.getY());
616
                        
617
                        EllipticArc ellipticArc = (EllipticArc)GeometryLocator.getGeometryManager().create(TYPES.ELLIPTICARC, SUBTYPES.GEOM2D);
618
                        ellipticArc.setPoints(pAxis1Start, pAxis1End, semiAxis2Length, angSt, angExt);
619
                        return ellipticArc;
620
                } catch (Exception e) {
621
                        logger.error("Impossible to create a EllipticArc2D", e);
622
                        return null;
623
                }
624
        }
625

    
626
        public  Geometry createEllipticArc2DZ(Point2D axis1Start, Point2D axis1End,
627
                        double semiAxis2Length, double angSt, double angExt, double z) {
628
                try {
629
                        Point pAxis1Start = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
630
                        pAxis1Start.setX(axis1Start.getX());
631
                        pAxis1Start.setY(axis1Start.getY());
632
                        
633
                        Point pAxis1End = (Point)GeometryLocator.getGeometryManager().create(TYPES.POINT, SUBTYPES.GEOM2D);
634
                        pAxis1End.setX(axis1End.getX());
635
                        pAxis1End.setY(axis1End.getY());
636
                        
637
                        EllipticArc ellipticArc = (EllipticArc)GeometryLocator.getGeometryManager().create(TYPES.ELLIPTICARC, SUBTYPES.GEOM2DZ);
638
                        ellipticArc.setPoints(pAxis1Start, pAxis1End, semiAxis2Length, angSt, angExt);
639
                        ellipticArc.setCoordinateAt(0, 2, z);
640
                        return ellipticArc;
641
                } catch (Exception e) {
642
                        logger.error("Impossible to create a EllipticArc3D", e);
643
                        return null;
644
                }
645
        }
646

    
647
        public  Geometry createSpline2D(Point2D[] points) {
648
                try {
649
                        Curve curve = (Curve)GeometryLocator.getGeometryManager().create(TYPES.SPLINE, SUBTYPES.GEOM2D);
650
                        for (int i=0 ; i<points.length ; i++){
651
                                curve.setCoordinateAt(i, 0, points[i].getX());
652
                                curve.setCoordinateAt(i, 1, points[i].getY());
653
                        }
654
                        return curve;
655
                } catch (Exception e) {
656
                        logger.error("Impossible to create a Arc2D", e);
657
                        return null;
658
                }                
659
        }
660

    
661
        public  Geometry createSpline2DZ(Point2D[] points, double z) {
662
                try {
663
                        Curve curve = (Curve)GeometryLocator.getGeometryManager().create(TYPES.SPLINE, SUBTYPES.GEOM2DZ);
664
                        for (int i=0 ; i<points.length ; i++){
665
                                curve.setCoordinateAt(i, 0, points[i].getX());
666
                                curve.setCoordinateAt(i, 1, points[i].getY());
667
                        }
668
                        curve.setCoordinateAt(0, 2, z);
669
                        return curve;
670
                } catch (Exception e) {
671
                        logger.error("Impossible to create a Arc2D", e);
672
                        return null;
673
                }                
674
        }
675
}