Revision 36748

View differences:

branches/v2_0_0_prep/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/operation/towkb/WKBNativeTest.java
28 28
package org.gvsig.fmap.geom.operation.towkb;
29 29

  
30 30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.Geometry.DIMENSIONS;
32 31
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33 32
import org.gvsig.fmap.geom.Geometry.TYPES;
34 33
import org.gvsig.fmap.geom.GeometryLocator;
......
53 52

  
54 53
    protected void doSetUp() throws Exception {
55 54
        manager = GeometryLocator.getGeometryManager();
56
        toWkb2d = manager.getGeometryOperation(ToWKBNative.CODE,
57
            Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM2D);
58
        fromWkb2d = manager.getGeometryOperation(FromWKB.CODE,
59
            Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM2D);
60 55
        fromWkbContext = new FromWKBGeometryOperationContext();
61 56
    }
62 57

  
......
64 59
        Point point = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
65 60
        point.setX(1);
66 61
        point.setY(2);
62
        toWkb2d =
63
            manager.getGeometryOperation(ToWKBNative.CODE,
64
                Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D);
65
        fromWkb2d =
66
            manager.getGeometryOperation(FromWKB.CODE, Geometry.TYPES.POINT,
67
                Geometry.SUBTYPES.GEOM2D);
67 68
        byte[] wkb = (byte[]) toWkb2d.invoke(point,
68 69
            null);
69 70
        fromWkbContext.setData(wkb);
......
81 82
        gp.lineTo(1.0, 1.0);
82 83
        gp.lineTo(2.0, 2.0);
83 84
        gp.lineTo(3.0, 3.0);
85
        toWkb2d =
86
            manager.getGeometryOperation(ToWKBNative.CODE,
87
                Geometry.TYPES.CURVE, Geometry.SUBTYPES.GEOM2D);
88
        fromWkb2d =
89
            manager.getGeometryOperation(FromWKB.CODE, Geometry.TYPES.CURVE,
90
                Geometry.SUBTYPES.GEOM2D);
84 91
        Curve curve = (Curve) manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
85 92
        curve.setGeneralPath(gp);
