Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / AbstractGeometry.java @ 42813

History | View | Annotate | Download (24.9 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.geom.jts;
24

    
25
import java.awt.Rectangle;
26
import java.awt.Shape;
27
import java.awt.geom.AffineTransform;
28
import java.awt.geom.Rectangle2D;
29
import java.io.IOException;
30

    
31
import com.vividsolutions.jts.algorithm.CGAlgorithms;
32
import com.vividsolutions.jts.geom.Coordinate;
33
import com.vividsolutions.jts.io.WKBWriter;
34
import com.vividsolutions.jts.io.WKTWriter;
35
import com.vividsolutions.jts.operation.distance.DistanceOp;
36
import com.vividsolutions.jts.operation.overlay.snap.GeometrySnapper;
37
import com.vividsolutions.jts.operation.valid.IsValidOp;
38
import com.vividsolutions.jts.operation.valid.TopologyValidationError;
39

    
40
import org.slf4j.Logger;
41
import org.slf4j.LoggerFactory;
42

    
43
import org.gvsig.fmap.geom.Geometry;
44
import org.gvsig.fmap.geom.GeometryLocator;
45
import org.gvsig.fmap.geom.GeometryManager;
46
import org.gvsig.fmap.geom.exception.CreateGeometryException;
47
import org.gvsig.fmap.geom.jts.operation.towkb.OGCWKBEncoder;
48
import org.gvsig.fmap.geom.jts.operation.towkb.PostGISEWKBEncoder;
49
import org.gvsig.fmap.geom.jts.operation.towkb.WKBEncodingException;
50
import org.gvsig.fmap.geom.jts.primitive.Envelope2D;
51
import org.gvsig.fmap.geom.jts.primitive.Envelope3D;
52
import org.gvsig.fmap.geom.jts.primitive.point.Point3D;
53
import org.gvsig.fmap.geom.jts.util.JTSUtils;
54
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
55
import org.gvsig.fmap.geom.operation.GeometryOperationException;
56
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
57
import org.gvsig.fmap.geom.primitive.Envelope;
58
import org.gvsig.fmap.geom.primitive.OrientableCurve;
59
import org.gvsig.fmap.geom.primitive.OrientableSurface;
60
import org.gvsig.fmap.geom.primitive.Point;
61
import org.gvsig.fmap.geom.type.GeometryType;
62
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
63

    
64
/**
65
 * @author fdiaz
66
 *
67
 */
68
public abstract class AbstractGeometry implements GeometryJTS {
69

    
70
    protected static final Logger logger = LoggerFactory.getLogger(AbstractGeometry.class);
71

    
72
    /**
73
     *
74
     */
75
    private static final long serialVersionUID = 4999326772576222293L;
76

    
77
    private final GeometryType geometryType;
78

    
79

    
80
    /**
81
     *
82
     */
83
    public AbstractGeometry(int type, int subtype) {
84
        try {
85
            this.geometryType = GeometryLocator.getGeometryManager().getGeometryType(type, subtype);
86
        } catch (Exception e) {
87
            // TODO: Ver de crear una excepcion para esto o si hay alguna en el API.
88
            throw new RuntimeException(e);
89
        }
90
    }
91

    
92
    public GeometryType getGeometryType(){
93
        return geometryType;
94
    }
95

    
96
    protected GeometryManager getManager() {
97
        return GeometryLocator.getGeometryManager();
98
    }
99

    
100
    /*
101
     * (non-Javadoc)
102
     *
103
     * @see org.gvsig.fmap.geom.Geometry#contains(org.gvsig.fmap.geom.Geometry)
104
     */
105
    public boolean contains(Geometry geometry) throws GeometryOperationNotSupportedException,
106
        GeometryOperationException {
107
        if (!(geometry instanceof GeometryJTS)) {
108
            return false;
109
        }
110
        return getJTS().contains(((GeometryJTS) geometry).getJTS());
111
    }
112

    
113
    /*
114
     * (non-Javadoc)
115
     *
116
     * @see java.lang.Comparable#compareTo(java.lang.Object)
117
     */
118
    public int compareTo(Object o) {
119
        return getJTS().compareTo(((GeometryJTS) o).getJTS());
120
    }
121

    
122
    /*
123
     * (non-Javadoc)
124
     *
125
     * @see java.awt.Shape#contains(double, double)
126
     */
127
    public boolean contains(double x, double y) {
128
        notifyDeprecated("Calling deprecated method of geometry contains from shape interface");
129
        Shape shp = getShape();
130
        return shp.contains(x, y);
131
    }
132

    
133
    /*
134
     * (non-Javadoc)
135
     *
136
     * @see java.awt.Shape#intersects(double, double, double, double)
137
     */
138
    public boolean intersects(double x, double y, double w, double h) {
139

    
140
        notifyDeprecated("Calling deprecated method of geometry intersects from shape interface");
141
        Shape shp = this.getShape();
142
        return shp.intersects(x, y, w, h);
143
    }
144

    
145
    /*
146
     * (non-Javadoc)
147
     *
148
     * @see java.awt.Shape#contains(double, double, double, double)
149
     */
150
    public boolean contains(double x, double y, double w, double h) {
151
        notifyDeprecated("Calling deprecated method of geometry contains from shape interface");
152
        Shape shp = this.getShape();
153
        return shp.contains(x, y, w, h);
154
    }
155

    
156
    /*
157
     * (non-Javadoc)
158
     *
159
     * @see java.awt.Shape#contains(java.awt.geom.Point2D)
160
     */
161
    public boolean contains(java.awt.geom.Point2D p) {
162
        notifyDeprecated("Calling deprecated method of geometry contains from shape interface");
163
        Shape shp = this.getShape();
164
        return shp.contains(p);
165
    }
166

    
167
    /*
168
     * (non-Javadoc)
169
     *
170
     * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
171
     */
172
    public boolean contains(Rectangle2D r) {
173
        notifyDeprecated("Calling deprecated method of geometry contains from shape interface");
174
        Shape shp = this.getShape();
175
        return shp.contains(r);
176
    }
177

    
178
    /*
179
     * (non-Javadoc)
180
     *
181
     * @see org.gvsig.fmap.geom.Geometry#distance(org.gvsig.fmap.geom.Geometry)
182
     */
183
    public double distance(org.gvsig.fmap.geom.Geometry other) throws GeometryOperationNotSupportedException,
184
        GeometryOperationException {
185
        return getJTS().distance(((GeometryJTS) other).getJTS());
186
    }
187

    
188
    /*
189
     * (non-Javadoc)
190
     *
191
     * @see
192
     * org.gvsig.fmap.geom.Geometry#isWithinDistance(org.gvsig.fmap.geom.Geometry
193
     * , double)
194
     */
195
    public boolean isWithinDistance(org.gvsig.fmap.geom.Geometry other, double distance)
196
        throws GeometryOperationNotSupportedException, GeometryOperationException {
197
        return com.vividsolutions.jts.operation.distance.DistanceOp.isWithinDistance(this.getJTS(),
198
            ((GeometryJTS) other).getJTS(), distance);
199
    }
200

    
201
    /*
202
     * (non-Javadoc)
203
     *
204
     * @see org.gvsig.fmap.geom.Geometry#overlaps(org.gvsig.fmap.geom.Geometry)
205
     */
206
    public boolean overlaps(org.gvsig.fmap.geom.Geometry geometry) throws GeometryOperationNotSupportedException,
207
        GeometryOperationException {
208
        // TODO: this method can be implemented throw invokeOperation
209
        return getJTS().overlaps(((GeometryJTS) geometry).getJTS());
210
    }
211

    
212
    public boolean coveredBy(Geometry geometry) throws GeometryOperationNotSupportedException,
213
        GeometryOperationException {
214

    
215
        return getJTS().coveredBy(((GeometryJTS) geometry).getJTS());
216
    }
217

    
218
    public boolean covers(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException {
219
        // TODO: this method can be implemented throw invokeOperation
220
        return getJTS().covers(((GeometryJTS) geometry).getJTS());
221

    
222
    }
223

    
224
    public boolean crosses(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException {
225
        // TODO: this method can be implemented throw invokeOperation
226
        return getJTS().crosses(((GeometryJTS) geometry).getJTS());
227
    }
228

    
229
    public boolean intersects(Geometry geometry) throws GeometryOperationNotSupportedException,
230
        GeometryOperationException {
231
        return getJTS().intersects(((GeometryJTS) geometry).getJTS());
232
    }
233

    
234
    public boolean touches(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException {
235
        // TODO: this method can be implemented throw invokeOperation
236
        return getJTS().touches(((GeometryJTS) geometry).getJTS());
237
    }
238

    
239
    public boolean disjoint(Geometry geometry) throws GeometryOperationNotSupportedException,
240
        GeometryOperationException {
241
        // TODO: this method can be implemented throw invokeOperation
242
        return getJTS().disjoint(((GeometryJTS) geometry).getJTS());
243
    }
244

    
245
    public boolean within(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException {
246
        // TODO: this method can be implemented throw invokeOperation
247
        return getJTS().within(((GeometryJTS) geometry).getJTS());
248
    }
249

    
250
    public double area() throws GeometryOperationNotSupportedException, GeometryOperationException {
251
        return getJTS().getArea();
252
    }
253

    
254
    public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException {
255
        return getJTS().getLength();
256
    }
257

    
258
    /*
259
     * (non-Javadoc)
260
     *
261
     * @see org.gvsig.fmap.geom.Geometry#intersects(java.awt.geom.Rectangle2D)
262
     */
263
    public boolean intersects(Rectangle2D r) {
264
        double x = r.getMinX();
265
        double y = r.getMinY();
266
        double w = r.getWidth();
267
        double h = r.getHeight();
268

    
269
        return fastIntersects(x, y, w, h);
270
    }
271

    
272
    /*
273
     * (non-Javadoc)
274
     *
275
     * @see org.gvsig.fmap.geom.Geometry#fastIntersects(double, double, double,
276
     * double)
277
     */
278
    public boolean fastIntersects(double x, double y, double w, double h) {
279
        com.vividsolutions.jts.geom.Geometry rect = null;
280
        com.vividsolutions.jts.geom.Coordinate[] coord = new com.vividsolutions.jts.geom.Coordinate[5];
281
        coord[0] = new com.vividsolutions.jts.geom.Coordinate(x, y);
282
        coord[1] = new com.vividsolutions.jts.geom.Coordinate(x + w, y);
283
        coord[2] = new com.vividsolutions.jts.geom.Coordinate(x + w, y + w);
284
        coord[3] = new com.vividsolutions.jts.geom.Coordinate(x, y + w);
285
        coord[4] = new com.vividsolutions.jts.geom.Coordinate(x, y);
286
        rect = JTSUtils.createJTSPolygon(coord);
287

    
288
        return getJTS().intersects(rect);
289
    }
290

    
291
    /*
292
     * (non-Javadoc)
293
     *
294
     * @see org.gvsig.fmap.geom.Geometry#getEnvelope()
295
     */
296
    public Envelope getEnvelope() {
297
        if (is3D()) {
298
            Coordinate[] coordinates = getJTS().getCoordinates();
299

    
300
            double minx = Double.POSITIVE_INFINITY;
301
            double miny = Double.POSITIVE_INFINITY;
302
            double minz = Double.POSITIVE_INFINITY;
303

    
304
            double maxx = Double.NEGATIVE_INFINITY;
305
            double maxy = Double.NEGATIVE_INFINITY;
306
            double maxz = Double.NEGATIVE_INFINITY;
307

    
308
            double x;
309
            double y;
310
            double z;
311

    
312
            for (int i = 0; i < coordinates.length; i++) {
313
                x = coordinates[i].x;
314
                y = coordinates[i].y;
315
                z = coordinates[i].z;
316
                minx = Math.min(x, minx);
317
                miny = Math.min(y, miny);
318
                minz = Math.min(z, minz);
319
                maxx = Math.max(x, maxx);
320
                maxy = Math.max(y, maxy);
321
                maxz = Math.max(z, maxz);
322
            }
323

    
324
            if (minx <= maxx && miny <= maxy && minz <= maxz) {
325
                Point min = new Point3D(minx, miny, minz);
326
                Point max = new Point3D(maxx, maxy, maxz);
327
                return new Envelope3D(min, max);
328
            }
329
            return new Envelope3D();
330
        } else {
331
            com.vividsolutions.jts.geom.Envelope envelope = getJTS().getEnvelopeInternal();
332
            return new Envelope2D(envelope);
333
        }
334
    }
335

    
336
    /*
337
     * (non-Javadoc)
338
     *
339
     * @see org.gvsig.fmap.geom.Geometry#isSimple()
340
     */
341
    public boolean isSimple() {
342
        return this.getJTS().isSimple();
343
    }
344

    
345
    /*
346
     * (non-Javadoc)
347
     *
348
     * @see org.gvsig.fmap.geom.Geometry#isCCW()
349
     */
350
    public boolean isCCW() throws GeometryOperationNotSupportedException, GeometryOperationException {
351
        return CGAlgorithms.isCCW(this.getJTS().getCoordinates());
352
    }
353

    
354
    /*
355
     * (non-Javadoc)
356
     *
357
     * @see org.gvsig.fmap.geom.Geometry#invokeOperation(int,
358
     * org.gvsig.fmap.geom.operation.GeometryOperationContext)
359
     */
360
    public Object invokeOperation(int index, GeometryOperationContext ctx)
361
        throws GeometryOperationNotSupportedException, GeometryOperationException {
362
        return getManager().invokeOperation(index, this, ctx);
363

    
364
    }
365

    
366
    /*
367
     * (non-Javadoc)
368
     *
369
     * @see org.gvsig.fmap.geom.Geometry#invokeOperation(java.lang.String,
370
     * org.gvsig.fmap.geom.operation.GeometryOperationContext)
371
     */
372
    public Object invokeOperation(String opName, GeometryOperationContext ctx)
373
        throws GeometryOperationNotSupportedException, GeometryOperationException {
374
        return getManager().invokeOperation(opName, this, ctx);
375

    
376
    }
377

    
378
    /*
379
     * (non-Javadoc)
380
     *
381
     * @see org.gvsig.fmap.geom.Geometry#getType()
382
     */
383
    public int getType() {
384
        return this.getGeometryType().getType();
385
    }
386

    
387
    public byte[] convertToWKB() throws GeometryOperationNotSupportedException, GeometryOperationException {
388
            try {
389
                        return new OGCWKBEncoder().encode(this);
390
                } catch (Exception e) {
391
                        throw new GeometryOperationException(e);
392
                }
393

    
394
    }
395

    
396
    public byte[] convertToWKB(int srs) throws GeometryOperationNotSupportedException, GeometryOperationException {
397
            /*
398
             * No se sabe si la especificaci?n de OGC soporta SRS. OGCWKBEncoder no.
399
             */
400

    
401
            try {
402
                        return new OGCWKBEncoder().encode(this);
403
                } catch (Exception e) {
404
                        throw new GeometryOperationException(e);
405
                }
406
    }
407

    
408
    public byte[] convertToWKBForcingType(int srs, int type) throws GeometryOperationNotSupportedException,
409
        GeometryOperationException {
410
            /*
411
             * No se sabe si la especificaci?n de OGC soporta SRS. OGCWKBEncoder no.
412
             */
413
            Geometry geom = this;
414
        if(this.getType() != type){
415
            com.vividsolutions.jts.geom.Geometry jts = getJTS();
416
            jts = JTSUtils.convertTypes(jts, this.getType(), type);
417

    
418
            geom = JTSUtils.createGeometry(jts);
419
        }
420
            try {
421
                        return new OGCWKBEncoder().encode(geom);
422
                } catch (Exception e) {
423
                        throw new GeometryOperationException(e);
424
                }
425

    
426
    }
427

    
428

    
429

    
430
    public byte[] convertToEWKB() throws GeometryOperationNotSupportedException, GeometryOperationException {
431
            try {
432
                        return new PostGISEWKBEncoder().encode(this);
433
                } catch (Exception e) {
434
                        throw new GeometryOperationException(e);
435
                }
436

    
437
    }
438

    
439
    public byte[] convertToEWKB(int srs) throws GeometryOperationNotSupportedException, GeometryOperationException {
440
            /*
441
             * No se sabe si la especificaci?n de OGC soporta SRS. OGCWKBEncoder no.
442
             */
443

    
444
            try {
445
                        return new PostGISEWKBEncoder().encode(this);
446
                } catch (Exception e) {
447
                        throw new GeometryOperationException(e);
448
                }
449
    }
450

    
451
    public byte[] convertToEWKBForcingType(int srs, int type) throws GeometryOperationNotSupportedException,
452
        GeometryOperationException {
453
            /*
454
             * No se sabe si la especificaci?n de OGC soporta SRS. OGCWKBEncoder no.
455
             */
456
            Geometry geom = this;
457
        if(this.getType() != type){
458
            com.vividsolutions.jts.geom.Geometry jts = getJTS();
459
            jts = JTSUtils.convertTypes(jts, this.getType(), type);
460

    
461
            geom = JTSUtils.createGeometry(jts);
462
        }
463
            try {
464
                        return new PostGISEWKBEncoder().encode(geom);
465
                } catch (Exception e) {
466
                        throw new GeometryOperationException(e);
467
                }
468

    
469
    }
470

    
471
    /*
472
     * (non-Javadoc)
473
     *
474
     * @see org.gvsig.fmap.geom.Geometry#convertToWKT()
475
     */
476
    public String convertToWKT() throws GeometryOperationNotSupportedException, GeometryOperationException {
477
        int subType = getGeometryType().getSubType();
478
        boolean is3D = subType == 1 || subType == 3;
479

    
480
        WKTWriter write = null;
481
        if (is3D)
482
            write = new WKTWriter(3);
483
        else
484
            write = new WKTWriter(2);
485
        com.vividsolutions.jts.geom.Geometry jts = getJTS();
486
        return write.write(jts);
487
    }
488

    
489
    /*
490
     * (non-Javadoc)
491
     *
492
     * @see org.gvsig.fmap.geom.Geometry#buffer(double)
493
     */
494
    public org.gvsig.fmap.geom.Geometry buffer(double distance) throws GeometryOperationNotSupportedException,
495
        GeometryOperationException {
496
        return JTSUtils.createGeometry(getJTS().buffer(distance));
497
    }
498

    
499
    /*
500
     * (non-Javadoc)
501
     *
502
     * @see org.gvsig.fmap.geom.Geometry#snapTo(org.gvsig.fmap.geom.Geometry,
503
     * double)
504
     */
505
    public org.gvsig.fmap.geom.Geometry snapTo(org.gvsig.fmap.geom.Geometry other, double snapTolerance)
506
        throws GeometryOperationNotSupportedException, GeometryOperationException {
507
        Geometry result = null;
508
        GeometrySnapper snapper = new GeometrySnapper(getJTS());
509
        com.vividsolutions.jts.geom.Geometry jts_result = snapper.snapTo(((GeometryJTS) other).getJTS(), snapTolerance);
510
        result = JTSUtils.createGeometry(jts_result);
511
        return result;
512
    }
513

    
514
    /*
515
     * (non-Javadoc)
516
     *
517
     * @see org.gvsig.fmap.geom.Geometry#getInteriorPoint()
518
     */
519
    public Point getInteriorPoint() throws GeometryOperationNotSupportedException, GeometryOperationException {
520

    
521
        com.vividsolutions.jts.geom.Geometry geometry = getJTS();
522
        com.vividsolutions.jts.geom.Point point = geometry.getInteriorPoint();
523
        Geometry result = JTSUtils.createGeometry(point);
524
        return (Point) result;
525
    }
526

    
527
    /*
528
     * (non-Javadoc)
529
     *
530
     * @see org.gvsig.fmap.geom.Geometry#isValid()
531
     */
532
    public boolean isValid() {
533
        return getJTS().isValid();
534
    }
535

    
536
    /*
537
     * (non-Javadoc)
538
     *
539
     * @see org.gvsig.fmap.geom.Geometry#getValidationStatus()
540
     */
541
    public ValidationStatus getValidationStatus() {
542
        DefaultValidationStatus status = new DefaultValidationStatus(ValidationStatus.VALID, null);
543
        com.vividsolutions.jts.geom.Geometry jtsgeom = null;
544
        try {
545
            jtsgeom = this.getJTS();
546
            IsValidOp validOp = new IsValidOp(jtsgeom);
547
            if (validOp != null) {
548
                status.setValidationError(validOp.getValidationError());
549
            }
550
        } catch (Exception ex) {
551
            status.setStatusCode(ValidationStatus.CURRUPTED);
552
            status.setMesage("The geometry is corrupted.");
553
            if (this instanceof OrientableSurface) {
554
                int vertices = ((OrientableSurface) this).getNumVertices();
555
                if (vertices < 3) {
556
                    status.setStatusCode(ValidationStatus.TOO_FEW_POINTS);
557
                    status.setMesage(TopologyValidationError.errMsg[TopologyValidationError.TOO_FEW_POINTS]);
558
                }
559
            } else if (this instanceof OrientableCurve) {
560
                int vertices = ((OrientableCurve) this).getNumVertices();
561
                if (vertices < 2) {
562
                    status.setStatusCode(ValidationStatus.TOO_FEW_POINTS);
563
                    status.setMesage(TopologyValidationError.errMsg[TopologyValidationError.TOO_FEW_POINTS]);
564
                }
565
            }
566
        }
567
        return status;
568
    }
569

    
570
    /*
571
     * (non-Javadoc)
572
     *
573
     * @see org.gvsig.fmap.geom.Geometry#makeValid()
574
     */
575
    public org.gvsig.fmap.geom.Geometry makeValid() {
576
        try {
577
            ValidationStatus vs = this.getValidationStatus();
578
            if (vs.isValid()) {
579
                return this;
580
            }
581
            Geometry g = null;
582
            switch (vs.getStatusCode()) {
583
            case Geometry.ValidationStatus.RING_SELF_INTERSECTION:
584
            case Geometry.ValidationStatus.SELF_INTERSECTION:
585
                g = this.buffer(0);
586
                if (g.isValid()) {
587
                    return g;
588
                }
589
                break;
590

    
591
            case Geometry.ValidationStatus.TOO_FEW_POINTS:
592
                if (this instanceof OrientableCurve) {
593
                    int vertices = ((OrientableCurve) this).getNumVertices();
594
                    if (vertices < 2) {
595
                        return null; // new
596
                                     // DefaultNullGeometry(this.getGeometryType());
597
                    }
598
                }
599
                if (this instanceof OrientableSurface) {
600
                    int vertices = ((OrientableSurface) this).getNumVertices();
601
                    if (vertices < 3) {
602
                        return null; // new
603
                                     // DefaultNullGeometry(this.getGeometryType());
604
                    }
605
                }
606
            }
607
        } catch (Exception ex) {
608
            return null;
609
        }
610
        return null;
611
    }
612

    
613
    /*
614
     * (non-Javadoc)
615
     *
616
     * @see org.gvsig.fmap.geom.Geometry#getBounds2D()
617
     */
618
    public Rectangle2D getBounds2D() {
619
        com.vividsolutions.jts.geom.Envelope envInternal = getJTS().getEnvelopeInternal();
620
        return new Rectangle2D.Double(envInternal.getMinX(), envInternal.getMinY(), envInternal.getWidth(),
621
            envInternal.getHeight());
622
    }
623

    
624
    /*
625
     * (non-Javadoc)
626
     *
627
     * @see java.awt.Shape#getBounds()
628
     */
629
    public Rectangle getBounds() {
630
        return this.getShape().getBounds();
631
    }
632

    
633
    /*
634
     * (non-Javadoc)
635
     *
636
     * @see org.gvsig.fmap.geom.Geometry#getInternalShape()
637
     */
638
    public Shape getInternalShape() {
639
        return getShape();
640
    }
641

    
642
    public void rotate(double radAngle, double basex, double basey) {
643

    
644
        AffineTransform at = new AffineTransform();
645
        at.rotate(radAngle, basex, basey);
646
        this.transform(at);
647
    }
648

    
649
    public void move(double dx, double dy) {
650

    
651
        AffineTransform at = new AffineTransform();
652
        at.translate(dx, dy);
653
        this.transform(at);
654
    }
655

    
656
    public void scale(Point basePoint, double sx, double sy) {
657

    
658
        AffineTransform at = new AffineTransform();
659
        at.setToTranslation(basePoint.getX(), basePoint.getY());
660
        at.scale(sx, sy);
661
        at.translate(-basePoint.getX(), -basePoint.getY());
662
        this.transform(at);
663
    }
664

    
665
    public Geometry[] closestPoints(Geometry other) throws GeometryOperationNotSupportedException,
666
        GeometryOperationException {
667
        Point[] points = null;
668

    
669
        Coordinate[] jts_points = DistanceOp.nearestPoints(getJTS(), ((GeometryJTS) other).getJTS());
670
        points = new Point[jts_points.length];
671
        for (int i = 0; i < jts_points.length; i++) {
672
            try {
673
                points[i] = JTSUtils.createPoint(this.getGeometryType(), jts_points[i]);
674
            } catch (CreateGeometryException e) {
675
                throw new GeometryOperationException(e);
676
            }
677
        }
678

    
679
        return (Geometry[]) points;
680
    }
681

    
682
    public Geometry convexHull() throws GeometryOperationNotSupportedException, GeometryOperationException {
683

    
684
        return JTSUtils.createGeometry(getJTS().convexHull());
685
    }
686

    
687
    public Geometry difference(Geometry other) throws GeometryOperationNotSupportedException,
688
        GeometryOperationException {
689
        return JTSUtils.createGeometry(getJTS().difference(((GeometryJTS) other).getJTS()));
690
    }
691

    
692
    public Geometry intersection(Geometry other) throws GeometryOperationNotSupportedException,
693
        GeometryOperationException {
694
        return JTSUtils.createGeometry(getJTS().intersection(((GeometryJTS) other).getJTS()));
695
    }
696

    
697
    public Geometry union(Geometry other) throws GeometryOperationNotSupportedException, GeometryOperationException {
698
        return JTSUtils.createGeometry(getJTS().union(((GeometryJTS) other).getJTS()));
699
    }
700

    
701
    public org.gvsig.fmap.geom.primitive.Point centroid() throws GeometryOperationNotSupportedException,
702
        GeometryOperationException {
703
        try {
704
            return JTSUtils.createPoint(this.getGeometryType(), getJTS().getCentroid().getCoordinate());
705
        } catch (CreateGeometryException e) {
706
            throw new GeometryOperationException(e);
707
        }
708
    }
709

    
710
    protected void notifyDeprecated(String message) {
711
        logger.info(message);
712

    
713
    }
714

    
715

    
716
    /* (non-Javadoc)
717
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#ensureOrientation(boolean)
718
     */
719
    public boolean ensureOrientation(boolean ccw) throws GeometryOperationNotSupportedException, GeometryOperationException {
720
        if(ccw!=isCCW()){
721
            flip();
722
            return true;
723
        }
724
        return false;
725
    }
726

    
727
    /* (non-Javadoc)
728
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#out(org.gvsig.fmap.geom.Geometry)
729
     */
730
    public boolean out(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException {
731
        GeometryJTS otherJtsGeom = (GeometryJTS)geometry;
732
        return (!contains(otherJtsGeom) && !intersects(otherJtsGeom));
733
    }
734

    
735
    /* (non-Javadoc)
736
     * @see java.lang.Object#equals(java.lang.Object)
737
     */
738
    @Override
739
    public boolean equals(Object obj) {
740
        if (obj instanceof GeometryJTS) {
741
            return this.getJTS().equals(((GeometryJTS) obj).getJTS());
742
        }
743
        return false;
744
    }
745

    
746
    public String toString(){
747
        return this.getGeometryType().getFullName();
748
    }
749

    
750

    
751
}