Revision 43908

View differences:

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
75 75
    private final GeometryType geometryType;
76 76

  
77 77
    private IProjection projection;
78
    
78

  
79 79
    /**
80 80
     *
81 81
     */
......
88 88
        }
89 89
    }
90 90

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

  
......
102 102
     * @see org.gvsig.fmap.geom.Geometry#contains(org.gvsig.fmap.geom.Geometry)
103 103
     */
104 104
    public boolean contains(Geometry geometry) throws GeometryOperationNotSupportedException,
105
        GeometryOperationException {
105
            GeometryOperationException {
106 106
        if (!(geometry instanceof GeometryJTS)) {
107 107
            return false;
108 108
        }
......
180 180
     * @see org.gvsig.fmap.geom.Geometry#distance(org.gvsig.fmap.geom.Geometry)
181 181
     */
182 182
    public double distance(org.gvsig.fmap.geom.Geometry other) throws GeometryOperationNotSupportedException,
183
        GeometryOperationException {
183
            GeometryOperationException {
184 184
        return getJTS().distance(((GeometryJTS) other).getJTS());
185 185
    }
186 186

  
......
192 192
     * , double)
193 193
     */
194 194
    public boolean isWithinDistance(org.gvsig.fmap.geom.Geometry other, double distance)
195
        throws GeometryOperationNotSupportedException, GeometryOperationException {
195
            throws GeometryOperationNotSupportedException, GeometryOperationException {
196 196
        return com.vividsolutions.jts.operation.distance.DistanceOp.isWithinDistance(this.getJTS(),
197
            ((GeometryJTS) other).getJTS(), distance);
197
                ((GeometryJTS) other).getJTS(), distance);
198 198
    }
199 199

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

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

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

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

  
......
236 236
    }
237 237

  
238 238
    public boolean disjoint(Geometry geometry) throws GeometryOperationNotSupportedException,
239
        GeometryOperationException {
239
            GeometryOperationException {
240 240
        // TODO: this method can be implemented throw invokeOperation
241 241
        return getJTS().disjoint(((GeometryJTS) geometry).getJTS());
242 242
    }
......
357 357
     * org.gvsig.fmap.geom.operation.GeometryOperationContext)
358 358
     */
359 359
    public Object invokeOperation(int index, GeometryOperationContext ctx)
360
        throws GeometryOperationNotSupportedException, GeometryOperationException {
360
            throws GeometryOperationNotSupportedException, GeometryOperationException {
361 361
        return getManager().invokeOperation(index, this, ctx);
362 362

  
363 363
    }
......
369 369
     * org.gvsig.fmap.geom.operation.GeometryOperationContext)
370 370
     */
371 371
    public Object invokeOperation(String opName, GeometryOperationContext ctx)
372
        throws GeometryOperationNotSupportedException, GeometryOperationException {
372
            throws GeometryOperationNotSupportedException, GeometryOperationException {
373 373
        return getManager().invokeOperation(opName, this, ctx);
374 374

  
375 375
    }
......
384 384
    }
385 385

  
386 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
		}
387
        try {
388
            return new OGCWKBEncoder().encode(this);
389
        } catch (Exception e) {
390
            throw new GeometryOperationException(e);
391
        }
392 392

  
393 393
    }
394 394

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

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

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

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

  
425 426
    }
426 427

  
427

  
428

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

  
436 435
    }
437 436

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

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

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

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

  
468 467
    }
469 468

  
......
478 477
        EWKTWriter writer = null;
479 478

  
480 479
        switch (subType) {
481
        case Geometry.SUBTYPES.GEOM3D:
482
            writer = new EWKTWriter(3, false);
483
            break;
484
        case Geometry.SUBTYPES.GEOM2DM:
485
            writer = new EWKTWriter(3, true);
486
            break;
487
        case Geometry.SUBTYPES.GEOM3DM:
488
            writer = new EWKTWriter(4, true);
489
            break;
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;
490 489

  
491
        default:
492
            writer = new EWKTWriter(2, false);
493
            break;
490
            default:
491
                writer = new EWKTWriter(2, false);
492
                break;
494 493
        }
495 494
        com.vividsolutions.jts.geom.Geometry jts = getJTS();