86 93
        byte[] wkb = (byte[]) toWkb2d.invoke(curve,
......
100 107
        gp.lineTo(5.0, 5.0);
101 108
        gp.closePath();
102 109

  
110
        toWkb2d =
111
            manager.getGeometryOperation(ToWKBNative.CODE,
112
                Geometry.TYPES.SURFACE, Geometry.SUBTYPES.GEOM2D);
113
        fromWkb2d =
114
            manager.getGeometryOperation(FromWKB.CODE, Geometry.TYPES.SURFACE,
115
                Geometry.SUBTYPES.GEOM2D);
116

  
103 117
        Surface surface = manager.createSurface(gp, SUBTYPES.GEOM2D);
104 118

  
105 119
        byte[] wkb = (byte[]) toWkb2d.invoke(surface, null);
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/impl/Geometry2D.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.geom.impl;
29

  
30
import java.awt.Rectangle;
31
import java.awt.Shape;
32
import java.awt.geom.AffineTransform;
33
import java.awt.geom.PathIterator;
34
import java.awt.geom.Point2D;
35
import java.awt.geom.Rectangle2D;
36

  
37
import org.cresques.cts.ICoordTrans;
38
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40

  
41
import org.gvsig.fmap.geom.Geometry;
42
import org.gvsig.fmap.geom.GeometryLocator;
43
import org.gvsig.fmap.geom.GeometryManager;
44
import org.gvsig.fmap.geom.exception.CreateGeometryException;
45
import org.gvsig.fmap.geom.handler.Handler;
46
import org.gvsig.fmap.geom.operation.GeometryOperation;
47
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
48
import org.gvsig.fmap.geom.operation.GeometryOperationException;
49
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
50
import org.gvsig.fmap.geom.operation.relationship.DefaultRelationshipGeometryOperationContext;
51
import org.gvsig.fmap.geom.primitive.Envelope;
52
import org.gvsig.fmap.geom.primitive.GeneralPathX;
53
import org.gvsig.fmap.geom.primitive.Point;
54
import org.gvsig.fmap.geom.primitive.impl.GeneralPathAdapter;
55
import org.gvsig.fmap.geom.type.GeometryType;
56
import org.gvsig.fmap.geom.util.Converter;
57

  
58
/**
59
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
60
 */
61
public class Geometry2D implements Geometry, Shape{
62

  
63
    private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class);
64

  
65
    private Geometry geometry = null;
66

  
67
    /**
68
     * @param primitive
69
     */
70
    public Geometry2D(Geometry geometry) {
71
        super();
72
        this.geometry = geometry;
73
    }
74

  
75
    /* (non-Javadoc)
76
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
77
     */
78
    public Geometry cloneGeometry() {
79
        return new Geometry2D((Geometry)geometry.cloneGeometry());
80
    }
81

  
82
    /* (non-Javadoc)
83
     * @see org.gvsig.fmap.geom.Geometry#fastIntersects(double, double, double, double)
84
     */
85
    public boolean fastIntersects(double x, double y, double w, double h) {
86
        return geometry.fastIntersects(x, y, w, h);
87
    }
88

  
89
    /* (non-Javadoc)
90
     * @see org.gvsig.fmap.geom.Geometry#getBounds2D()
91
     */
92
    public Rectangle2D getBounds2D() {
93
        return geometry.getBounds2D();
94
    }
95

  
96
    /* (non-Javadoc)
97
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
98
     */
99
    public int getDimension() {
100
        return geometry.getDimension();
101
    }
102

  
103
    /* (non-Javadoc)
104
     * @see org.gvsig.fmap.geom.Geometry#getEnvelope()
105
     */
106
    public Envelope getEnvelope() {
107
        return geometry.getEnvelope();
108
    }
109

  
110
    /* (non-Javadoc)
111
     * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
112
     */
113
    public GeneralPathX getGeneralPath() {
114
        return geometry.getGeneralPath();
115
    }
116

  
117
    /* (non-Javadoc)
118
     * @see org.gvsig.fmap.geom.Geometry#getGeometryType()
119
     */
120
    public GeometryType getGeometryType() {
121
        return geometry.getGeometryType();
122
    }
123

  
124
    /* (non-Javadoc)
125
     * @see org.gvsig.fmap.geom.Geometry#getHandlers(int)
126
     */
127
    public Handler[] getHandlers(int type) {
128
        return geometry.getHandlers(type);
129
    }
130

  
131
    /* (non-Javadoc)
132
     * @see org.gvsig.fmap.geom.Geometry#getInternalShape()
133
     */
134
    public Shape getInternalShape() {
135
        return geometry.getInternalShape();
136
    }
137

  
138
    /* (non-Javadoc)
139
     * @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform)
140
     */
141
    public PathIterator getPathIterator(AffineTransform at) {
142
        return geometry.getPathIterator(at);
143
    }
144

  
145
    /* (non-Javadoc)
146
     * @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double)
147
     */
148
    public PathIterator getPathIterator(AffineTransform at, double flatness) {
149
        return geometry.getPathIterator(at, flatness);
150
    }
151

  
152
    /* (non-Javadoc)
153
     * @see org.gvsig.fmap.geom.Geometry#getType()
154
     */
155
    public int getType() {
156
        return geometry.getType();
157
    }
158

  
159
    /* (non-Javadoc)
160
     * @see org.gvsig.fmap.geom.Geometry#intersects(java.awt.geom.Rectangle2D)
161
     */
162
    public boolean intersects(Rectangle2D r) {
163
        return geometry.intersects(r);
164
    }
165

  
166
    /* (non-Javadoc)
167
     * @see org.gvsig.fmap.geom.Geometry#invokeOperation(int, org.gvsig.fmap.geom.operation.GeometryOperationContext)
168
     */
169
    public Object invokeOperation(int index, GeometryOperationContext ctx)
170
    throws GeometryOperationNotSupportedException,
171
    GeometryOperationException {
172
        return geometry.invokeOperation(index, ctx);
173
    }
174

  
175
    /* (non-Javadoc)
176
     * @see org.gvsig.fmap.geom.Geometry#invokeOperation(java.lang.String, org.gvsig.fmap.geom.operation.GeometryOperationContext)
177
     */
178
    public Object invokeOperation(String opName, GeometryOperationContext ctx)
179
    throws GeometryOperationNotSupportedException,
180
    GeometryOperationException {
181
        return geometry.invokeOperation(opName, ctx);
182
    }
183

  
184
    /* (non-Javadoc)
185
     * @see org.gvsig.fmap.geom.Geometry#isSimple()
186
     */
187
    public boolean isSimple() {
188
        return geometry.isSimple();
189
    }
190

  
191
    /* (non-Javadoc)
192
     * @see org.gvsig.fmap.geom.Geometry#reProject(org.cresques.cts.ICoordTrans)
193
     */
194
    public void reProject(ICoordTrans ct) {
195
        geometry.reProject(ct);
196
    }
197

  
198
    /* (non-Javadoc)
199
     * @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
200
     */
201
    public void transform(AffineTransform at) {
202
        geometry.transform(at);
203
    }
204

  
205
    /* (non-Javadoc)
206
     * @see java.awt.Shape#contains(java.awt.geom.Point2D)
207
     */
208
    public boolean contains(Point2D p) {
209

  
210

  
211

  
212
        try {
213
            return containsPoint(geometry, p.getX(), p.getY());
214
        } catch (GeometryOperationException e) {
215
            logger.error("While doing contains: " + e.getMessage(), e);
216
            return true;
217
        }
218
    }
219

  
220
    /* (non-Javadoc)
221
     * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
222
     */
223
    public boolean contains(Rectangle2D r) {
224
        try {
225
            return containsRectangle(geometry,
226
                r.getMinX(),
227
                r.getMinY(),
228
                r.getWidth(),
229
                r.getHeight());
230
        } catch (GeometryOperationException e) {
231
            logger.error("While doing contains: " + e.getMessage(), e);
232
            return true;
233
        }
234
    }
235

  
236
    /* (non-Javadoc)
237
     * @see java.awt.Shape#contains(double, double)
238
     */
239
    public boolean contains(double x, double y) {
240
        try {
241
            return containsPoint(geometry, x, y);
242
        } catch (GeometryOperationException e) {
243
            logger.error("While doing contains: " + e.getMessage(), e);
244
            return true;
245
        }
246
    }
247

  
248
    /* (non-Javadoc)
249
     * @see java.awt.Shape#contains(double, double, double, double)
250
     */
251
    public boolean contains(double x, double y, double w, double h) {
252
        try {
253
            return containsRectangle(geometry, x, y, w, h);
254
        } catch (GeometryOperationException e) {
255
            logger.error("While doing contains: " + e.getMessage(), e);
256
            return true;
257
        }
258
    }
259

  
260
    /* (non-Javadoc)
261
     * @see java.awt.Shape#getBounds()
262
     */
263
    public Rectangle getBounds() {
264
        return geometry.getShape().getBounds();
265
    }
266

  
267
    /* (non-Javadoc)
268
     * @see java.awt.Shape#intersects(double, double, double, double)
269
     */
270
    public boolean intersects(double x, double y, double w, double h) {
271
        try {
272
            return intersectsRectangle(geometry, x, y, w, h);
273
        } catch (GeometryOperationException e) {
274
            logger.error("While doing intersects: " + e.getMessage(), e);
275
            return true;
276
        }
277
    }
278

  
279
    /* (non-Javadoc)
280
     * @see java.lang.Comparable#compareTo(java.lang.Object)
281
     */
282
    public int compareTo(Object arg0) {
283
        return geometry.compareTo(arg0);
284
    }	
285

  
286
    /**
287
     * Utility method
288
     * @param geometry
289
     * @param x
290
     * @param y
291
     * @return
292
     * @throws GeometryOperationException
293
     */
294
    protected boolean containsPoint(Geometry geom, double x, double y) throws GeometryOperationException {
295

  
296
        // exclude disjoint 
297
        Envelope env = geom.getEnvelope();
298
        if (x > env.getMaximum(0)) return false; 
299
        if (y > env.getMaximum(1)) return false; 
300
        if (x < env.getMinimum(0)) return false; 
301
        if (y < env.getMinimum(1)) return false; 
302

  
303
        // boxes overlap, need long version
304

  
305
        Geometry geompoint = null;
306
        try {
307
            geompoint = GeometryLocator.getGeometryManager().createPoint(x, y, SUBTYPES.GEOM2D);
308
        } catch (Exception e1) {
309
            throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e1);
310
        }
311

  
312
        DefaultRelationshipGeometryOperationContext drgoc =
313
            new DefaultRelationshipGeometryOperationContext(geompoint);
314

  
315
        Object resp = null;
316
        boolean respboolean = true;
317
        try {
318
            resp = geom.invokeOperation(GeometryOperation.OPERATION_CONTAINS_CODE, drgoc);
319
            respboolean = ((Boolean) resp).booleanValue();
320
        } catch (Exception e) {
321
            throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e);
322
        }
