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

History | View | Annotate | Download (25.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

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

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

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

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

    
68
    protected static final Logger logger = LoggerFactory.getLogger(AbstractGeometry.class);
69

    
70
    /**
71
     *
72
     */
73
    private static final long serialVersionUID = 4999326772576222293L;
74

    
75
    private final GeometryType geometryType;
76

    
77
    private IProjection projection;
78

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
221
    }
222

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
363
    }
364

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

    
375
    }
376

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

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

    
393
    }
394

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

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

    
407
    @Override
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
    public byte[] convertToEWKB() throws GeometryOperationNotSupportedException, GeometryOperationException {
429
        try {
430
            return new PostGISEWKBEncoder().encode(this);
431
        } catch (Exception e) {
432
            throw new GeometryOperationException(e);
433
        }
434

    
435
    }
436

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

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

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

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

    
467
    }
468

    
469
    /*
470
     * (non-Javadoc)
471
     *
472
     * @see org.gvsig.fmap.geom.Geometry#convertToWKT()
473
     */
474
    public String convertToWKT() throws GeometryOperationNotSupportedException, GeometryOperationException {
475
        int subType = getGeometryType().getSubType();
476

    
477
        EWKTWriter writer = null;
478

    
479
        switch (subType) {
480
            case Geometry.SUBTYPES.GEOM3D:
481
                writer = new EWKTWriter(3, false);
482
                break;
483
            case Geometry.SUBTYPES.GEOM2DM:
484
                writer = new EWKTWriter(3, true);
485
                break;
486
            case Geometry.SUBTYPES.GEOM3DM:
487
                writer = new EWKTWriter(4, true);
488
                break;
489

    
490
            default:
491
                writer = new EWKTWriter(2, false);
492
                break;
493
        }
494
        com.vividsolutions.jts.geom.Geometry jts = getJTS();
495
        return writer.write(jts);
496
    }
497

    
498
    /*
499
     * (non-Javadoc)
500
     *
501
     * @see org.gvsig.fmap.geom.Geometry#buffer(double)
502
     */
503
    public org.gvsig.fmap.geom.Geometry buffer(double distance) throws GeometryOperationNotSupportedException,
504
            GeometryOperationException {
505
        return JTSUtils.createGeometry(getJTS().buffer(distance));
506
    }
507

    
508
    /*
509
     * (non-Javadoc)
510
     *
511
     * @see org.gvsig.fmap.geom.Geometry#snapTo(org.gvsig.fmap.geom.Geometry,
512
     * double)
513
     */
514
    public org.gvsig.fmap.geom.Geometry snapTo(org.gvsig.fmap.geom.Geometry other, double snapTolerance)
515
            throws GeometryOperationNotSupportedException, GeometryOperationException {
516
        Geometry result = null;
517
        GeometrySnapper snapper = new GeometrySnapper(getJTS());
518
        com.vividsolutions.jts.geom.Geometry jts_result = snapper.snapTo(((GeometryJTS) other).getJTS(), snapTolerance);
519
        result = JTSUtils.createGeometry(jts_result);
520
        return result;
521
    }
522

    
523
    /*
524
     * (non-Javadoc)
525
     *
526
     * @see org.gvsig.fmap.geom.Geometry#getInteriorPoint()
527
     */
528
    public Point getInteriorPoint() throws GeometryOperationNotSupportedException, GeometryOperationException {
529

    
530
        com.vividsolutions.jts.geom.Geometry geometry = getJTS();
531
        com.vividsolutions.jts.geom.Point point = geometry.getInteriorPoint();
532
        Geometry result = JTSUtils.createGeometry(point);
533
        return (Point) result;
534
    }
535

    
536
    /*
537
     * (non-Javadoc)
538
     *
539
     * @see org.gvsig.fmap.geom.Geometry#isValid()
540
     */
541
    public boolean isValid() {
542
        return getJTS().isValid();
543
    }
544

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

    
579
    /*
580
     * (non-Javadoc)
581
     *
582
     * @see org.gvsig.fmap.geom.Geometry#makeValid()
583
     */
584
    public org.gvsig.fmap.geom.Geometry makeValid() {
585
        try {
586
            ValidationStatus vs = this.getValidationStatus();
587
            if (vs.isValid()) {
588
                return this;
589
            }
590
            Geometry g = null;
591
            switch (vs.getStatusCode()) {
592
                case Geometry.ValidationStatus.RING_SELF_INTERSECTION:
593
                case Geometry.ValidationStatus.SELF_INTERSECTION:
594
                    g = this.buffer(0);
595
                    if (g.isValid()) {
596
                        return g;
597
                    }
598
                    break;
599

    
600
                case Geometry.ValidationStatus.TOO_FEW_POINTS:
601
                    if (this instanceof OrientableCurve) {
602
                        int vertices = ((OrientableCurve) this).getNumVertices();
603
                        if (vertices < 2) {
604
                            return null; // new
605
                            // DefaultNullGeometry(this.getGeometryType());
606
                        }
607
                    }
608
                    if (this instanceof OrientableSurface) {
609
                        int vertices = ((OrientableSurface) this).getNumVertices();
610
                        if (vertices < 3) {
611
                            return null; // new
612
                            // DefaultNullGeometry(this.getGeometryType());
613
                        }
614
                    }
615
            }
616
        } catch (Exception ex) {
617
            return null;
618
        }
619
        return null;
620
    }
