Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / impl / AbstractPrimitive.java @ 40366

History | View | Annotate | Download (22.4 KB)

1
package org.gvsig.fmap.geom.primitive.impl;
2

    
3
import java.awt.Shape;
4
import java.awt.geom.AffineTransform;
5
import java.awt.geom.PathIterator;
6
import java.io.Serializable;
7

    
8
import com.vividsolutions.jts.geom.Coordinate;
9
import com.vividsolutions.jts.geom.GeometryFactory;
10
import com.vividsolutions.jts.io.WKBWriter;
11
import com.vividsolutions.jts.operation.distance.DistanceOp;
12
import com.vividsolutions.jts.operation.overlay.snap.GeometrySnapper;
13

    
14
import org.cresques.cts.ICoordTrans;
15
import org.cresques.cts.IProjection;
16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18

    
19
import org.gvsig.fmap.geom.Geometry;
20
import org.gvsig.fmap.geom.GeometryLocator;
21
import org.gvsig.fmap.geom.GeometryManager;
22
import org.gvsig.fmap.geom.exception.CreateGeometryException;
23
import org.gvsig.fmap.geom.handler.Handler;
24
import org.gvsig.fmap.geom.operation.GeometryOperation;
25
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
26
import org.gvsig.fmap.geom.operation.GeometryOperationException;
27
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
28
import org.gvsig.fmap.geom.operation.towkb.ToWKBOperationContext;
29
import org.gvsig.fmap.geom.primitive.Envelope;
30
import org.gvsig.fmap.geom.primitive.FShape;
31
import org.gvsig.fmap.geom.primitive.GeneralPathX;
32
import org.gvsig.fmap.geom.primitive.NullGeometry;
33
import org.gvsig.fmap.geom.primitive.Point;
34
import org.gvsig.fmap.geom.primitive.Primitive;
35
import org.gvsig.fmap.geom.type.GeometryType;
36
import org.gvsig.fmap.geom.util.Converter;
37

    
38

    
39
/**
40
 * @author Jorge Piera Llodr� (jorge.piera@iver.es)
41
 */