323

  
324
        return respboolean;
325
    }
326

  
327
    /**
328
     * 
329
     * @param geometry
330
     * @param x
331
     * @param y
332
     * @param w
333
     * @param h
334
     * @return
335
     */
336
    protected boolean containsRectangle(Geometry geom, double x, double y,
337
        double w, double h) throws GeometryOperationException {
338

  
339

  
340
        // exclude disjoint boxes
341
        Envelope env = geom.getEnvelope();
342
        if (x > env.getMaximum(0)) return false; 
343
        if ((x+w) < env.getMinimum(0)) return false; 
344
        if (y > env.getMaximum(1)) return false; 
345
        if ((y+h) < env.getMinimum(1)) return false; 
346

  
347
        if (w == 0 && h == 0) {
348
            return  containsPoint(geom, x, y); 
349
        }
350

  
351
        // boxes overlap, need long version
352
        Geometry rectgeom = null;
353
        GeneralPathX gpx = new GeneralPathX();
354
        gpx.moveTo(x, y);
355
        gpx.lineTo(x+w, y);
356
        gpx.lineTo(x+w, y+h);
357
        gpx.lineTo(x, y+h);
358
        gpx.lineTo(x, y);
359

  
360
        try {
361
            rectgeom = GeometryLocator.getGeometryManager().createSurface(gpx, SUBTYPES.GEOM2D);
362
        } catch (Exception e1) {
363
            throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e1);
364
        }
