Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_geometries / src-test / org / gvsig / fmap / geom / operation / towkb / WKBNativeTest.java @ 35474

History | View | Annotate | Download (5.11 KB)

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.operation.towkb;
29

    
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.Geometry.DIMENSIONS;
32
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.Geometry.TYPES;
34
import org.gvsig.fmap.geom.GeometryLocator;
35
import org.gvsig.fmap.geom.GeometryManager;
36
import org.gvsig.fmap.geom.operation.GeometryOperation;
37
import org.gvsig.fmap.geom.operation.fromwkb.FromWKB;
38
import org.gvsig.fmap.geom.operation.fromwkb.FromWKBGeometryOperationContext;
39
import org.gvsig.fmap.geom.primitive.Curve;
40
import org.gvsig.fmap.geom.primitive.GeneralPathX;
41
import org.gvsig.fmap.geom.primitive.Point;
42
import org.gvsig.fmap.geom.primitive.Surface;
43
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
44

    
45
/**
46
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
47
 */
48
public class WKBNativeTest extends AbstractLibraryAutoInitTestCase {
49
    private GeometryManager manager;
50
    private GeometryOperation toWkb2d;
51
    private GeometryOperation fromWkb2d;
52
    private FromWKBGeometryOperationContext fromWkbContext;
53

    
54
    protected void doSetUp() throws Exception {
55
        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
        fromWkbContext = new FromWKBGeometryOperationContext();
61
    }
62

    
63
    public void testPoint() throws Exception{
64
        Point point = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
65
        point.setX(1);
66
        point.setY(2);
67
        byte[] wkb = (byte[]) toWkb2d.invoke(point,
68
            null);
69
        fromWkbContext.setData(wkb);
70
        Geometry geom = (Geometry) fromWkb2d.invoke(null,
71
            fromWkbContext);
72

    
73
        assertEquals(point, geom);
74
    }
75

    
76
    public void testCurve() throws Exception {
77

    
78
        GeneralPathX gp = new GeneralPathX();
79

    
80
        gp.moveTo(0.0, 0.0);
81
        gp.lineTo(1.0, 1.0);
82
        gp.lineTo(2.0, 2.0);
83
        gp.lineTo(3.0, 3.0);
84
        Curve curve = (Curve) manager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
85
        curve.setGeneralPath(gp);
86
        byte[] wkb = (byte[]) toWkb2d.invoke(curve,
87
            null);
88
        fromWkbContext.setData(wkb);
89
        Geometry geom = (Geometry) fromWkb2d.invoke(null,
90
            fromWkbContext);
91
        assertTrue(curve.equals(geom));
92
    }
93

    
94
    public void testPolygon() throws Exception {
95
        GeneralPathX gp = new GeneralPathX();
96
        gp.moveTo(1.0, 1.0);
97
        gp.lineTo(2.0, 2.0);
98
        gp.lineTo(3.0, 3.0);
99
        gp.lineTo(4.0, 4.0);
100
        gp.lineTo(5.0, 5.0);
101
        gp.closePath();
102

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

    
105
        byte[] wkb = (byte[]) toWkb2d.invoke(surface, null);
106
        fromWkbContext.setData(wkb);
107
        Geometry geom = (Geometry) fromWkb2d.invoke(null, fromWkbContext);
108
        assertTrue(surface.equals(geom));
109
    }
110

    
111
//    public void testPolygonWithZ() throws Exception {
112
//        Surface surface = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM3D);
113
//
114
//        Point point = manager.createPoint(1, 1, SUBTYPES.GEOM3D);
115
//        point.setCoordinateAt(DIMENSIONS.Z, 1);
116
//        surface.addMoveToVertex(point);
117
//        
118
//        point = manager.createPoint(2, 2, SUBTYPES.GEOM3D);
119
//        point.setCoordinateAt(DIMENSIONS.Z, 2);
120
//        surface.addVertex(point);
121
//        
122
//        point = manager.createPoint(3, 3, SUBTYPES.GEOM3D);
123
//        point.setCoordinateAt(DIMENSIONS.Z, 3);
124
//        surface.addVertex(point);
125
//        
126
//        point = manager.createPoint(4, 4, SUBTYPES.GEOM3D);
127
//        point.setCoordinateAt(DIMENSIONS.Z, 4);
128
//        surface.addVertex(point);
129
//        
130
//        point = manager.createPoint(5, 5, SUBTYPES.GEOM3D);
131
//        point.setCoordinateAt(DIMENSIONS.Z, 5);
132
//        surface.addVertex(point);       
133
//
134
//        surface.closePrimitive();
135
//        
136
//        byte[] wkb = (byte[]) toWkb2d.invoke(surface, null);
137
//        fromWkbContext.setData(wkb);
138
//        Geometry geom = (Geometry) fromWkb2d.invoke(null, fromWkbContext);
139
//        assertTrue(surface.equals(geom));
140
//    }
141
}
142