42
public abstract class AbstractPrimitive implements Primitive, FShape, Shape, Serializable {
43
        
44
        private static final Logger logger = LoggerFactory.getLogger(AbstractPrimitive.class);
45

    
46
        private static final long serialVersionUID = -4334977368955260872L;
47
        protected String id = null;
48
        protected IProjection projection = null;
49
        protected GeometryType geometryType = null;
50
        protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
51

    
52
        /**
53
         * The constructor with the GeometryType like and argument 
54
         * is used by the {@link GeometryType}{@link #create()}
55
         * to create the geometry
56
         * @param type
57
         * The geometry type
58
         */
59
        public AbstractPrimitive(GeometryType geometryType) {
60
                this(geometryType, null, null);                
61
        }
62
        
63
        AbstractPrimitive(int type, int subtype) {
64
                try {
65
                        geometryType = geomManager.getGeometryType(type, subtype);
66
                } catch (Exception e) {
67
                        //TODO Not registered geometry
68
                        geometryType = null;
69
                }
70
        }        
71
        
72
        public AbstractPrimitive(GeometryType geometryType, String id, IProjection projection) {
73
                super();
74
                this.id = id;
75
                this.projection = projection;
76
                this.geometryType = geometryType;
77
        }
78

    
79
        public AbstractPrimitive(GeometryType geometryType, IProjection projection) {
80
                this(geometryType, null, projection);
81
        }
82

    
83
        /* (non-Javadoc)
84
         * @see org.gvsig.fmap.geom.Geometry#getGeometryType()
85
         */
86
        public GeometryType getGeometryType() {
87
                return geometryType;
88
        }
89

    
90
        /* (non-Javadoc)
91
         * @see org.gvsig.fmap.geom.Geometry#getType()
92
         */
93
        public int getType() {
94
                return geometryType.getType();
95
        }
96

    
97
        /**
98
         * (non-Javadoc)
99
         * @see com.iver.cit.gvsig.fmap.core.Geometry#getInternalShape()
100
         * @deprecated this Geometry is a Shape.
101
         */
102
        public Shape getInternalShape() {
103
                return this;
104
        }
105

    
106
        /* (non-Javadoc)
107
         * @see org.gvsig.geometries.iso.AbstractGeometry#getId()
108
         */
109
        public String getId() {
110
                return id;
111
        }
112

    
113
        /* (non-Javadoc)
114
         * @see org.gvsig.geometries.iso.AbstractGeometry#getSRS()
115
         */
116
        public IProjection getSRS() {
117
                return projection;
118
        }
119

    
120
        /* (non-Javadoc)
121
         * @see org.gvsig.geometries.iso.AbstractGeometry#transform(org.cresques.cts.IProjection)
122
         */
123
        public AbstractPrimitive transform(IProjection newProjection) {
124
                Geometry newGeom = cloneGeometry();
125
                ICoordTrans coordTrans = projection.getCT(newProjection);
126
                newGeom.reProject(coordTrans);
127
                return (AbstractPrimitive)newGeom;
128
        }
129

    
130

    
131

    
132
        /*
133
         * (non-Javadoc)
134
         * @see org.gvsig.fmap.geom.Geometry#fastIntersects(double, double, double, double)
135
         */
136
        public boolean fastIntersects(double x, double y, double w, double h) {
137

    
138
                boolean resp = true;
139
                
140
                try {
141
                        resp = intersectsRectangle(this, x, y, w, h);
142
                } catch (GeometryOperationException e) {
143
                        logger.error("While doing fastintersects: " + e.getMessage(), e);
144
                }
145
                
146
                return resp;
147
        }
148

    
149
        /*
150
         * (non-Javadoc)
151
         * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
152
         */
153
        public Geometry cloneGeometry() {
154
                return (Geometry)cloneFShape();
155
        }
156

    
157
        /*
158
         * (non-Javadoc)
159
         * @see org.gvsig.fmap.geom.Geometry#getHandlers(int)
160
         */
161
        public Handler[] getHandlers(int type) {
162
                if (type==STRETCHINGHANDLER){
163
                        return getStretchingHandlers();
164
                }else if (type==SELECTHANDLER){
165
                        return getSelectHandlers();
166
                }
167
                return null;
168
        }
169

    
170
        /*
171
         * (non-Javadoc)
172
         * @see org.gvsig.fmap.geom.Geometry#isSimple()
173
         */
174
        public boolean isSimple() {
175
                return true;
176
        }
177

    
178
        /*
179
         * (non-Javadoc)
180
         * @see org.gvsig.fmap.geom.Geometry#invokeOperation(int, org.gvsig.fmap.geom.operation.GeometryOperationContext)
181
         */
182
        public Object invokeOperation(int index, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException {
183
                return geomManager.invokeOperation(index, this, ctx);
184
        }
185

    
186
        /*
187
         * (non-Javadoc)
188
         * @see org.gvsig.fmap.geom.Geometry#invokeOperation(java.lang.String, org.gvsig.fmap.geom.operation.GeometryOperationContext)
189
         */
190
        public Object invokeOperation(String oppName, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException {
191
                return geomManager.invokeOperation(oppName, this, ctx);
192
        }
193

    
194
        /*
195
         * (non-Javadoc)
196
         * @see java.lang.Comparable#compareTo(T)
197
         */
198
        public int compareTo(Object arg0) {
199
                // TODO Auto-generated method stub
200
                return -1;
201
        }
202

    
203
        /*
204
         * (non-Javadoc)
205
         * @see java.lang.Object#toString()
206
         */
207
        public String toString() {
208
                String name=getGeometryType().getName();
209
                return name.substring(name.lastIndexOf(".")+1);
210
        }
211

    
212
        /*
213
         * (non-Javadoc)
214
         * @see java.lang.Object#equals(java.lang.Object)
215
         */
216
        public boolean equals(Object obj) {
217
                if (obj == null) {
218
                        return false;
219
                }
220
                if (this.getClass() != obj.getClass()) {
221
                        return false;
222
                }
223

    
224
                AbstractPrimitive other = (AbstractPrimitive) obj;
225
                if (this.getGeometryType().getType() != other.getGeometryType()
226
                                .getType()) {
227
                        return false;
228

    
229
                }
230
                
231
                if (this.getGeometryType().getSubType() != other.getGeometryType()
232
                                .getSubType()) {
233
                        return false;
234

    
235
                }
236
                
237
                if (this instanceof NullGeometry || obj instanceof NullGeometry) {
238
                    /*
239
                     * If any of them is null geometry, they both have to be
240
                     * null geometry, or else, they are not equal.
241
                     * This prevents null pointer exception in the rest of the
242
                     * method
243
                     */
244
                if (this instanceof NullGeometry && obj instanceof NullGeometry) {
245
                    return true;
246
                } else {
247
                    return false;
248
                }
249
                }
250
                
251
                if (this.projection != other.projection) {
252
                        if (this.projection == null) {
253
                                return false;
254
                        }
255
                        if (this.projection.getAbrev() != other.projection.getAbrev()) { //FIXME this must be false
256
                                return false;
257
                        }
258
                }
259
                if (!this.getBounds().equals(other.getBounds())) {
260
                        return false;
261
                }
262

    
263

    
264
                GeneralPathX myPath = this.getGeneralPath();
265
                GeneralPathX otherPath = other.getGeneralPath();
266
                if (myPath == null) {
267
                        if (otherPath != null) {
268
                                return false;
269
                        } else {
270
                                // TODO checkThis
271
                                return true;
272
                        }
273

    
274
                }
275
                if (myPath.getNumTypes() != otherPath.getNumTypes()) {
276
                        return false;
277
                }
278
                if (Math.abs(myPath.getNumCoords() - otherPath.getNumCoords()) > this
279
                                .getDimension()) {
280
                        return false;
281
                }
282
                PathIterator myIter = myPath.getPathIterator(null);
283
                PathIterator otherIter = otherPath.getPathIterator(null);
284
                int myType,otherType;
285
                // FIXME when 3D, 2DM and 3DM
286
                double[] myData = new double[6];
287
                double[] otherData = new double[6];
288
                double[] myFirst = new double[] { myPath.getPointAt(0).getX(),myPath.getPointAt(0).getY()};
289
                double[] otherFirst = new double[] { otherPath.getPointAt(0).getX(),otherPath.getPointAt(0).getY()};
290

    
291
                while (!myIter.isDone()) {
292
                        if (otherIter.isDone()) {
293
                                return false;
294
                        }
295
                        for (int i = 0; i < myData.length; i++) {
296
                                myData[i] = 0.0;
297
                                otherData[i] = 0.0;
298
                        }
299

    
300
                        myType = myIter.currentSegment(myData);
301
                        otherType = otherIter.currentSegment(otherData);
302

    
303
                        switch (myType) {
304
                        case PathIterator.SEG_LINETO:
305
                                if (otherType != myType) {
306
                                        if (otherType == PathIterator.SEG_CLOSE){
307
                                                if (!comparePathIteratorData(otherFirst, myData)) {
308
                                                        return false;
309
                                                }
310
                                        } else {
311
                                                return false;
312
                                        }
313
                                } else {
314
                                        if (!comparePathIteratorData(myData, otherData)) {
315
                                                return false;
316
                                        }
317
                                }
318
                                break;
319

    
320

    
321
                        case PathIterator.SEG_CLOSE:
322
                                if (otherType != myType) {
323
                                        if (otherType == PathIterator.SEG_LINETO) {
324
                                                if (!comparePathIteratorData(myFirst, otherData)) {
325
                                                        return false;
326
                                                }
327
                                        } else {
328
                                                return false;
329
                                        }
330
                                } else {
331
                                        if (!comparePathIteratorData(myData, otherData)) {
332
                                                return false;
333
                                        }
334
                                }
335
                                break;
336

    
337

    
338

    
339
                        case PathIterator.SEG_MOVETO:
340
                        case PathIterator.SEG_QUADTO:
341
                        case PathIterator.SEG_CUBICTO:
342
                                if (otherType != myType) {
343
                                        return false;
344
                                }
345
                                if (!comparePathIteratorData(myData, otherData)) {
346
                                        return false;
347
                                }
348
                                break;
349

    
350
                        } // end switch
351

    
352

    
353
                        myIter.next();
354
                        otherIter.next();
355
                }
356
                if (!otherIter.isDone()) {
357
                        return false;
358
                }
359
                return true;
360
        }
361

    
362
        private boolean comparePathIteratorData(double[] org, double[] other) {
363
                for (int i = 0; i < org.length; i++) {
364
                        if (Math.abs(org[i] - other[i]) > 0.0000001) {
365
                                return false;
366
                        }
367
                }
368
                return true;
369
        }
370

    
371
        /* (non-Javadoc)
372
         * @see org.gvsig.fmap.geom.primitive.FShape#getShapeType()
373
         */
374
        public int getShapeType() {
375
                return getType();
376
        }
377
        
378
        
379
        
380
        
381
        
382
        
383
        
384
        
385
        /**
386
         * Utility method
387
         * @param geometry
388
         * @param x
389
         * @param y
390
         * @return
391
         * @throws GeometryOperationException
392
         */
393
        protected boolean containsPoint(Geometry geom, double x, double y) throws GeometryOperationException {
394
                
395
                // exclude disjoint 
396
                Envelope env = geom.getEnvelope();
397
                if (x > env.getMaximum(0)) return false; 
398
                if (y > env.getMaximum(1)) return false; 
399
                if (x < env.getMinimum(0)) return false; 
400
                if (y < env.getMinimum(1)) return false; 
401
                
402
                // boxes overlap, need long version
403
                
404
                Geometry geompoint = null;
405
                try {
406
                        geompoint = GeometryLocator.getGeometryManager().createPoint(x, y, SUBTYPES.GEOM2D);
407
                } catch (Exception e1) {
408
                        throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e1);
409
                }
410
                
411
                GeometryOperationContext drgoc = new GeometryOperationContext();
412
                 drgoc.setAttribute("geom",geompoint);
413
                
414
                Object resp = null;
415
                boolean respboolean = true;
416
                try {
417
                        resp = geom.invokeOperation(GeometryOperation.OPERATION_CONTAINS_CODE, drgoc);
418
                        respboolean = ((Boolean) resp).booleanValue();
419
                } catch (Exception e) {
420
                        throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e);
421
                }
422

    
423
                return respboolean;
424
        }
425

    
426
        /**
427
         * 
428
         * @param geometry
429
         * @param x
430
         * @param y
431
         * @param w
432
         * @param h
433
         * @return
434
         */
435
        protected boolean containsRectangle(Geometry geom, double x, double y,
436
                        double w, double h) throws GeometryOperationException {
437
                
438
                
439
                // exclude disjoint boxes
440
                Envelope env = geom.getEnvelope();
441
                if (x > env.getMaximum(0)) return false; 
442
                if ((x+w) < env.getMinimum(0)) return false; 
443
                if (y > env.getMaximum(1)) return false; 
444
                if ((y+h) < env.getMinimum(1)) return false; 
445
                
446
                if (w == 0 && h == 0) {
447
                        return  containsPoint(geom, x, y); 
448
                }
449
                
450
                // boxes overlap, need long version
451
                Geometry rectgeom = null;
452
                GeneralPathX gpx = new GeneralPathX();
453
                gpx.moveTo(x, y);
454
                gpx.lineTo(x+w, y);
455
                gpx.lineTo(x+w, y+h);
456
                gpx.lineTo(x, y+h);
457
                gpx.lineTo(x, y);
458
                
459
                try {
460
                        rectgeom = GeometryLocator.getGeometryManager().createSurface(gpx, SUBTYPES.GEOM2D);
461
                } catch (Exception e1) {
462
                        throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e1);
463
                }
464
                
465
                GeometryOperationContext drgoc = new GeometryOperationContext();
466
                drgoc.setAttribute("geom",rectgeom);
467

    
468
                Object resp = null;
469
                boolean respboolean = true;
470
                try {
471
                        resp = geom.invokeOperation(GeometryOperation.OPERATION_CONTAINS_CODE, drgoc);
472
                        respboolean = ((Boolean) resp).booleanValue();
473
                } catch (Exception e) {
474
                        throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e);
475
                }