365

  
366
        DefaultRelationshipGeometryOperationContext drgoc =
367
            new DefaultRelationshipGeometryOperationContext(rectgeom);
368

  
369
        Object resp = null;
370
        boolean respboolean = true;
371
        try {
372
            resp = geom.invokeOperation(GeometryOperation.OPERATION_CONTAINS_CODE, drgoc);
373
            respboolean = ((Boolean) resp).booleanValue();
374
        } catch (Exception e) {
375
            throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e);
376
        }
377

  
378
        return respboolean;
379
    }
380

  
381

  
382
    /**
383
     * 
384
     * @param geom
385
     * @param x
386
     * @param y
387
     * @param w
388
     * @param h
389
     * @return
390
     */
391
    protected boolean intersectsRectangle(Geometry geom, double x, double y,
392
        double w, double h) throws GeometryOperationException {
393

  
394
        // exclude disjoint boxes
395
        Envelope env = geom.getEnvelope();
396
        if (x > env.getMaximum(0)) return false; 
397
        if ((x+w) < env.getMinimum(0)) return false; 
398
        if (y > env.getMaximum(1)) return false; 
399
        if ((y+h) < env.getMinimum(1)) return false; 
400

  
401
        // boxes overlap, need long version
402
        Geometry rectgeom = null;
403
        GeneralPathX gpx = new GeneralPathX();
404
        gpx.moveTo(x, y);
405
        gpx.lineTo(x+w, y);
406
        gpx.lineTo(x+w, y+h);
407
        gpx.lineTo(x, y+h);
408
        gpx.lineTo(x, y);
409

  
410
        try {
411
            rectgeom = GeometryLocator.getGeometryManager().createSurface(gpx, SUBTYPES.GEOM2D);
412
        } catch (Exception e1) {
413
            throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_INTERSECTS_CODE, e1);
414
        }
415

  
416
        DefaultRelationshipGeometryOperationContext drgoc =
417
            new DefaultRelationshipGeometryOperationContext(rectgeom);
418

  
419
        Object resp = null;
420
        boolean respboolean = true;
421
        try {
422
            resp = geom.invokeOperation(GeometryOperation.OPERATION_INTERSECTS_CODE, drgoc);
423
            respboolean = ((Boolean) resp).booleanValue();
424
        } catch (Exception e) {
425
            throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_INTERSECTS_CODE, e);
426
        }
427

  
428
        return respboolean;
429

  
430

  
431
    }