496 495
        return writer.write(jts);
......
502 501
     * @see org.gvsig.fmap.geom.Geometry#buffer(double)
503 502
     */
504 503
    public org.gvsig.fmap.geom.Geometry buffer(double distance) throws GeometryOperationNotSupportedException,
505
        GeometryOperationException {
504
            GeometryOperationException {
506 505
        return JTSUtils.createGeometry(getJTS().buffer(distance));
507 506
    }
508 507

  
......
513 512
     * double)
514 513
     */
515 514
    public org.gvsig.fmap.geom.Geometry snapTo(org.gvsig.fmap.geom.Geometry other, double snapTolerance)
516
        throws GeometryOperationNotSupportedException, GeometryOperationException {
515
            throws GeometryOperationNotSupportedException, GeometryOperationException {
517 516
        Geometry result = null;
518 517
        GeometrySnapper snapper = new GeometrySnapper(getJTS());
519 518
        com.vividsolutions.jts.geom.Geometry jts_result = snapper.snapTo(((GeometryJTS) other).getJTS(), snapTolerance);
......
590 589
            }
591 590
            Geometry g = null;
592 591
            switch (vs.getStatusCode()) {
593
            case Geometry.ValidationStatus.RING_SELF_INTERSECTION:
594
            case Geometry.ValidationStatus.SELF_INTERSECTION:
595
                g = this.buffer(0);
596
                if (g.isValid()) {
597
                    return g;
598
                }
599
                break;
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;
600 599

  
601
            case Geometry.ValidationStatus.TOO_FEW_POINTS:
602
                if (this instanceof OrientableCurve) {
603
                    int vertices = ((OrientableCurve) this).getNumVertices();
604
                    if (vertices < 2) {
605
                        return null; // new
606
                                     // DefaultNullGeometry(this.getGeometryType());
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 607
                    }
608
                }
609
                if (this instanceof OrientableSurface) {
610
                    int vertices = ((OrientableSurface) this).getNumVertices();
611
                    if (vertices < 3) {
612
                        return null; // new
613
                                     // DefaultNullGeometry(this.getGeometryType());
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 614
                    }
615
                }
616 615
            }
617 616
        } catch (Exception ex) {
618 617
            return null;
......
628 627
    public Rectangle2D getBounds2D() {
629 628
        com.vividsolutions.jts.geom.Envelope envInternal = getJTS().getEnvelopeInternal();
630 629
        return new Rectangle2D.Double(envInternal.getMinX(), envInternal.getMinY(), envInternal.getWidth(),
631
            envInternal.getHeight());
630
                envInternal.getHeight());
632 631
    }
633 632

  
634 633
    /*
......
673 672
    }
674 673

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

  
679 678
        Coordinate[] jts_points = DistanceOp.nearestPoints(getJTS(), ((GeometryJTS) other).getJTS());
......
695 694
    }
696 695

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

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

  
......
709 708
    }
710 709

  
711 710
    public org.gvsig.fmap.geom.primitive.Point centroid() throws GeometryOperationNotSupportedException,
712
        GeometryOperationException {
711
            GeometryOperationException {
713 712
        try {
714 713
            return JTSUtils.createPoint(this.getGeometryType(), getJTS().getCentroid().getCoordinate());
715 714
        } catch (CreateGeometryException e) {
......
727 726
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#ensureOrientation(boolean)
728 727
     */
729 728
    public boolean ensureOrientation(boolean ccw) throws GeometryOperationNotSupportedException, GeometryOperationException {
730
        if(ccw!=isCCW()){
729
        if (ccw != isCCW()) {
731 730
            flip();
732 731
            return true;
733 732
        }
......
738 737
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#out(org.gvsig.fmap.geom.Geometry)
739 738
     */
740 739
    public boolean out(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException {
741
        GeometryJTS otherJtsGeom = (GeometryJTS)geometry;
740
        GeometryJTS otherJtsGeom = (GeometryJTS) geometry;
742 741
        return (!contains(otherJtsGeom) && !intersects(otherJtsGeom));
743 742
    }
744 743

  
......
753 752
        return false;
754 753
    }
755 754

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

  
......
764 763

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

Also available in: Unified diff