476

    
477
                return respboolean;
478
        }
479
        
480

    
481
        /**
482
         * 
483
         * @param geom
484
         * @param x
485
         * @param y
486
         * @param w
487
         * @param h
488
         * @return
489
         */
490
        protected boolean intersectsRectangle(Geometry geom, double x, double y,
491
                        double w, double h) throws GeometryOperationException {
492
                
493
                // exclude disjoint boxes
494
                Envelope env = geom.getEnvelope();
495
                if (x > env.getMaximum(0)) return false; 
496
                if ((x+w) < env.getMinimum(0)) return false; 
497
                if (y > env.getMaximum(1)) return false; 
498
                if ((y+h) < env.getMinimum(1)) return false; 
499
                
500
                // boxes overlap, need long version
501
                Geometry rectgeom = null;
502
                GeneralPathX gpx = new GeneralPathX();
503
                gpx.moveTo(x, y);
504
                gpx.lineTo(x+w, y);
505
                gpx.lineTo(x+w, y+h);
506
                gpx.lineTo(x, y+h);
507
                gpx.lineTo(x, y);
508
                
509
                try {
510
                        rectgeom = GeometryLocator.getGeometryManager().createSurface(gpx, SUBTYPES.GEOM2D);
511
                } catch (Exception e1) {
512
                        throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_INTERSECTS_CODE, e1);
513
                }