432

  
433

  
434
    private com.vividsolutions.jts.geom.Geometry getJTS() {
435
        return Converter.geometryToJts(this);
436
    }
437

  
438
    public byte[] convertToWKB() throws GeometryOperationNotSupportedException,
439
    GeometryOperationException {
440
        return (byte[]) this.invokeOperation(OPERATIONS.CONVERTTOWKB, null);
441
    }
442

  
443
    public String convertToWKT() throws GeometryOperationNotSupportedException,
444
    GeometryOperationException {
445
        return (String) this.invokeOperation(OPERATIONS.CONVERTTOWKT, null);
446
    }
447

  
448
    public Geometry buffer(double distance)
449
    throws GeometryOperationNotSupportedException,
450
    GeometryOperationException {
451
        // TODO: this method can be implemented throw invokeOperation 
452
        try {
453
            return Converter.jtsToGeometry( getJTS().buffer(distance) );
454
        } catch (CreateGeometryException e) {
455
            throw new GeometryOperationException(e);
456
        }
457
    }
458

  
459
    public boolean contains(Geometry geometry)
460
    throws GeometryOperationNotSupportedException,
461
    GeometryOperationException {
462
        // TODO: this method can be implemented throw invokeOperation 
463
        return getJTS().contains(Converter.geometryToJts(geometry));
464
    }
465

  
466
    public double distance(Geometry geometry)
467
    throws GeometryOperationNotSupportedException,
468
    GeometryOperationException {
469
        // TODO: this method can be implemented throw invokeOperation 
470
        return getJTS().distance( Converter.geometryToJts(geometry));
471
    }
472

  
473
    public boolean overlaps(Geometry geometry)
474
    throws GeometryOperationNotSupportedException,
475
    GeometryOperationException {
476
        // TODO: this method can be implemented throw invokeOperation 
477
        return getJTS().overlaps(Converter.geometryToJts(geometry));
478
    }
479

  
480
    public Geometry convexHull() throws GeometryOperationNotSupportedException,
481
    GeometryOperationException {
482
        // TODO: this method can be implemented throw invokeOperation 
483
        try {
484
            return Converter.jtsToGeometry( getJTS().convexHull() );
485
        } catch (CreateGeometryException e) {
486
            throw new GeometryOperationException(e);
487
        }
488
    }
489

  
490
    public boolean coveredBy(Geometry geometry)
491
    throws GeometryOperationNotSupportedException,
492
    GeometryOperationException {
493
        // TODO: this method can be implemented throw invokeOperation 
494
        return getJTS().coveredBy( Converter.geometryToJts(geometry));
495
    }
496

  
497
    public boolean crosses(Geometry geometry)
498
    throws GeometryOperationNotSupportedException,
499
    GeometryOperationException {
500
        // TODO: this method can be implemented throw invokeOperation 
501
        return getJTS().crosses(Converter.geometryToJts(geometry));
502
    }
503

  
504
    public Geometry difference(Geometry other)
505
    throws GeometryOperationNotSupportedException,
506
    GeometryOperationException {
507
        // TODO: this method can be implemented throw invokeOperation 
508
        try {
509
            return Converter.jtsToGeometry( getJTS().difference( Converter.geometryToJts(other)) );
510
        } catch (CreateGeometryException e) {
511
            throw new GeometryOperationException(e);
512
        }
513
    }
514

  
515
    public Geometry intersection(Geometry other)
516
    throws GeometryOperationNotSupportedException,
517
    GeometryOperationException {
518
        // TODO: this method can be implemented throw invokeOperation 
519
        try {
520
            return Converter.jtsToGeometry( getJTS().intersection(Converter.geometryToJts(other)) );
521
        } catch (CreateGeometryException e) {
522
            throw new GeometryOperationException(e);
523
        }
524
    }
525

  
526
    public boolean intersects(Geometry geometry)
527
    throws GeometryOperationNotSupportedException,
528
    GeometryOperationException {
529
        // TODO: this method can be implemented throw invokeOperation 
530
        return getJTS().intersects(Converter.geometryToJts(geometry));
531
    }
532

  
533
    public boolean touches(Geometry geometry)
534
    throws GeometryOperationNotSupportedException,
535
    GeometryOperationException {
536
        // TODO: this method can be implemented throw invokeOperation 
537
        return getJTS().touches(Converter.geometryToJts(geometry));
538
    }