621

    
622
    /*
623
     * (non-Javadoc)
624
     *
625
     * @see org.gvsig.fmap.geom.Geometry#getBounds2D()
626
     */
627
    public Rectangle2D getBounds2D() {
628
        com.vividsolutions.jts.geom.Envelope envInternal = getJTS().getEnvelopeInternal();
629
        return new Rectangle2D.Double(envInternal.getMinX(), envInternal.getMinY(), envInternal.getWidth(),
630
                envInternal.getHeight());
631
    }
632

    
633
    /*
634
     * (non-Javadoc)
635
     *
636
     * @see java.awt.Shape#getBounds()
637
     */
638
    public Rectangle getBounds() {
639
        return this.getShape().getBounds();
640
    }
641

    
642
    /*
643
     * (non-Javadoc)
644
     *
645
     * @see org.gvsig.fmap.geom.Geometry#getInternalShape()
646
     */
647
    public Shape getInternalShape() {
648
        return getShape();
649
    }
650

    
651
    public void rotate(double radAngle, double basex, double basey) {
652

    
653
        AffineTransform at = new AffineTransform();
654
        at.rotate(radAngle, basex, basey);
655
        this.transform(at);
656
    }
657

    
658
    public void move(double dx, double dy) {
659

    
660
        AffineTransform at = new AffineTransform();
661
        at.translate(dx, dy);
662
        this.transform(at);
663
    }
664

    
665
    public void scale(Point basePoint, double sx, double sy) {
666

    
667
        AffineTransform at = new AffineTransform();
668
        at.setToTranslation(basePoint.getX(), basePoint.getY());
669
        at.scale(sx, sy);
670
        at.translate(-basePoint.getX(), -basePoint.getY());
671
        this.transform(at);
672
    }
673

    
674
    public Geometry[] closestPoints(Geometry other) throws GeometryOperationNotSupportedException,
675
            GeometryOperationException {
676
        Point[] points = null;
677

    
678
        Coordinate[] jts_points = DistanceOp.nearestPoints(getJTS(), ((GeometryJTS) other).getJTS());
679
        points = new Point[jts_points.length];
680
        for (int i = 0; i < jts_points.length; i++) {
681
            try {
682
                points[i] = JTSUtils.createPoint(this.getGeometryType(), jts_points[i]);
683
            } catch (CreateGeometryException e) {
684
                throw new GeometryOperationException(e);
685
            }
686
        }
687

    
688
        return (Geometry[]) points;
689
    }
690

    
691
    public Geometry convexHull() throws GeometryOperationNotSupportedException, GeometryOperationException {
692

    
693
        return JTSUtils.createGeometry(getJTS().convexHull());
694
    }
695

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

    
701
    public Geometry intersection(Geometry other) throws GeometryOperationNotSupportedException,
702
            GeometryOperationException {
703
        return JTSUtils.createGeometry(getJTS().intersection(((GeometryJTS) other).getJTS()));
704
    }
705

    
706
    public Geometry union(Geometry other) throws GeometryOperationNotSupportedException, GeometryOperationException {
707
        return JTSUtils.createGeometry(getJTS().union(((GeometryJTS) other).getJTS()));
708
    }
709

    
710
    public org.gvsig.fmap.geom.primitive.Point centroid() throws GeometryOperationNotSupportedException,
711
            GeometryOperationException {
712
        try {
713
            return JTSUtils.createPoint(this.getGeometryType(), getJTS().getCentroid().getCoordinate());
714
        } catch (CreateGeometryException e) {
715
            throw new GeometryOperationException(e);
716
        }
717
    }
718

    
719
    protected void notifyDeprecated(String message) {
720
        logger.info(message);
721

    
722
    }
723

    
724

    
725
    /* (non-Javadoc)
726
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#ensureOrientation(boolean)
727
     */
728
    public boolean ensureOrientation(boolean ccw) throws GeometryOperationNotSupportedException, GeometryOperationException {
729
        if (ccw != isCCW()) {
730
            flip();
731
            return true;
732
        }
733
        return false;
734
    }
735

    
736
    /* (non-Javadoc)
737
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#out(org.gvsig.fmap.geom.Geometry)
738
     */
739
    public boolean out(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException {
740
        GeometryJTS otherJtsGeom = (GeometryJTS) geometry;
741
        return (!contains(otherJtsGeom) && !intersects(otherJtsGeom));
742
    }
743

    
744
    /* (non-Javadoc)
745
     * @see java.lang.Object#equals(java.lang.Object)
746
     */
747
    @Override
748
    public boolean equals(Object obj) {
749
        if (obj instanceof GeometryJTS) {
750
            return this.getJTS().equals(((GeometryJTS) obj).getJTS());
751
        }
752
        return false;
753
    }
754

    
755
    public String toString() {
756
        return this.getGeometryType().getFullName();
757
    }
758

    
759
    @Override
760
    public IProjection getProjection() {
761
        return this.projection;
762
    }
763

    
764
    @Override
765
    public void setProjectionIffNull(IProjection projection) {
766
        if (this.projection == null) {
767
            this.projection = projection;
768
        }
769
    }
770

    
771
    @Override
772
    public void setProjection(IProjection projection) {
773
        this.projection = projection;
774
    }
775

    
776
}