514

    
515
                GeometryOperationContext drgoc = new GeometryOperationContext();
516
                drgoc.setAttribute("geom",rectgeom);
517
                
518
                Object resp = null;
519
                boolean respboolean = true;
520
                try {
521
                        resp = geom.invokeOperation(GeometryOperation.OPERATION_INTERSECTS_CODE, drgoc);
522
                        respboolean = ((Boolean) resp).booleanValue();
523
                } catch (Exception e) {
524
                        throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_INTERSECTS_CODE, e);
525
                }
526

    
527
                return respboolean;
528

    
529

    
530
        }
531

    
532
        private com.vividsolutions.jts.geom.Geometry getJTS() {
533
                return Converter.geometryToJts(this);
534
        }
535
        
536
        public byte[] convertToWKB() throws GeometryOperationNotSupportedException,
537
                        GeometryOperationException {
538
                return (byte[]) this.invokeOperation(OPERATIONS.CONVERTTOWKB, null);
539
        }
540

    
541
        public byte[] convertToWKB(int srs) throws GeometryOperationNotSupportedException,
542
                        GeometryOperationException {
543
                WKBWriter write = new WKBWriter();
544
                return write.write(Converter.geometryToJtsWithSRID(this,srs));
545
        }
546

    
547
        public String convertToWKT() throws GeometryOperationNotSupportedException,
