root / branches / v2_0_0_prep / libraries / libFMap_geometries / src-test / org / gvsig / fmap / geom / operation / towkb / WKBNativeTest.java @ 36748
History | View | Annotate | Download (5.64 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.SUBTYPES; |
32 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
33 |
import org.gvsig.fmap.geom.GeometryLocator; |
34 |
import org.gvsig.fmap.geom.GeometryManager; |
35 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
36 |
import org.gvsig.fmap.geom.operation.fromwkb.FromWKB; |
37 |
import org.gvsig.fmap.geom.operation.fromwkb.FromWKBGeometryOperationContext; |
38 |
import org.gvsig.fmap.geom.primitive.Curve; |
39 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
40 |
import org.gvsig.fmap.geom.primitive.Point; |
41 |
import org.gvsig.fmap.geom.primitive.Surface; |
42 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
43 |
|
44 |
/**
|
45 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
46 |
*/
|
47 |
public class WKBNativeTest extends AbstractLibraryAutoInitTestCase { |
48 |
private GeometryManager manager;
|
49 |
private GeometryOperation toWkb2d;
|
50 |
private GeometryOperation fromWkb2d;
|
51 |
private FromWKBGeometryOperationContext fromWkbContext;
|
52 |
|
53 |
protected void doSetUp() throws Exception { |
54 |
manager = GeometryLocator.getGeometryManager(); |
55 |
fromWkbContext = new FromWKBGeometryOperationContext();
|
56 |
} |
57 |
|
58 |
public void testPoint() throws Exception{ |
59 |
Point point = (Point) manager.create(TYPES.POINT, SUBTYPES.GEOM2D); |
60 |
point.setX(1);
|
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); |
68 |
byte[] wkb = (byte[]) toWkb2d.invoke(point, |
69 |
null);
|
70 |
fromWkbContext.setData(wkb); |
71 |
Geometry geom = (Geometry) fromWkb2d.invoke(null,
|
72 |
fromWkbContext); |
73 |
|
74 |
assertEquals(point, geom); |
75 |
} |
76 |
|
77 |
public void testCurve() throws Exception { |
78 |
|
79 |
GeneralPathX gp = new GeneralPathX();
|
80 |
|
81 |
gp.moveTo(0.0, 0.0); |
82 |
gp.lineTo(1.0, 1.0); |
83 |
gp.lineTo(2.0, 2.0); |
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); |
91 |
Curve curve = (Curve) manager.create(TYPES.CURVE, SUBTYPES.GEOM2D); |
92 |
curve.setGeneralPath(gp); |
93 |
byte[] wkb = (byte[]) toWkb2d.invoke(curve, |
94 |
null);
|
95 |
fromWkbContext.setData(wkb); |
96 |
Geometry geom = (Geometry) fromWkb2d.invoke(null,
|
97 |
fromWkbContext); |
98 |
assertTrue(curve.equals(geom)); |
99 |
} |
100 |
|
101 |
public void testPolygon() throws Exception { |
102 |
GeneralPathX gp = new GeneralPathX();
|
103 |
gp.moveTo(1.0, 1.0); |
104 |
gp.lineTo(2.0, 2.0); |
105 |
gp.lineTo(3.0, 3.0); |
106 |
gp.lineTo(4.0, 4.0); |
107 |
gp.lineTo(5.0, 5.0); |
108 |
gp.closePath(); |
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 |
|
117 |
Surface surface = manager.createSurface(gp, SUBTYPES.GEOM2D); |
118 |
|
119 |
byte[] wkb = (byte[]) toWkb2d.invoke(surface, null); |
120 |
fromWkbContext.setData(wkb); |
121 |
Geometry geom = (Geometry) fromWkb2d.invoke(null, fromWkbContext);
|
122 |
assertTrue(surface.equals(geom)); |
123 |
} |
124 |
|
125 |
// public void testPolygonWithZ() throws Exception {
|
126 |
// Surface surface = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM3D);
|
127 |
//
|
128 |
// Point point = manager.createPoint(1, 1, SUBTYPES.GEOM3D);
|
129 |
// point.setCoordinateAt(DIMENSIONS.Z, 1);
|
130 |
// surface.addMoveToVertex(point);
|
131 |
//
|
132 |
// point = manager.createPoint(2, 2, SUBTYPES.GEOM3D);
|
133 |
// point.setCoordinateAt(DIMENSIONS.Z, 2);
|
134 |
// surface.addVertex(point);
|
135 |
//
|
136 |
// point = manager.createPoint(3, 3, SUBTYPES.GEOM3D);
|
137 |
// point.setCoordinateAt(DIMENSIONS.Z, 3);
|
138 |
// surface.addVertex(point);
|
139 |
//
|
140 |
// point = manager.createPoint(4, 4, SUBTYPES.GEOM3D);
|
141 |
// point.setCoordinateAt(DIMENSIONS.Z, 4);
|
142 |
// surface.addVertex(point);
|
143 |
//
|
144 |
// point = manager.createPoint(5, 5, SUBTYPES.GEOM3D);
|
145 |
// point.setCoordinateAt(DIMENSIONS.Z, 5);
|
146 |
// surface.addVertex(point);
|
147 |
//
|
148 |
// surface.closePrimitive();
|
149 |
//
|
150 |
// byte[] wkb = (byte[]) toWkb2d.invoke(surface, null);
|
151 |
// fromWkbContext.setData(wkb);
|
152 |
// Geometry geom = (Geometry) fromWkb2d.invoke(null, fromWkbContext);
|
153 |
// assertTrue(surface.equals(geom));
|
154 |
// }
|
155 |
} |
156 |
|