539

  
540
    public Geometry union(Geometry other)
541
    throws GeometryOperationNotSupportedException,
542
    GeometryOperationException {
543
        // TODO: this method can be implemented throw invokeOperation 
544
        try {
545
            return Converter.jtsToGeometry( getJTS().union(Converter.geometryToJts(other)) );
546
        } catch (CreateGeometryException e) {
547
            throw new GeometryOperationException(e);
548
        }
549
    }
550

  
551
    public boolean disjoint(Geometry geometry)
552
    throws GeometryOperationNotSupportedException,
553
    GeometryOperationException {
554
        // TODO: this method can be implemented throw invokeOperation 
555
        return getJTS().disjoint(Converter.geometryToJts(geometry));
556
    }
557

  
558
    public boolean within(Geometry geometry)
559
    throws GeometryOperationNotSupportedException,
560
    GeometryOperationException {
561
        // TODO: this method can be implemented throw invokeOperation 
562
        return getJTS().within(Converter.geometryToJts(geometry));
563
    }
564

  
565
    public Point centroid() throws GeometryOperationNotSupportedException, GeometryOperationException {
566
        com.vividsolutions.jts.geom.Geometry geometry = getJTS();
567
        com.vividsolutions.jts.geom.Point point = geometry.getCentroid();
568
        GeometryOperationContext geometryOperationContext = new GeometryOperationContext();
569
        geometryOperationContext.setAttribute("JTSGeometry", point);
570
        return (Point)this.invokeOperation("fromJTS", geometryOperationContext);		
571
    }
572

  
573
    public double area() throws GeometryOperationNotSupportedException, GeometryOperationException
574
    {
575
        //Using get getJTS method instead of use the "toJTS" operation just for performance
576
        return getJTS().getArea();
577
    }
578

  
579
    public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException
580
    {
581
        //Using get getJTS method instead of use the "toJTS" operation just for performance
582
        return getJTS().getLength();
583
    }
584

  
585
    public Shape getShape() {
586
        return this;
587
    }  
588
    
589
    public Shape getShape(AffineTransform affineTransform) {
590
        if (affineTransform == null){
591
            return this;
592
        }
593
        return new GeneralPathAdapter(affineTransform, getGeneralPath());
594
    }   
595
}
596

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/impl/Geometry2DZ.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.geom.impl;
23

  
24
import org.gvsig.fmap.geom.Geometry;
25

  
26

  
27
/**
28
 * @author gvSIG Team
29
 * @version $Id$
30
 *
31
 */
32
public class Geometry2DZ extends Geometry2D{
33
    private static final long serialVersionUID = 9077261346066587523L;
34

  
35
    /**
36
     * @param geometry
37
     */
38
    public Geometry2DZ(Geometry geometry) {
39
        super(geometry);       
40
    }
41
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/impl/DefaultGeometryLibrary.java
108 108
        GeometryOperation.OPERATION_INTERSECTS_CODE =
109 109
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
110 110
                GeometryOperation.OPERATION_INTERSECTS_NAME);
111
        ;
112 111

  
113 112
        GeometryOperation.OPERATION_CONTAINS_CODE =
114 113
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
115 114
                GeometryOperation.OPERATION_CONTAINS_NAME);
116
        ;
117 115

  
118 116
        // Register the geometries in 2D
119
        geometryManager.registerGeometryType(Geometry2D.class, "Geometry2D",
120
            TYPES.GEOMETRY, SUBTYPES.GEOM2D);
121 117
        geometryManager.registerGeometryType(DefaultNullGeometry.class, "Null",
122 118
            TYPES.NULL, SUBTYPES.GEOM2D);
123 119

  
......
154 150
            TYPES.MULTISURFACE, SUBTYPES.GEOM2D, TYPES.AGGREGATE);
155 151

  
156 152
        // Register the geometries in 3D
157
        geometryManager.registerGeometryType(Geometry2DZ.class, "Geometry3D", 
158
            TYPES.GEOMETRY, SUBTYPES.GEOM3D);
159 153
        geometryManager.registerGeometryType(DefaultNullGeometry.class,
160 154
            TYPES.NULL, SUBTYPES.GEOM3D);
161 155

  

Also available in: Unified diff