548
                        GeometryOperationException {
549
                return (String) this.invokeOperation(OPERATIONS.CONVERTTOWKT, null);
550
        }
551

    
552
        public Geometry buffer(double distance)
553
                        throws GeometryOperationNotSupportedException,
554
                        GeometryOperationException {
555
                // TODO: this method can be implemented throw invokeOperation 
556
                try {
557
                        return Converter.jtsToGeometry( getJTS().buffer(distance) );
558
                } catch (CreateGeometryException e) {
559
                        throw new GeometryOperationException(e);
560
                }
561
        }
562
        
563
        public boolean contains(Geometry geometry)
564
                        throws GeometryOperationNotSupportedException,
565
                        GeometryOperationException {
566
                // TODO: this method can be implemented throw invokeOperation 
567
                return getJTS().contains(Converter.geometryToJts(geometry));
568
        }
569
        
570
        public double distance(Geometry geometry)
571
                        throws GeometryOperationNotSupportedException,
572
                        GeometryOperationException {
573
                // TODO: this method can be implemented throw invokeOperation 
574
                return getJTS().distance( Converter.geometryToJts(geometry));
575
        }
576
        
577
        public Geometry snapTo(Geometry other, double snapTolerance)
578
                        throws GeometryOperationNotSupportedException,
579
                        GeometryOperationException {
580
                Geometry result = null;
581
                GeometrySnapper snapper = new GeometrySnapper(getJTS());
582
                com.vividsolutions.jts.geom.Geometry jts_result = snapper.snapTo(Converter.geometryToJts(other), snapTolerance);
583
                try {
584
                        result = Converter.jtsToGeometry(jts_result);
585
                } catch (CreateGeometryException e) {
586
                        throw new GeometryOperationException(e);
587
                }
588
                return result;
589
        }
590
        
591
        public boolean isWithinDistance(Geometry other, double distance)
592
                        throws GeometryOperationNotSupportedException,
593
                        GeometryOperationException {
594
                return DistanceOp.isWithinDistance(this.getJTS(), Converter.geometryToJts(other), distance);
595
        }
596
        
597
        
598
        public Geometry[] closestPoints(Geometry other)
599
                        throws GeometryOperationNotSupportedException,
600
                        GeometryOperationException {
601
                Geometry[] points = null;
602

    
603
                Coordinate[] jts_points = DistanceOp.closestPoints(this.getJTS(),
604
                                Converter.geometryToJts(other));
605
                points = new Point[jts_points.length];
606
                GeometryFactory geomFactory = new GeometryFactory();
607
                for (int n = 0; n < jts_points.length; n++) {
608
                        try {
609
                                points[n] = Converter.jtsToGeometry(geomFactory.createPoint(jts_points[n]));
610
                        } catch (CreateGeometryException e) {
611
                                throw new GeometryOperationException(e);
612
                        }
613
                }
614
                return points;
615
        }
616
        
617
        public boolean overlaps(Geometry geometry)
618
                        throws GeometryOperationNotSupportedException,
619
                        GeometryOperationException {
620
                // TODO: this method can be implemented throw invokeOperation 
621
                return getJTS().overlaps(Converter.geometryToJts(geometry));
622
        }
623
        
624
        public Geometry convexHull() throws GeometryOperationNotSupportedException,
625
                        GeometryOperationException {
626
                // TODO: this method can be implemented throw invokeOperation 
627
                try {
628
                        return Converter.jtsToGeometry( getJTS().convexHull() );
629
                } catch (CreateGeometryException e) {
630
                        throw new GeometryOperationException(e);
631
                }
632
        }
633
        
634
        public boolean coveredBy(Geometry geometry)
635
                        throws GeometryOperationNotSupportedException,
636
                        GeometryOperationException {
637
                // TODO: this method can be implemented throw invokeOperation 
638
                return getJTS().coveredBy( Converter.geometryToJts(geometry));
639
        }
640
        
641
        public boolean crosses(Geometry geometry)
642
                        throws GeometryOperationNotSupportedException,
643
                        GeometryOperationException {
644
                // TODO: this method can be implemented throw invokeOperation 
645
                return getJTS().crosses(Converter.geometryToJts(geometry));
646
        }
647
        
648
        public Geometry difference(Geometry other)
649
                        throws GeometryOperationNotSupportedException,
650
                        GeometryOperationException {
651
                // TODO: this method can be implemented throw invokeOperation 
652
                try {
653
                        return Converter.jtsToGeometry( getJTS().difference( Converter.geometryToJts(other)) );
654
                } catch (CreateGeometryException e) {
655
                        throw new GeometryOperationException(e);
656
                }
657
        }
658
        
659
        public Geometry intersection(Geometry other)
660
                        throws GeometryOperationNotSupportedException,
661
                        GeometryOperationException {
662
                // TODO: this method can be implemented throw invokeOperation 
663
                try {
664
                        return Converter.jtsToGeometry( getJTS().intersection(Converter.geometryToJts(other)) );
665
                } catch (CreateGeometryException e) {
666
                        throw new GeometryOperationException(e);
667
                }
668
        }
669
        
670
        public boolean intersects(Geometry geometry)
671
                        throws GeometryOperationNotSupportedException,
672
                        GeometryOperationException {
673
                // TODO: this method can be implemented throw invokeOperation 
674
                return getJTS().intersects(Converter.geometryToJts(geometry));
675
        }
676
        
677
        public boolean touches(Geometry geometry)
678
                        throws GeometryOperationNotSupportedException,
679
                        GeometryOperationException {
680
                // TODO: this method can be implemented throw invokeOperation 
681
                return getJTS().touches(Converter.geometryToJts(geometry));
682
        }
683
        
684
        public Geometry union(Geometry other)
685
                        throws GeometryOperationNotSupportedException,
686
                        GeometryOperationException {
687
                // TODO: this method can be implemented throw invokeOperation 
688
                try {
689
                        return Converter.jtsToGeometry( getJTS().union(Converter.geometryToJts(other)) );
690
                } catch (CreateGeometryException e) {
691
                        throw new GeometryOperationException(e);
692
                }
693
        }
694
        
695
        public boolean disjoint(Geometry geometry)
696
                        throws GeometryOperationNotSupportedException,
697
                        GeometryOperationException {
698
                // TODO: this method can be implemented throw invokeOperation 
699
                return getJTS().disjoint(Converter.geometryToJts(geometry));
700
        }
701
        
702
        public boolean within(Geometry geometry)
703
                        throws GeometryOperationNotSupportedException,
704
                        GeometryOperationException {
705
                // TODO: this method can be implemented throw invokeOperation 
706
                return getJTS().within(Converter.geometryToJts(geometry));
707
        }
708
        
709
        public Point centroid() throws GeometryOperationNotSupportedException, GeometryOperationException {
710
                com.vividsolutions.jts.geom.Geometry geometry = getJTS();
711
                com.vividsolutions.jts.geom.Point point = geometry.getCentroid();
712
                GeometryOperationContext geometryOperationContext = new GeometryOperationContext();
713
                geometryOperationContext.setAttribute("JTSGeometry", point);
714
                return (Point)this.invokeOperation("fromJTS", geometryOperationContext);                
715
        }
716
        
717
           
718
        public Point getInteriorPoint() throws GeometryOperationNotSupportedException, GeometryOperationException {
719
            
720
            try {
721
                com.vividsolutions.jts.geom.Geometry geometry = getJTS();
722
                com.vividsolutions.jts.geom.Point point = geometry.getInteriorPoint();
723
                GeometryOperationContext geometryOperationContext = new GeometryOperationContext();
724
                geometryOperationContext.setAttribute("JTSGeometry", point);
725
                return (Point)this.invokeOperation("fromJTS", geometryOperationContext);
726
        } catch (GeometryOperationNotSupportedException ns_ex) {
727
            throw ns_ex;
728
        } catch (GeometryOperationException op_ex) {
729
            throw op_ex;
730
            } catch (Exception ex) {
731
                /*
732
                 * This is for unexpected null pointer exceptions or other
733
                 */
734
                throw new GeometryOperationException(ex);
735
            }
736
        }   
737

    
738
        
739
        public double area() throws GeometryOperationNotSupportedException, GeometryOperationException
740
    {
741
        //Using get getJTS method instead of use the "toJTS" operation just for performance
742
        return getJTS().getArea();
743
    }
744
    
745
    public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException
746
    {
747
      //Using get getJTS method instead of use the "toJTS" operation just for performance
748
        return getJTS().getLength();
749
    }
750

    
751
    public Shape getShape() {
752
        return this;
753
    }  
754
    
755
    public Shape getShape(AffineTransform affineTransform) {
756
        if (affineTransform == null){
757
            return this;
758
        }
759
        return new GeneralPathAdapter(affineTransform, getGeneralPath());
760
    }     
761
    
762
    public void rotate(double radAngle, double basex, double basey) {
763
        
764
        AffineTransform at = new AffineTransform();
765
        at.rotate(radAngle,basex,basey);
766
        this.transform(at);
767
    }
768
    
769
    public void move(double dx, double dy) {
770
        
771
        AffineTransform at = new AffineTransform();
772
        at.translate(dx, dy);
773
        this.transform(at);
774
    }
775
    
776
    public void scale(Point basePoint, double sx, double sy) {
777
        
778
        AffineTransform at = new AffineTransform();
779
        at.setToTranslation(basePoint.getX(),basePoint.getY());
780
        at.scale(sx,sy);
781
        at.translate(-basePoint.getX(),-basePoint.getY());
782
        this.transform(at);
783
    }
784

    
785
}